summaryrefslogtreecommitdiff
path: root/nix/libutil/hash.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nix/libutil/hash.cc')
-rw-r--r--nix/libutil/hash.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc
index 7853acdd49..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]))
@@ -244,7 +247,7 @@ Hash hashFile(HashType ht, const Path & path)
start(ht, ctx);
AutoCloseFD fd = open(path.c_str(), O_RDONLY);
- if (fd == -1) throw SysError(format("opening file `%1%'") % path);
+ if (fd == -1) throw SysError(format("computing hash of file `%1%'") % path);
unsigned char buf[8192];
ssize_t n;