yabase/base32/crockford
Values
pub fn decode(
input: String,
) -> Result(BitArray, error.CodecError)
Decode a Crockford Base32 string to a BitArray. Accepts hyphens (ignored). O->0, I/L->1. Case-insensitive.
pub fn decode_check(
input: String,
) -> Result(BitArray, error.CodecError)
Decode a Crockford Base32 string with check symbol verification. The last character is the check symbol; the rest is the encoded data. Returns Error(InvalidChecksum) if the check symbol does not match.
pub fn encode(data: BitArray) -> String
Encode a BitArray to a Crockford Base32 string (bignum shape).
The input is treated as a big-endian unsigned integer and converted to base 32 using Crockford’s alphabet, with leading zero digits stripped. As a result the output length varies with the numeric magnitude of the input, not with its byte length — see the module-level docstring for the implications (issue #22).
If you want fixed-length 8-character output for every 5-byte
input (the byte-aligned framing ULID / NanoID expect), use
yabase/base32/rfc4648.encode
instead.
pub fn encode_check(data: BitArray) -> String
Encode a BitArray to Crockford Base32 with a check symbol appended. The check symbol is computed as the numeric value of the data mod 37, mapped to the 37-character check alphabet (0-9A-Z plus *~$=U).