Skip to main content

Crate base32

Crate base32 

Source
Expand description

Fast base32 encoding and decoding with SIMD acceleration, constant-time operations, and const fn support.

Nine alphabet variants are available via Alphabet:

VariantCharactersPaddingDescription
Rfc4648A-Z 2-7=RFC 4648 (standard)
Rfc4648NoPaddingA-Z 2-7noneRFC 4648 without padding
Rfc4648Lowera-z 2-7=RFC 4648 lowercase
Rfc4648LowerNoPaddinga-z 2-7noneRFC 4648 lowercase no pad
Rfc4648Hex0-9 A-V=RFC 4648 extended hex
Rfc4648HexNoPadding0-9 A-VnoneRFC 4648 extended hex no pad
Rfc4648HexLower0-9 a-v=RFC 4648 extended hex lower
Rfc4648HexLowerNoPadding0-9 a-vnoneRFC 4648 extended hex lower no pad
Crockford0-9 A-H J-K M-N P-ZnoneCrockford (no I L O U)

§Feature flags

FlagDescription
stdstd::error::Error trait impls (enabled by default)
allocString/Vec-returning convenience APIs
serdeSerde serialize/deserialize helpers

§Performance

The encode_into and decode_into functions automatically dispatch to SIMD-accelerated paths (AVX2 on x86/x86_64, NEON on aarch64). When a constant-time guarantee is required, use encode_into_constant_time or decode_into_constant_time.

§const fn support

encode_array and decode_array are const fn, enabling base32 encoding and decoding at compile time.

§Examples

let encoded = base32::encode(b"hello", base32::Alphabet::Rfc4648);
assert_eq!(encoded, "NBSWY3DP");

let decoded = base32::decode(b"NBSWY3DP", base32::Alphabet::Rfc4648).unwrap();
assert_eq!(decoded, b"hello");

let url = base32::encode(b"hello", base32::Alphabet::Crockford);
assert_eq!(url, "D1JPRV3F");

Enums§

Alphabet
DecodeError
EncodeError

Functions§

decodealloc
Decodes a base32 string into bytes.
decode_array
Decodes a base32 string into a fixed-size array at compile time.
decode_into
Decodes a base32 string into an existing buffer.
decode_into_constant_time
Constant-time base32 decoding. Processes all input data without secret-dependent branches or memory accesses, making it suitable for cryptographic applications.
encodealloc
Encode Encodes bytes to a base32 string using the given Alphabet.
encode_array
Encodes data into a fixed-size array at compile time.
encode_into
Encodes bytes into an existing buffer.
encode_into_constant_time
Constant-time base32 encoding. Processes all input data without secret-dependent branches or memory accesses, making it suitable for cryptographic applications.
encode_into_stringalloc
Appends the base32-encoded representation of data to a String.
encoded_length
Returns the size in bytes of the input data after base32 encoding.