[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
28/295: daemon: Map directly to gcrypt hash functions.
From: |
guix-commits |
Subject: |
28/295: daemon: Map directly to gcrypt hash functions. |
Date: |
Mon, 27 Jul 2020 06:25:09 -0400 (EDT) |
dannym pushed a commit to branch wip-desktop
in repository guix.
commit 3fb6b8f30444d41963ba5bdd441123a6d2df17bd
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Jun 23 11:46:05 2020 +0200
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'.
---
nix/libutil/hash.cc | 8 +++-----
nix/libutil/hash.hh | 17 +++++++++--------
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc
index ea69aa6..251f18f 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);
}
diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh
index 6b5e47c..7357a34 100644
--- a/nix/libutil/hash.hh
+++ b/nix/libutil/hash.hh
@@ -1,5 +1,7 @@
#pragma once
+#include <gcrypt.h>
+
#include "types.hh"
#include "serialise.hh"
@@ -7,16 +9,15 @@
namespace nix {
-typedef enum { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 } HashType;
-
-
-const int md5HashSize = 16;
-const int sha1HashSize = 20;
-const int sha256HashSize = 32;
-const int sha512HashSize = 64;
-
extern const string base32Chars;
+typedef enum {
+ htUnknown = 0,
+ htMD5 = GCRY_MD_MD5,
+ htSHA1 = GCRY_MD_SHA1,
+ htSHA256 = GCRY_MD_SHA256,
+ htSHA512 = GCRY_MD_SHA512
+} HashType;
struct Hash
{
- 12/295: gnu: dav1d: Update to 0.7.1., (continued)
- 12/295: gnu: dav1d: Update to 0.7.1., guix-commits, 2020/07/27
- 15/295: gnu: python-gevent: Update to 20.6.2., guix-commits, 2020/07/27
- 13/295: gnu: Add python2-selectors2., guix-commits, 2020/07/27
- 19/295: gnu: ilmbase: Update to 2.5.2., guix-commits, 2020/07/27
- 17/295: gnu: exempi: Delete the static library., guix-commits, 2020/07/27
- 14/295: gnu: python-greenlet: Update to 0.4.16., guix-commits, 2020/07/27
- 21/295: gnu: x265: Update to 3.4., guix-commits, 2020/07/27
- 22/295: gnu: Add emacs-browse-kill-ring., guix-commits, 2020/07/27
- 25/295: gnu: python-setproctitle: Fix indentation., guix-commits, 2020/07/27
- 23/295: gnu: Add r-shapforxgboost., guix-commits, 2020/07/27
- 28/295: daemon: Map directly to gcrypt hash functions.,
guix-commits <=
- 29/295: daemon: Remove OpenSSL hash compatibility wrappers., guix-commits, 2020/07/27
- 31/295: packages: Recognize SHA3 and BLAKE2s for 'content-hash'., guix-commits, 2020/07/27
- 32/295: gnu: libtiff: Use HTTPS., guix-commits, 2020/07/27
- 33/295: gnu: lxqt: Update to 0.15.0., guix-commits, 2020/07/27
- 39/295: gnu: r-renv: Update to 0.11.0., guix-commits, 2020/07/27
- 41/295: gnu: r-officer: Update to 0.3.12., guix-commits, 2020/07/27
- 43/295: gnu: r-raster: Update to 3.3-7., guix-commits, 2020/07/27
- 44/295: gnu: r-emmeans: Update to 1.4.8., guix-commits, 2020/07/27
- 82/295: gnu: Add rust-sha2-0.9., guix-commits, 2020/07/27
- 93/295: gnu: Rename rust-unicase-2.6 to rust-unicase-2., guix-commits, 2020/07/27