yabase/base32/rfc4648

Values

pub fn decode(
  input: String,
) -> Result(BitArray, error.CodecError)

Decode a Base32 string (with or without padding) to a BitArray.

Non-alphabet characters (whitespace, CR/LF, punctuation outside A-Z, 2-7, and =) are rejected with InvalidCharacter carrying the offending byte and its position. The alphabet check runs before the length check so the caller does not see a misleading InvalidLength when the real fault is an out-of-alphabet byte.

pub fn decode_strict(
  input: String,
) -> Result(BitArray, error.CodecError)

Decode input and additionally reject non-canonical encodings per RFC 4648 §3.5 / §6: the canonical form is the uppercase, padded shape produced by encode/1, and any deviation (lowercase, mixed case, missing padding, non-zero pad bits in a final partial block) is rejected with Error(NonCanonical). Useful for signature verification, content-addressable storage, and replay-attack-resistant token handling, where the wire encoding’s uniqueness is part of the contract.

Returns Error(NonCanonical) when the input is not byte-equal to encode(decode(input)). Other failure modes (InvalidCharacter, InvalidLength) are surfaced unchanged from decode/1.

pub fn encode(data: BitArray) -> String

Encode a BitArray to a Base32 string with padding.

Sub-byte input panics; see yabase/core/guard.assert_byte_aligned.

Search Document