packages: Recognize SHA3 and BLAKE2s for 'content-hash'.
authorLudovic Courtès <ludo@gnu.org>
Tue, 23 Jun 2020 14:35:58 +0000 (16:35 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sat, 27 Jun 2020 21:42:20 +0000 (23:42 +0200)
* guix/packages.scm (build-content-hash): Add 'sha3-256', 'sha3-512',
and 'blake2s-256'.
* tests/packages.scm ("package-source-derivation, origin, sha3-512"):
New test.

guix/packages.scm
tests/packages.scm

index 1e0ec41..68ef718 100644 (file)
@@ -191,7 +191,10 @@ its first argument has the right size for the chosen algorithm."
 
 (define-content-hash-constructor build-content-hash
   (sha256 32)
-  (sha512 64))
+  (sha512 64)
+  (sha3-256 32)
+  (sha3-512 64)
+  (blake2s-256 64))
 
 (define-syntax content-hash
   (lambda (s)
index c7b6f66..26377b2 100644 (file)
     (build-derivations %store (list drv))
     (call-with-input-file output get-string-all)))
 
+(test-equal "package-source-derivation, origin, sha3-512"
+  "hello, sha3"
+  (let* ((bash    (search-bootstrap-binary "bash" (%current-system)))
+         (builder (add-text-to-store %store "my-fixed-builder.sh"
+                                     "echo -n hello, sha3 > $out" '()))
+         (method  (lambda* (url hash-algo hash #:optional name
+                                #:rest rest)
+                    (and (eq? hash-algo 'sha3-512)
+                         (raw-derivation name bash (list builder)
+                                         #:sources (list builder)
+                                         #:hash hash
+                                         #:hash-algo hash-algo))))
+         (source  (origin
+                    (method method)
+                    (uri "unused://")
+                    (file-name "origin-sha3")
+                    (hash (content-hash
+                           (gcrypt:bytevector-hash (string->utf8 "hello, sha3")
+                                                   (gcrypt:lookup-hash-algorithm
+                                                    'sha3-512))
+                           sha3-512))))
+         (drv    (package-source-derivation %store source))
+         (output (derivation->output-path drv)))
+    (build-derivations %store (list drv))
+    (call-with-input-file output get-string-all)))
+
 (unless (network-reachable?) (test-skip 1))
 (test-equal "package-source-derivation, snippet"
   "OK"