aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-19 18:41:33 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-19 19:32:29 +0000
commit20799a5151cbb185c1772b8e5160493b2dc2d0e8 (patch)
tree9eeec94504608c40e9ca77ad396b44bec77224a4 /src/libutil/hash.hh
parent984e521392b3f41f7cdab203e5c00f3e00e27a28 (diff)
WIP: Make Hash always store a valid hash type
Diffstat (limited to 'src/libutil/hash.hh')
-rw-r--r--src/libutil/hash.hh17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh
index 0d9916508..b51850ccf 100644
--- a/src/libutil/hash.hh
+++ b/src/libutil/hash.hh
@@ -25,14 +25,11 @@ enum Base : int { Base64, Base32, Base16, SRI };
struct Hash
{
- static const unsigned int maxHashSize = 64;
- unsigned int hashSize = 0;
- unsigned char hash[maxHashSize] = {};
+ constexpr static size_t maxHashSize = 64;
+ size_t hashSize = 0;
+ uint8_t hash[maxHashSize] = {};
- std::optional<HashType> type = {};
-
- /* Create an unset hash object. */
- Hash() { };
+ HashType type;
/* Create a zero-filled hash object. */
Hash(HashType type) : type(type) { init(); };
@@ -105,7 +102,7 @@ Hash newHashAllowEmpty(std::string hashStr, std::optional<HashType> ht);
string printHash16or32(const Hash & hash);
/* Compute the hash of the given string. */
-Hash hashString(HashType ht, const string & s);
+Hash hashString(HashType ht, std::string_view s);
/* Compute the hash of the given file. */
Hash hashFile(HashType ht, const Path & path);
@@ -121,9 +118,9 @@ HashResult hashPath(HashType ht, const Path & path,
Hash compressHash(const Hash & hash, unsigned int newSize);
/* Parse a string representing a hash type. */
-HashType parseHashType(const string & s);
+HashType parseHashType(std::string_view s);
/* Will return nothing on parse error */
-std::optional<HashType> parseHashTypeOpt(const string & s);
+std::optional<HashType> parseHashTypeOpt(std::string_view s);
/* And the reverse. */
string printHashType(HashType ht);