aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--module/crypto.scm10
-rw-r--r--tests/test/crypto.scm6
2 files changed, 9 insertions, 7 deletions
diff --git a/module/crypto.scm b/module/crypto.scm
index 6428f16d..79eaaf89 100644
--- a/module/crypto.scm
+++ b/module/crypto.scm
@@ -28,11 +28,7 @@
((@ (system foreign) bytevector->pointer) md))
md)
-(define (checksum->string md)
- (string-concatenate
- (map (lambda (byte)
- (format #f "~x~x"
- (logand #xF (ash byte -4))
- (logand #xF byte)))
- (bytevector->u8-list md))))
+(define* (checksum->string md #:optional port)
+ ((@ (ice-9 format) format) port
+ "~{~2'0x~}" (bytevector->u8-list md)))
diff --git a/tests/test/crypto.scm b/tests/test/crypto.scm
index 610ac819..71ecfc99 100644
--- a/tests/test/crypto.scm
+++ b/tests/test/crypto.scm
@@ -7,3 +7,9 @@
(test-equal "sha256 string digest"
"185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969"
(checksum->string (sha256 "Hello")))
+
+(let ((port (open-output-string)))
+ (checksum->string (sha256 "Hello") port)
+ (test-equal "sha256 string digest to port"
+ "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969"
+ (get-output-string port)))