daemon: Recognize SHA3 and BLAKE2s.
* nix/libutil/hash.hh (HashType): Add htSHA3_256, htSHA3_512, and htBLAKE2s_256. * nix/libutil/hash.cc (parseHashType, printHashType): Recognize them. * tests/store.scm ("add-to-store"): Test these algorithms.
parent
8dc6c38785
commit
8e6c1415d8
|
@ -321,6 +321,9 @@ HashType parseHashType(const string & s)
|
||||||
else if (s == "sha1") return htSHA1;
|
else if (s == "sha1") return htSHA1;
|
||||||
else if (s == "sha256") return htSHA256;
|
else if (s == "sha256") return htSHA256;
|
||||||
else if (s == "sha512") return htSHA512;
|
else if (s == "sha512") return htSHA512;
|
||||||
|
else if (s == "sha3-256") return htSHA3_256;
|
||||||
|
else if (s == "sha3-512") return htSHA3_512;
|
||||||
|
else if (s == "blake2s-256") return htBLAKE2s_256;
|
||||||
else return htUnknown;
|
else return htUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,6 +334,9 @@ string printHashType(HashType ht)
|
||||||
else if (ht == htSHA1) return "sha1";
|
else if (ht == htSHA1) return "sha1";
|
||||||
else if (ht == htSHA256) return "sha256";
|
else if (ht == htSHA256) return "sha256";
|
||||||
else if (ht == htSHA512) return "sha512";
|
else if (ht == htSHA512) return "sha512";
|
||||||
|
else if (ht == htSHA3_256) return "sha3-256";
|
||||||
|
else if (ht == htSHA3_512) return "sha3-512";
|
||||||
|
else if (ht == htBLAKE2s_256) return "blake2s-256";
|
||||||
else throw Error("cannot print unknown hash type");
|
else throw Error("cannot print unknown hash type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,10 @@ typedef enum {
|
||||||
htMD5 = GCRY_MD_MD5,
|
htMD5 = GCRY_MD_MD5,
|
||||||
htSHA1 = GCRY_MD_SHA1,
|
htSHA1 = GCRY_MD_SHA1,
|
||||||
htSHA256 = GCRY_MD_SHA256,
|
htSHA256 = GCRY_MD_SHA256,
|
||||||
htSHA512 = GCRY_MD_SHA512
|
htSHA512 = GCRY_MD_SHA512,
|
||||||
|
htSHA3_256 = GCRY_MD_SHA3_256,
|
||||||
|
htSHA3_512 = GCRY_MD_SHA3_512,
|
||||||
|
htBLAKE2s_256 = GCRY_MD_BLAKE2S_256
|
||||||
} HashType;
|
} HashType;
|
||||||
|
|
||||||
struct Hash
|
struct Hash
|
||||||
|
|
|
@ -116,7 +116,7 @@
|
||||||
(list (stat:uid s) (stat:perms s))))
|
(list (stat:uid s) (stat:perms s))))
|
||||||
|
|
||||||
(test-equal "add-to-store"
|
(test-equal "add-to-store"
|
||||||
'("sha1" "sha256" "sha512")
|
'("sha1" "sha256" "sha512" "sha3-256" "sha3-512" "blake2s-256")
|
||||||
(let* ((file (search-path %load-path "guix.scm"))
|
(let* ((file (search-path %load-path "guix.scm"))
|
||||||
(content (call-with-input-file file get-bytevector-all)))
|
(content (call-with-input-file file get-bytevector-all)))
|
||||||
(map (lambda (hash-algo)
|
(map (lambda (hash-algo)
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
(bytevector=? (call-with-input-file file get-bytevector-all)
|
(bytevector=? (call-with-input-file file get-bytevector-all)
|
||||||
content)
|
content)
|
||||||
hash-algo)))
|
hash-algo)))
|
||||||
'("sha1" "sha256" "sha512"))))
|
'("sha1" "sha256" "sha512" "sha3-256" "sha3-512" "blake2s-256"))))
|
||||||
|
|
||||||
(test-equal "add-data-to-store"
|
(test-equal "add-data-to-store"
|
||||||
#vu8(1 2 3 4 5)
|
#vu8(1 2 3 4 5)
|
||||||
|
|
Reference in New Issue