diff options
-rw-r--r-- | chickadee/base64.scm | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/chickadee/base64.scm b/chickadee/base64.scm index 89fc4bb..c12fa39 100644 --- a/chickadee/base64.scm +++ b/chickadee/base64.scm @@ -45,9 +45,9 @@ (let ((cache (make-hash-table))) (lambda (alphabet) (or (hash-ref cache alphabet) - (let ((bv (make-bytevector 128))) + (let ((bv (make-bytevector 128 -1))) (alphabet-for-each (lambda (i x) - (bytevector-u8-set! bv x i)) + (bytevector-s8-set! bv x i)) alphabet) (hash-set! cache alphabet bv) bv))))) @@ -56,7 +56,11 @@ "Decode the base64 encoded string @var{str} using @var{alphabet} and return a bytevector containing the decoded data." (define decoder (alphabet->decoder alphabet)) - (define (decode char) (bytevector-u8-ref decoder (char->integer char))) + (define (decode char) + (let ((x (bytevector-s8-ref decoder (char->integer char)))) + (when (eq? x -1) + (error "invalid base64 character" char)) + x)) (call-with-input-string str (lambda (in) (call-with-output-bytevector |