base64
RFC 4648 base64 encode + decode.
MVP scope : standard alphabet only (A-Z a-z 0-9 + /), strict
padding with =. URL-safe variant (- _, optional padding) is a
follow-up: call site is small (alphabet + sentinel for the missing
pad).
Pure Vader, zero host imports: WASM-ready as-is.
Types
Base64Error :: struct Error returned by decode when the input violates RFC 4648.
Fields
msg: string Functions
encode :: fn(input: u8[]) -> string Encode raw bytes as a base64 string (standard alphabet, =-padded). The
output is always ASCII ; its length is 4 * ceil(input.len() / 3). To
encode text, pass text.bytes().
Parameters
| input | u8[] | the raw bytes to encode. |
Returns
string decode :: fn(input: string) -> u8[] | Base64Error Decode a base64 string back to the raw bytes it encodes. Strict : input
length MUST be a multiple of 4 and padding MUST be canonical (one or two
trailing =, nothing else). Whitespace and newlines are NOT allowed:
strip them upstream if your transport adds them.
Returns u8[] rather than string so arbitrary binary round-trips
exactly : string is codepoint-based, so non-UTF-8 octets would not
survive a string round-trip. Call .bytes_to_string() on the result when the
payload is known to be valid UTF-8 text.
Parameters
| input | string | the base64 text (standard alphabet, =-padded). |
Returns
u8[] | Base64Error the decoded raw bytes.Errors
- Base64Error when
input.len()isn't a multiple of 4, or any non-alphabet character appears.