base64.scm 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ;;; guile-gcrypt --- crypto tooling for guile
  2. ;;;
  3. ;;; Code taken from:
  4. ;;;
  5. ;;; GNU Guix --- Functional package management for GNU
  6. ;;; Copyright © 2014 Nikita Karetnikov <nikita@karetnikov.org>
  7. ;;;
  8. ;;; This file is part of guile-gcrypt.
  9. ;;;
  10. ;;; guile-gcrypt is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or
  13. ;;; (at your option) any later version.
  14. ;;;
  15. ;;; guile-gcrypt is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. ;;; General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with guile-gcrypt. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (test-base64)
  23. #:use-module (gcrypt base64)
  24. #:use-module (rnrs bytevectors)
  25. #:use-module (srfi srfi-64))
  26. (define (string->base64 str)
  27. (base64-encode (string->utf8 str)))
  28. ;;; Test vectors from <https://tools.ietf.org/rfc/rfc4648.txt>.
  29. (test-begin "base64")
  30. (test-equal "empty string"
  31. (string->base64 "")
  32. "")
  33. (test-equal "f"
  34. (string->base64 "f")
  35. "Zg==")
  36. (test-equal "fo"
  37. (string->base64 "fo")
  38. "Zm8=")
  39. (test-equal "foo"
  40. (string->base64 "foo")
  41. "Zm9v")
  42. (test-equal "foob"
  43. (string->base64 "foob")
  44. "Zm9vYg==")
  45. (test-equal "fooba"
  46. (string->base64 "fooba")
  47. "Zm9vYmE=")
  48. (test-equal "foobar"
  49. (string->base64 "foobar")
  50. "Zm9vYmFy")
  51. (test-end "base64")