summaryrefslogtreecommitdiff
path: root/guix/hash.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/hash.scm')
-rw-r--r--guix/hash.scm26
1 files changed, 18 insertions, 8 deletions
diff --git a/guix/hash.scm b/guix/hash.scm
index 44e4472580..39834043e1 100644
--- a/guix/hash.scm
+++ b/guix/hash.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2018 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -23,7 +23,9 @@
#:use-module (system foreign)
#:use-module ((guix build utils) #:select (dump-port))
#:use-module (srfi srfi-11)
- #:export (sha256
+ #:use-module (srfi srfi-26)
+ #:export (sha1
+ sha256
open-sha256-port
port-sha256
file-sha256
@@ -44,17 +46,26 @@
;; Value as of Libgcrypt 1.5.2.
(identifier-syntax 8))
-(define sha256
+(define-syntax GCRY_MD_SHA1
+ (identifier-syntax 2))
+
+(define bytevector-hash
(let ((hash (pointer->procedure void
(libgcrypt-func "gcry_md_hash_buffer")
`(,int * * ,size_t))))
- (lambda (bv)
- "Return the SHA256 of BV as a bytevector."
- (let ((digest (make-bytevector (/ 256 8))))
- (hash GCRY_MD_SHA256 (bytevector->pointer digest)
+ (lambda (bv type size)
+ "Return the hash TYPE, of SIZE bytes, of BV as a bytevector."
+ (let ((digest (make-bytevector size)))
+ (hash type (bytevector->pointer digest)
(bytevector->pointer bv) (bytevector-length bv))
digest))))
+(define sha1
+ (cut bytevector-hash <> GCRY_MD_SHA1 20))
+
+(define sha256
+ (cut bytevector-hash <> GCRY_MD_SHA256 (/ 256 8)))
+
(define open-sha256-md
(let ((open (pointer->procedure int
(libgcrypt-func "gcry_md_open")
@@ -159,7 +170,6 @@ data read from PORT. The thunk always returns the same value."
(define (unbuffered port)
;; Guile <= 2.0.9 does not support 'setvbuf' on custom binary input ports.
- ;; If you get a wrong-type-arg error here, the fix is to upgrade Guile. :-)
(setvbuf port _IONBF)
port)