Commit5b52d812Recorded4 May 2026Repositorysigil-crypto

test: fix base64url alphabet test bytevector construction (Group C)

Message

The test built its 3-byte test vector via (base64-decode (base64-encode (string (integer->char #xfb) ...))) expecting to recover #u8(#xfb #xff #xbf). Sigil strings are UTF-8, so each codepoint > 127 expands to 2 UTF-8 bytes. The round-trip yielded 6 raw bytes (C3 BB C3 BF C2 BF) which encode to "w7vDv8K_" — exactly the actual failure output.

The encoder is correct: nativebase64encode handles both string and bytevector input by walking their raw byte buffers; bytevector input is not re-encoded. Verified via direct call: (base64url-encode #u8(#xfb #xff #xbf)) returns "--" as expected. Replaced the test setup with the bytevector literal.

Changed
 test/test-crypto.sgl | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Diff
test/test-crypto.sglmodified
@@ -306,12 +306,12 @@
306
307
(test "alphabet substitution: bytes encoding to + and /"
308
;; The 3-byte sequence #u8(#xfb #xff #xbf) base64-encodes to "+/+/".
309
;; In base64url it becomes "-_-_".
310
(let* ((bv (base64-decode (base64-encode (string (integer->char #xfb)
311
(integer->char #xff)
312
(integer->char #xbf)))))
313
(encoded (base64url-encode bv)))
314
(assert-equal "-_-_" encoded)))
+309
;; In base64url it becomes "-_-_". Feed a bytevector literal —
+310
;; constructing one via (base64-decode (base64-encode (string ...)))
+311
;; round-trips through Sigil's UTF-8 string representation: each
+312
;; codepoint > 127 expands to a 2-byte UTF-8 sequence, so the
+313
;; round-trip yields 6 raw bytes (the UTF-8 form), not 3.
+314
(assert-equal "-_-_" (base64url-encode #u8(#xfb #xff #xbf))))
315
316
(test "round-trip random bytes"
317
(let* ((bv (random-bytes 32))