1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 10:31:15 +02:00

Rename two hash constructors to proper functions

This commit is contained in:
Carlo Nucera 2020-07-01 18:34:18 -04:00
parent c8c4bcf90e
commit 263ccdd489
20 changed files with 45 additions and 37 deletions

View file

@ -144,7 +144,10 @@ Hash Hash::fromSRI(std::string_view original) {
return Hash(rest, std::make_pair(parsedType, true));
}
Hash::Hash(std::string_view s) : Hash(s, std::nullopt) {}
Hash Hash::parseAnyPrefixed(std::string_view s)
{
return parseAny(s, std::nullopt);
}
static std::pair<HashType, bool> newFunction(std::string_view & original, std::optional<HashType> optType)
{
@ -181,8 +184,11 @@ static std::pair<HashType, bool> newFunction(std::string_view & original, std::o
}
// mutates the string_view
Hash::Hash(std::string_view original, std::optional<HashType> optType)
: Hash(original, newFunction(original, optType)) {}
Hash Hash::parseAny(std::string_view original, std::optional<HashType> optType)
{
auto typeAndSRI = newFunction(original, optType);
return Hash(original, typeAndSRI);
}
Hash::Hash(std::string_view rest, std::pair<HashType, bool> typeAndSRI)
: Hash(typeAndSRI.first)
@ -249,7 +255,7 @@ Hash newHashAllowEmpty(std::string hashStr, std::optional<HashType> ht)
warn("found empty hash, assuming '%s'", h.to_string(SRI, true));
return h;
} else
return Hash(hashStr, ht);
return Hash::parseAny(hashStr, ht);
}

View file

@ -39,9 +39,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(std::string_view s, std::optional<HashType> type);
static Hash parseAny(std::string_view s, std::optional<HashType> type);
// hash type must be part of string
Hash(std::string_view s);
static Hash parseAnyPrefixed(std::string_view s);
// prefix parsed separately; non SRI hash
static Hash parseAnyUnprefixed(std::string_view s, HashType type);
static Hash fromSRI(std::string_view original);