mirror of
https://github.com/NixOS/nix
synced 2025-06-29 06:21:14 +02:00
Add newHashAllowEmpty helper function
This replaces the copy&paste with a helper function in hash.hh.
This commit is contained in:
parent
19aa892f20
commit
b260c9ee03
6 changed files with 24 additions and 38 deletions
|
@ -205,6 +205,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 you wanted '%s'", h.to_string());
|
||||
} else
|
||||
return Hash(hashStr, ht);
|
||||
}
|
||||
|
||||
|
||||
union Ctx
|
||||
{
|
||||
|
|
|
@ -94,6 +94,8 @@ struct Hash
|
|||
}
|
||||
};
|
||||
|
||||
/* 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue