me
/
guix
Archived
1
0
Fork 0

Use libchop for cryptographic hashes and related.

* guix/derivations.scm (sha256): Rewrite using libchop's
  `bytevector-hash'.
  (derivation-hash): Add docstring.
master
Ludovic Courtès 2012-06-01 23:29:55 +02:00
parent 341c6fdd82
commit 69f90f5c81
1 changed files with 7 additions and 24 deletions

View File

@ -24,6 +24,10 @@
#:use-module (rnrs bytevectors) #:use-module (rnrs bytevectors)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (ice-9 rdelim) #:use-module (ice-9 rdelim)
#:use-module (guix store)
#:use-module ((chop hash)
#:select (bytevector-hash
hash-method/sha256))
#:export (derivation? #:export (derivation?
derivation-outputs derivation-outputs
derivation-inputs derivation-inputs
@ -184,32 +188,11 @@ that form."
(display ")" port)))) (display ")" port))))
(define (sha256 bv) (define (sha256 bv)
"Return the SHA256 of BV as an string of hexadecimal digits." "Return the SHA256 of BV as a bytevector."
;; XXX: Poor programmer's implementation that uses Coreutils. (bytevector-hash hash-method/sha256 bv))
(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))))))
(define (derivation-hash drv) ; `hashDerivationModulo' in derivations.cc (define (derivation-hash drv) ; `hashDerivationModulo' in derivations.cc
"Return the hash of DRV, modulo its fixed-output inputs, as a bytevector."
(match drv (match drv
(($ <derivation> ((_ . ($ <derivation-output> path (($ <derivation> ((_ . ($ <derivation-output> path
(? symbol? hash-algo) (? string? hash))))) (? symbol? hash-algo) (? string? hash)))))