base32.scm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2015, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  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.
  10. ;;;
  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.
  15. ;;;
  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/>.
  18. (define-module (test-base32)
  19. #:use-module (gcrypt hash)
  20. #:use-module (guix base32)
  21. #:use-module (guix utils)
  22. #:use-module (srfi srfi-1)
  23. #:use-module (srfi srfi-34)
  24. #:use-module (srfi srfi-64)
  25. #:use-module (ice-9 match)
  26. #:use-module (rnrs bytevectors)
  27. #:use-module (rnrs io ports))
  28. ;; Test the (guix base32) module.
  29. (test-begin "base32")
  30. (test-assert "bytevector->base32-string"
  31. (fold (lambda (bv expected result)
  32. (and result
  33. (string=? (bytevector->base32-string bv)
  34. expected)))
  35. #t
  36. ;; Examples from RFC 4648.
  37. (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))
  38. '(""
  39. "my"
  40. "mzxq"
  41. "mzxw6"
  42. "mzxw6yq"
  43. "mzxw6ytb"
  44. "mzxw6ytboi")))
  45. (test-assert "base32-string->bytevector"
  46. (every (lambda (bv)
  47. (equal? (base32-string->bytevector
  48. (bytevector->base32-string bv))
  49. bv))
  50. ;; Examples from RFC 4648.
  51. (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))))
  52. (test-assert "nix-base32-string->bytevector"
  53. (every (lambda (bv)
  54. (equal? (nix-base32-string->bytevector
  55. (bytevector->nix-base32-string bv))
  56. bv))
  57. ;; Examples from RFC 4648.
  58. (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))))
  59. (test-equal "&invalid-base32-character"
  60. #\e
  61. (guard (c ((invalid-base32-character? c)
  62. (invalid-base32-character-value c)))
  63. (nix-base32-string->bytevector
  64. (string-append (make-string 51 #\a) "e"))))
  65. (test-end)