aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 21:58:27 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 22:11:19 +0000
commitbbbf3602a323538b8da38f1a2c7ce136a20f74c6 (patch)
treee783d838d8a75d854e0b72eea03784c5909040bc /src/libutil/hash.hh
parent406dbb7fce32f7d80b02f560d91c956698b58d6e (diff)
parent40526fbea56a8006eb7f1758d461a5acbe9a1694 (diff)
Merge branch 'enum-class' into no-hash-type-unknown
Diffstat (limited to 'src/libutil/hash.hh')
-rw-r--r--src/libutil/hash.hh12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh
index 41322be67..8f9364440 100644
--- a/src/libutil/hash.hh
+++ b/src/libutil/hash.hh
@@ -25,7 +25,7 @@ const int sha512HashSize = 64;
extern const string base32Chars;
-enum struct Base : int {
+enum struct Base {
Base64,
Base32,
Base16,
@@ -52,11 +52,11 @@ struct Hash
Subresource Integrity hash expression). If the 'type' argument
is not present, then the hash type must be specified in the
string. */
- Hash(const std::string & s, std::optional<HashType> type);
+ Hash(std::string_view s, std::optional<HashType> type);
// type must be provided
- Hash(const std::string & s, HashType type);
+ Hash(std::string_view s, HashType type);
// hash type must be part of string
- Hash(const std::string & s);
+ Hash(std::string_view s);
void init();
@@ -93,7 +93,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
{
@@ -108,6 +108,8 @@ struct Hash
}
};
+/* Helper that defaults empty hashes to the 0 hash. */
+Hash newHashAllowEmpty(std::string hashStr, std::optional<HashType> ht);
/* Print a hash in base-16 if it's MD5, or base-32 otherwise. */
string printHash16or32(const Hash & hash);