aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-01 15:15:32 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-01 15:15:32 -0400
commitf7f44f7c96eaa65b096e1448591e5790a58f3ad9 (patch)
tree1fdcfbbc31a1496075dd6796043c75426ee8da1c /src/libutil/hash.cc
parent5abd643c6d10f2cfa6e26652a9688a0263310094 (diff)
parentaa99005004bccc9be506a2a2f162f78bad4bcb41 (diff)
Merge commit 'aa99005004bccc9be506a2a2f162f78bad4bcb41' into ca-drv-exotic
Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r--src/libutil/hash.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index d2fd0c15a..5735e4715 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -71,12 +71,13 @@ const std::string base16Chars = "0123456789abcdef";
static std::string printHash16(const Hash & hash)
{
- char buf[hash.hashSize * 2];
+ std::string buf;
+ buf.reserve(hash.hashSize * 2);
for (unsigned int i = 0; i < hash.hashSize; i++) {
- buf[i * 2] = base16Chars[hash.hash[i] >> 4];
- buf[i * 2 + 1] = base16Chars[hash.hash[i] & 0x0f];
+ buf.push_back(base16Chars[hash.hash[i] >> 4]);
+ buf.push_back(base16Chars[hash.hash[i] & 0x0f]);
}
- return std::string(buf, hash.hashSize * 2);
+ return buf;
}
@@ -130,7 +131,7 @@ std::string Hash::to_string(Base base, bool includeType) const
break;
case Base64:
case SRI:
- s += base64Encode(std::string((const char *) hash, hashSize));
+ s += base64Encode(std::string_view((const char *) hash, hashSize));
break;
}
return s;
@@ -403,7 +404,7 @@ HashType parseHashType(std::string_view s)
throw UsageError("unknown hash algorithm '%1%'", s);
}
-std::string printHashType(HashType ht)
+std::string_view printHashType(HashType ht)
{
switch (ht) {
case htMD5: return "md5";