1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 01:11:15 +02:00

Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2020-06-17 10:26:52 +02:00
commit 1524752c17
139 changed files with 2586 additions and 1707 deletions

View file

@ -128,7 +128,7 @@ std::string Hash::to_string(Base base, bool includeType) const
}
Hash::Hash(const std::string & s, HashType type)
Hash::Hash(std::string_view s, HashType type)
: type(type)
{
size_t pos = 0;
@ -197,7 +197,7 @@ Hash::Hash(const std::string & s, HashType type)
}
else if (isSRI || size == base64Len()) {
auto d = base64Decode(std::string(s, pos));
auto d = base64Decode(s.substr(pos));
if (d.size() != hashSize)
throw BadHash("invalid %s hash '%s'", isSRI ? "SRI" : "base-64", s);
assert(hashSize);
@ -208,6 +208,16 @@ Hash::Hash(const std::string & s, HashType type)
throw BadHash("hash '%s' has wrong length for hash type '%s'", s, printHashType(type));
}
Hash newHashAllowEmpty(std::string hashStr, HashType ht)
{
if (hashStr.empty()) {
Hash h(ht);
warn("found empty hash, assuming '%s'", h.to_string(SRI, true));
return h;
} else
return Hash(hashStr, ht);
}
union Ctx
{