Commit Graph
8 Commits
Author SHA1 Message Date
Ihor Antonov a5bef5224c core: add unpadded base64 encoding
core:encoding/base64 can only produce padded output, so callers that need
the canonical unpadded ("raw") form -- JOSE base64url, Go's
RawStdEncoding/RawURLEncoding -- have to encode and then trim, which
forces an extra allocation and cleanup dance around the returned string.

Add an Encode_Options bit set, mirroring Decode_Options, and honor
{.No_Padding} in `encode`, `encode_into_buf`, `encode_into`, and
`encoded_len`. Existing calls and padded output are unchanged.

Tests cover the RFC 4648 section 9 illustrations and section 10 test
vectors across the standard and URL alphabets, padded and raw, plus Go's
reference corpus. Newline characters are asserted to be rejected per
RFC 4648 section 3.3. Comments in `encode_impl` document the 24-bit group
packing and the padding decision for partial groups.
2026-09-30 19:53:10 -07:00
Ihor Antonov 2109ba8fbd core: add strict base64 decoding
core:encoding/base64 currently decodes leniently: it infers padding from the
last one or two bytes, accepts missing/extra/interior padding, and does not
check the trailing padding bits required by RFC 4648 Section 3.5.
Go exposes canonical decoding as `Encoding.Strict()`; Odin has no equivalent,
so downstream ports (e.g. age) have to reimplement base64 from scratch.

This adds opt-in strict decoding through a `Decode_Options` bit set.
Existing calls and behavior are unchanged.
2026-09-28 19:59:23 -07:00
Yawning Angel 82a18797b4 core/encoding/base64: Misc fixes and improvements
- Add error checking to `decode`
- Add `encode_into_buf`/`decode_into_buf`
2026-05-26 00:38:50 +09:00
rykad 454f75cb22 core:encoding/base64: add support for url variant 2026-01-17 22:26:25 +00:00
Jeroen van Rijn 1fb95dade2 Expand base64 tests to include roundtrip 2025-11-22 15:44:19 +01:00
Jeroen van Rijn a27b167218 Update tests\core\encoding\cbor to use new test runner.
It was leaky and required a substantial number of `loc := #caller_location` additions to parts of the core library to make it easier to track down how and where it leaked.

The tests now run fine multi-threaded.
2024-06-02 14:47:07 -04:00
Laytan 0076c07076 encoding/cbor: core -> base 2024-03-04 17:26:19 +01:00
Laytan Laats b6c47e7963 encoding/base64: add decode_into, add tests 2024-03-04 17:26:17 +01:00