aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-17 03:51:02 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-17 03:51:02 +0000
commit02928f76fdf8ab991da404d4216e97d54af19976 (patch)
treed3b05632fbad02a2019d69eee8db445fc95557a0 /src/libutil/hash.hh
parente3173242362c8421429633c0e9f64ab0211760bd (diff)
parent29542865cee37ab22efe1bd142900b69f6c59f0d (diff)
Merge remote-tracking branch 'upstream/master' into multi-output-hashDerivationModulo
Diffstat (limited to 'src/libutil/hash.hh')
-rw-r--r--src/libutil/hash.hh18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh
index ffa43ecf5..180fb7633 100644
--- a/src/libutil/hash.hh
+++ b/src/libutil/hash.hh
@@ -42,7 +42,7 @@ struct Hash
Subresource Integrity hash expression). If the 'type' argument
is htUnknown, then the hash type must be specified in the
string. */
- Hash(const std::string & s, HashType type = htUnknown);
+ Hash(std::string_view s, HashType type = htUnknown);
void init();
@@ -79,9 +79,23 @@ 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 = Base32, bool includeType = true) const;
+ std::string to_string(Base base, bool includeType) const;
+
+ std::string gitRev() const
+ {
+ assert(type == htSHA1);
+ return to_string(Base16, false);
+ }
+
+ std::string gitShortRev() const
+ {
+ assert(type == htSHA1);
+ return std::string(to_string(Base16, false), 0, 7);
+ }
};
+/* 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);