Move `sha256' to (guix hash).
authorLudovic Courtès <ludo@gnu.org>
Mon, 1 Jul 2013 21:28:21 +0000 (23:28 +0200)
committerLudovic Courtès <ludo@gnu.org>
Mon, 1 Jul 2013 21:28:21 +0000 (23:28 +0200)
* guix/utils.scm (sha256): Move to...
* guix/hash.scm: ... here.  New file.
* Makefile.am (MODULES): Add it.
* guix/derivations.scm, guix/scripts/download.scm,
  guix/scripts/hash.scm, guix/scripts/refresh.scm, tests/base32.scm,
  tests/derivations.scm, tests/store.scm: Use (guix hash).

Makefile.am
guix/derivations.scm
guix/hash.scm [new file with mode: 0644]
guix/scripts/download.scm
guix/scripts/hash.scm
guix/scripts/refresh.scm
guix/utils.scm
tests/base32.scm
tests/derivations.scm
tests/store.scm

index 418b63a..2893ffb 100644 (file)
@@ -38,6 +38,7 @@ MODULES =                                     \
   guix/scripts/refresh.scm                     \
   guix/base32.scm                              \
   guix/records.scm                             \
+  guix/hash.scm                                        \
   guix/utils.scm                               \
   guix/serialization.scm                       \
   guix/nar.scm                                 \
index 3c433a2..b7ab07c 100644 (file)
@@ -26,6 +26,7 @@
   #:use-module (ice-9 rdelim)
   #:use-module (guix store)
   #:use-module (guix utils)
+  #:use-module (guix hash)
   #:use-module (guix base32)
   #:export (<derivation>
             derivation?
diff --git a/guix/hash.scm b/guix/hash.scm
new file mode 100644 (file)
index 0000000..1c7e342
--- /dev/null
@@ -0,0 +1,49 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix hash)
+  #:use-module (guix config)
+  #:use-module (rnrs bytevectors)
+  #:use-module (system foreign)
+  #:export (sha256))
+
+;;; Commentary:
+;;;
+;;; Cryptographic hashes.
+;;;
+;;; Code:
+
+\f
+;;;
+;;; Hash.
+;;;
+
+(define sha256
+  (let ((hash   (pointer->procedure void
+                                    (dynamic-func "gcry_md_hash_buffer"
+                                                  (dynamic-link %libgcrypt))
+                                    `(,int * * ,size_t)))
+        (sha256 8))                        ; GCRY_MD_SHA256, as of 1.5.0
+    (lambda (bv)
+      "Return the SHA256 of BV as a bytevector."
+      (let ((digest (make-bytevector (/ 256 8))))
+        (hash sha256 (bytevector->pointer digest)
+              (bytevector->pointer bv) (bytevector-length bv))
+        digest))))
+
+;;; hash.scm ends here
index da5fa5b..3fbda03 100644 (file)
@@ -19,6 +19,7 @@
 (define-module (guix scripts download)
   #:use-module (guix ui)
   #:use-module (guix store)
+  #:use-module (guix hash)
   #:use-module (guix utils)
   #:use-module (guix base32)
   #:use-module (guix download)
index 1b14aaa..ca3928b 100644 (file)
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (guix scripts hash)
-    #:use-module (guix base32)
-    #:use-module (guix ui)
-    #:use-module (guix utils)
-    #:use-module (rnrs io ports)
-    #:use-module (rnrs files)
-    #:use-module (ice-9 match)
-    #:use-module (srfi srfi-1)
-    #:use-module (srfi srfi-26)
-    #:use-module (srfi srfi-37)
-    #:export (guix-hash))
+  #:use-module (guix base32)
+  #:use-module (guix hash)
+  #:use-module (guix ui)
+  #:use-module (guix utils)
+  #:use-module (rnrs io ports)
+  #:use-module (rnrs files)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
+  #:use-module (srfi srfi-37)
+  #:export (guix-hash))
 
 \f
 ;;;
index b8d4efd..aa74d63 100644 (file)
@@ -19,6 +19,7 @@
 
 (define-module (guix scripts refresh)
   #:use-module (guix ui)
+  #:use-module (guix hash)
   #:use-module (guix store)
   #:use-module (guix utils)
   #:use-module (guix packages)
index 2478fb6..4187efd 100644 (file)
@@ -36,7 +36,6 @@
   #:autoload   (system foreign) (pointer->procedure)
   #:export (bytevector->base16-string
             base16-string->bytevector
-            sha256
 
             %nixpkgs-directory
             nixpkgs-derivation
@@ -138,23 +137,6 @@ evaluate to a simple datum."
                    s)
       bv)))
 
-\f
-;;;
-;;; Hash.
-;;;
-
-(define sha256
-  (let ((hash   (pointer->procedure void
-                                    (dynamic-func "gcry_md_hash_buffer"
-                                                  (dynamic-link %libgcrypt))
-                                    `(,int * * ,size_t)))
-        (sha256 8))                        ; GCRY_MD_SHA256, as of 1.5.0
-    (lambda (bv)
-      "Return the SHA256 of BV as a bytevector."
-      (let ((digest (make-bytevector (/ 256 8))))
-        (hash sha256 (bytevector->pointer digest)
-              (bytevector->pointer bv) (bytevector-length bv))
-        digest))))
 
 \f
 ;;;
index d674547..81d2423 100644 (file)
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -17,6 +17,7 @@
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (test-base32)
+  #:use-module (guix hash)
   #:use-module (guix base32)
   #:use-module (guix utils)
   #:use-module (srfi srfi-1)
index 0cba98e..788cffd 100644 (file)
@@ -21,6 +21,7 @@
   #:use-module (guix derivations)
   #:use-module (guix store)
   #:use-module (guix utils)
+  #:use-module (guix hash)
   #:use-module (guix base32)
   #:use-module ((guix packages) #:select (package-derivation))
   #:use-module ((gnu packages) #:select (search-bootstrap-binary))
index b42bc97..3d5d59b 100644 (file)
@@ -20,6 +20,7 @@
 (define-module (test-store)
   #:use-module (guix store)
   #:use-module (guix utils)
+  #:use-module (guix hash)
   #:use-module (guix base32)
   #:use-module (guix packages)
   #:use-module (guix derivations)