mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
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'.
This commit is contained in:
parent
4b4f890cb0
commit
3fb6b8f304
2 changed files with 12 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue