1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2015, 2020 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-base32)
20 #:use-module (gcrypt hash)
21 #:use-module (guix base32)
22 #:use-module (guix utils)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-34)
25 #:use-module (srfi srfi-64)
26 #:use-module (ice-9 match)
27 #:use-module (rnrs bytevectors)
28 #:use-module (rnrs io ports))
30 ;; Test the (guix base32) module.
34 (test-assert "bytevector->base32-string"
35 (fold (lambda (bv expected result)
37 (string=? (bytevector->base32-string bv)
41 ;; Examples from RFC 4648.
42 (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))
51 (test-assert "base32-string->bytevector"
53 (equal? (base32-string->bytevector
54 (bytevector->base32-string bv))
56 ;; Examples from RFC 4648.
57 (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))))
59 (test-assert "nix-base32-string->bytevector"
61 (equal? (nix-base32-string->bytevector
62 (bytevector->nix-base32-string bv))
64 ;; Examples from RFC 4648.
65 (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))))
67 (test-equal "&invalid-base32-character"
69 (guard (c ((invalid-base32-character? c)
70 (invalid-base32-character-value c)))
71 (nix-base32-string->bytevector
72 (string-append (make-string 51 #\a) "e"))))