core:base64
Base64 encoding and decoding (RFC 4648): standard and URL-safe alphabets,
configurable padding via Encoding flags, and two decoders. [decode]
accepts either alphabet with or without padding; [decode_url_strict]
accepts only the canonical URL-safe unpadded spelling. Entry points accept
any AsByteSlice source (ByteList, ByteArray, ByteSlice, or String).
Synopsis
let encoded = encode(&b"Hello, Wado!");
assert encoded == "SGVsbG8sIFdhZG8h";
assert decode(&encoded) matches { Some(round) && encode(&round) == encoded };
Functions
pub fn encode<S: AsByteSlice>(data: &S) -> String
Encodes bytes as standard Base64 (RFC 4648 §4, padded).
pub fn encode_url<S: AsByteSlice>(data: &S) -> String
Encodes bytes as URL-safe Base64 (RFC 4648 §5, no padding).
Equivalent to encode_with(data, Encoding::UrlSafe | Encoding::NoPadding).
pub fn encode_with<S: AsByteSlice>(data: &S, encoding: Encoding) -> String
Encodes bytes as Base64 with custom flags.
pub fn decode<S: AsByteSlice>(encoded: &S) -> Option<ByteList>
Decodes Base64 from text or raw bytes (e.g., HTTP body, file content). Accepts both standard (+/) and URL-safe (-_) alphabets, with or without padding. Returns null on invalid input.
pub fn decode_url_strict<S: AsByteSlice>(encoded: &S) -> Option<ByteList>
Decodes URL-safe Base64 (RFC 4648 §5, unpadded), the exact inverse of
[encode_url] and the encoding JWS/JWT mandate.
This one is canonical where [decode] is lenient. It rejects everything
encode_url never writes: the standard alphabet's + and /, =
padding, and a final group whose unused bits are set. One byte string
therefore has exactly one accepted spelling. Use [decode] for input from
a producer you do not control.
