diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-07-27 18:40:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-27 18:40:57 +0200 |
commit | 86805a2c0a25f5ceefac0d64e64ba57ace73b7f5 (patch) | |
tree | c9b28ba4c468446911f8bc5411933a334b1fe184 /src/libutil/hash.hh | |
parent | a5f7d310dd10fe86b6f6aa1c2771c30f113741d4 (diff) | |
parent | 43f2bd8dc5950c38a817242884870f344a84a291 (diff) |
Merge pull request #3738 from obsidiansystems/hash-always-has-type
Hash always has a valid type
Diffstat (limited to 'src/libutil/hash.hh')
-rw-r--r-- | src/libutil/hash.hh | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index ad6093fca..98ee1bed0 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -27,14 +27,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(); }; @@ -107,7 +104,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); @@ -123,10 +120,10 @@ 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); |