1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 16:51:15 +02:00

nix hash convert: Don't fail on uppercase base-16 hashes

(cherry picked from commit 33b645cedf)
This commit is contained in:
Eelco Dolstra 2024-12-05 16:19:21 +01:00 committed by Mergify
parent 00d0e63c61
commit dd79a490bf
2 changed files with 9 additions and 3 deletions

View file

@ -227,9 +227,13 @@ struct CmdHashConvert : Command
from == HashFormat::SRI from == HashFormat::SRI
? Hash::parseSRI(s) ? Hash::parseSRI(s)
: Hash::parseAny(s, algo); : Hash::parseAny(s, algo);
if (from && from != HashFormat::SRI && h.to_string(*from, false) != s) { if (from
&& from != HashFormat::SRI
&& h.to_string(*from, false) !=
(from == HashFormat::Base16 ? toLower(s) : s))
{
auto from_as_string = printHashFormat(*from); auto from_as_string = printHashFormat(*from);
throw BadHash("input hash '%s' does not have the expected format '--from %s'", s, from_as_string); throw BadHash("input hash '%s' does not have the expected format for '--from %s'", s, from_as_string);
} }
logger->cout(h.to_string(to, to == HashFormat::SRI)); logger->cout(h.to_string(to, to == HashFormat::SRI));
} }

View file

@ -98,6 +98,8 @@ try3() {
expectStderr 1 nix hash convert --hash-algo "$1" --from base16 "$3" | grepQuiet "input hash" expectStderr 1 nix hash convert --hash-algo "$1" --from base16 "$3" | grepQuiet "input hash"
expectStderr 1 nix hash convert --hash-algo "$1" --from nix32 "$4" | grepQuiet "input hash" expectStderr 1 nix hash convert --hash-algo "$1" --from nix32 "$4" | grepQuiet "input hash"
# Base-16 hashes can be in uppercase.
nix hash convert --hash-algo "$1" --from base16 "$(echo $2 | tr [a-z] [A-Z])"
} }
try3 sha1 "800d59cfcd3c05e900cb4e214be48f6b886a08df" "vw46m23bizj4n8afrc0fj19wrp7mj3c0" "gA1Zz808BekAy04hS+SPa4hqCN8=" try3 sha1 "800d59cfcd3c05e900cb4e214be48f6b886a08df" "vw46m23bizj4n8afrc0fj19wrp7mj3c0" "gA1Zz808BekAy04hS+SPa4hqCN8="