summary refs log tree commit diff
path: root/nix/libutil/hash.cc
diff options
context:
space:
mode:
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);
 }