summaryrefslogtreecommitdiff
path: root/nix/libutil/hash.cc
diff options
context:
space:
mode:
authorMarius Bakke <marius@gnu.org>2023-01-10 00:24:11 +0100
committerMarius Bakke <marius@gnu.org>2023-01-10 00:24:11 +0100
commitd9bcd1a8d6300b79f5884e48b2cefff05de8dce4 (patch)
treee484be53fb1d3cd7c5bb76a34451c7364502d9ec /nix/libutil/hash.cc
parent0d65f7daae7428b26a8141b83c2567e6d0d9d009 (diff)
parent79a9bb25bcb3d8b29968363db9b288cf3844108a (diff)
Merge branch 'master' into staging
Diffstat (limited to 'nix/libutil/hash.cc')
-rw-r--r--nix/libutil/hash.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc
index 9ba604eb85..9b83ffcdd9 100644
--- a/nix/libutil/hash.cc
+++ b/nix/libutil/hash.cc
@@ -76,8 +76,11 @@ string printHash(const Hash & hash)
Hash parseHash(HashType ht, const string & s)
{
Hash hash(ht);
- if (s.length() != hash.hashSize * 2)
- throw Error(format("invalid hash `%1%'") % s);
+ if (s.length() != hash.hashSize * 2) {
+ string algo = gcry_md_algo_name(ht);
+ throw Error(format("invalid %1% hash '%2%' (%3% bytes but expected %4%)")
+ % algo % s % (s.length() / 2) % hash.hashSize);
+ }
for (unsigned int i = 0; i < hash.hashSize; i++) {
string s2(s, i * 2, 2);
if (!isxdigit(s2[0]) || !isxdigit(s2[1]))