summaryrefslogtreecommitdiff
path: root/nix/libutil/hash.cc
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-06-23 11:46:05 +0200
committerLudovic Courtès <ludo@gnu.org>2020-06-27 23:42:20 +0200
commit3fb6b8f30444d41963ba5bdd441123a6d2df17bd (patch)
tree0159dc3f3ceefdbe75e42587afc6d711a7c460dc /nix/libutil/hash.cc
parent4b4f890cb03d7c5b958fe08553dfad2f39a1d4f2 (diff)
daemon: Map directly to gcrypt hash functions.
* nix/libutil/hash.hh (HashType): Map directly to GCRY_MD_ values. (md5HashSize, sha1HashSize, sha256HashSize, sha512HashSize): Remove. * nix/libutil/hash.cc (Hash::Hash): Use 'gcry_md_get_algo_dlen'.
Diffstat (limited to 'nix/libutil/hash.cc')
-rw-r--r--nix/libutil/hash.cc8
1 files changed, 3 insertions, 5 deletions
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc
index ea69aa64f9..251f18f60e 100644
--- a/nix/libutil/hash.cc
+++ b/nix/libutil/hash.cc
@@ -38,11 +38,9 @@ Hash::Hash()
Hash::Hash(HashType type)
{
this->type = type;
- if (type == htMD5) hashSize = md5HashSize;
- else if (type == htSHA1) hashSize = sha1HashSize;
- else if (type == htSHA256) hashSize = sha256HashSize;
- else if (type == htSHA512) hashSize = sha512HashSize;
- else throw Error("unknown hash type");
+ hashSize = gcry_md_get_algo_dlen(type);
+
+ if (hashSize == 0) throw Error("unknown hash type");
assert(hashSize <= maxHashSize);
memset(hash, 0, maxHashSize);
}