feat(stdlib): add ard/base64 encoding module#81
Merged
Conversation
Adds base64 encoding/decoding to the standard library with three variants: - encode/decode: standard base64 with padding - encode_url/decode_url: base64url with padding - encode_url_no_pad/decode_url_no_pad: base64url without '=' padding These map 1:1 to Go's encoding/base64 StdEncoding, URLEncoding, and RawURLEncoding. Motivation: the no-pad url-safe variant is required by PKCE (OAuth 2.1) for base64url(sha256(verifier)), and by JWT headers/payloads. Notes: - Module path is 'ard/base64' (flat, matching existing stdlib layout) rather than 'ard/encoding/base64' — nested stdlib paths aren't currently supported by std_lib/embed.go. - Decode functions return Str!Str so invalid input produces a recoverable Result::err with the underlying Go error message.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The stdlib test functions in std_lib/base64.ard already cover all the cases from base64_test.go. Both run against the same bytecode VM, so keeping both was pure duplication.
Collapse encode_url_no_pad/decode_url_no_pad into encode_url/decode_url
with an optional Bool? parameter to opt out of padding:
base64::encode_url("f") // "Zg==" (padded, default)
base64::encode_url("f", true) // "Zg" (no padding, for JWT/PKCE)
Also fixes a runtime inconsistency: AsBool and AsFloat now unwrap raw
values like AsInt and AsString, so FFI functions with nullable Bool?/
Float? parameters work correctly with the checker's automatic wrapping
of non-nullable arguments.
Both standard and URL-safe variants now accept the same optional no_pad parameter, matching Go's base64 API which exposes RawStdEncoding and RawURLEncoding symmetrically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds base64 encoding/decoding to the standard library with all three common variants.
Motivation
The no-pad URL-safe variant is required by:
base64url(sha256(verifier))with no paddingThis blocks implementing Oauth for MCP servers.
Mapping
encode/decodebase64.StdEncodingencode_url/decode_urlbase64.URLEncodingencode_url_no_pad/decode_url_no_padbase64.RawURLEncodingDecode functions return
Str!Str, so invalid input produces a recoverableResult::errwith the underlying Go error message.Notes
ard/base64(flat, matching existing stdlib layout) rather thanard/encoding/base64. Nested stdlib paths aren't currently supported bystd_lib/embed.go; can be revisited later if more encoding modules are added.Tests
compiler/bytecode/vm/base64_test.go: 11 VM tests covering encode/decode round-trips, all three variants, padding behavior, and error handling.compiler/std_lib/base64.ard: 13 inlinetest fncases (run viaard test std_lib).