diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-18 21:38:15 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-18 21:38:15 +0000 |
commit | 40526fbea56a8006eb7f1758d461a5acbe9a1694 (patch) | |
tree | 5d74492a86f28fb7183897dc2a6d7baf2d24f7f1 /src/libutil/hash.hh | |
parent | 6dd471ebf6b9a4996405398093ccb371b8abdf2f (diff) | |
parent | 6c000eed80565d83d596da800ca0db92e248342e (diff) |
Merge remote-tracking branch 'upstream/master' into enum-class
Diffstat (limited to 'src/libutil/hash.hh')
-rw-r--r-- | src/libutil/hash.hh | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 0fe6e7677..e87595f6d 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -26,7 +26,7 @@ const int sha512HashSize = 64; extern const string base32Chars; -enum struct Base : int { +enum struct Base { Base64, Base32, Base16, @@ -53,7 +53,7 @@ struct Hash Subresource Integrity hash expression). If the 'type' argument is HashType::Unknown, then the hash type must be specified in the string. */ - Hash(const std::string & s, HashType type = HashType::Unknown); + Hash(std::string_view s, HashType type = HashType::Unknown); void init(); @@ -90,7 +90,7 @@ struct Hash /* Return a string representation of the hash, in base-16, base-32 or base-64. By default, this is prefixed by the hash type (e.g. "sha256:"). */ - std::string to_string(Base base = Base::Base32, bool includeType = true) const; + std::string to_string(Base base, bool includeType) const; std::string gitRev() const { @@ -105,6 +105,8 @@ struct Hash } }; +/* Helper that defaults empty hashes to the 0 hash. */ +Hash newHashAllowEmpty(std::string hashStr, HashType ht); /* Print a hash in base-16 if it's MD5, or base-32 otherwise. */ string printHash16or32(const Hash & hash); |