From 0623359fbc67c421bf76b7433f92c7ef58050321 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 20 Sep 2006 16:15:32 +0000 Subject: * Print a better error message for wrong hashes (NIX-49). --- src/libutil/hash.cc | 8 +++++++- src/libutil/hash.hh | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/libutil') diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 16597fd47cbf..7381948f2180 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -120,6 +120,12 @@ static unsigned char divMod(unsigned char * bytes, unsigned char y) } +unsigned int hashLength32(const Hash & hash) +{ + return (hash.hashSize * 8 - 1) / 5 + 1; +} + + // omitted: E O U T const string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz"; @@ -127,7 +133,7 @@ const string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz"; string printHash32(const Hash & hash) { Hash hash2(hash); - unsigned int len = (hash.hashSize * 8 - 1) / 5 + 1; + unsigned int len = hashLength32(hash); const char * chars = base32Chars.c_str(); diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 95629bc9e5ba..74ae51db3286 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -49,6 +49,9 @@ string printHash(const Hash & hash); /* Parse a hexadecimal representation of a hash code. */ Hash parseHash(HashType ht, const string & s); +/* Returns the length of a base-32 hash representation. */ +unsigned int hashLength32(const Hash & hash); + /* Convert a hash to a base-32 representation. */ string printHash32(const Hash & hash); -- cgit 1.4.1