From 69f90f5c81419b55a4de0fd8324356f9116d9f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 1 Jun 2012 23:29:55 +0200 Subject: [PATCH] Use libchop for cryptographic hashes and related. * guix/derivations.scm (sha256): Rewrite using libchop's `bytevector-hash'. (derivation-hash): Add docstring. --- guix/derivations.scm | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/guix/derivations.scm b/guix/derivations.scm index d0e90a9952..9bdcdacf1f 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm @@ -24,6 +24,10 @@ #:use-module (rnrs bytevectors) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) + #:use-module (guix store) + #:use-module ((chop hash) + #:select (bytevector-hash + hash-method/sha256)) #:export (derivation? derivation-outputs derivation-inputs @@ -184,32 +188,11 @@ that form." (display ")" port)))) (define (sha256 bv) - "Return the SHA256 of BV as an string of hexadecimal digits." - ;; XXX: Poor programmer's implementation that uses Coreutils. - (let ((in (pipe)) - (out (pipe)) - (pid (primitive-fork))) - (if (= 0 pid) - (begin ; child - (close (cdr in)) - (close (car out)) - (close 0) - (close 1) - (dup2 (fileno (car in)) 0) - (dup2 (fileno (cdr out)) 1) - (execlp "sha256sum" "sha256sum")) - (begin ; parent - (close (car in)) - (close (cdr out)) - (put-bytevector (cdr in) bv) - (close (cdr in)) ; EOF - (let ((line (car (string-tokenize (read-line (car out)))))) - (close (car out)) - (and (and=> (status:exit-val (cdr (waitpid pid))) - zero?) - line)))))) + "Return the SHA256 of BV as a bytevector." + (bytevector-hash hash-method/sha256 bv)) (define (derivation-hash drv) ; `hashDerivationModulo' in derivations.cc + "Return the hash of DRV, modulo its fixed-output inputs, as a bytevector." (match drv (($ ((_ . ($ path (? symbol? hash-algo) (? string? hash)))))