Expand description
Fast base32 encoding and decoding with SIMD acceleration, constant-time
operations, and const fn support.
Nine alphabet variants are available via Alphabet:
| Variant | Characters | Padding | Description |
|---|---|---|---|
Rfc4648 | A-Z 2-7 | = | RFC 4648 (standard) |
Rfc4648NoPadding | A-Z 2-7 | none | RFC 4648 without padding |
Rfc4648Lower | a-z 2-7 | = | RFC 4648 lowercase |
Rfc4648LowerNoPadding | a-z 2-7 | none | RFC 4648 lowercase no pad |
Rfc4648Hex | 0-9 A-V | = | RFC 4648 extended hex |
Rfc4648HexNoPadding | 0-9 A-V | none | RFC 4648 extended hex no pad |
Rfc4648HexLower | 0-9 a-v | = | RFC 4648 extended hex lower |
Rfc4648HexLowerNoPadding | 0-9 a-v | none | RFC 4648 extended hex lower no pad |
Crockford | 0-9 A-H J-K M-N P-Z | none | Crockford (no I L O U) |
§Feature flags
| Flag | Description |
|---|---|
std | std::error::Error trait impls (enabled by default) |
alloc | String/Vec-returning convenience APIs |
serde | Serde 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§
Functions§
- decode
alloc - 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.
- encode
alloc - Encode
Encodes bytes to a base32 string using the given
Alphabet. - encode_
array - Encodes
datainto 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_ string alloc - Appends the base32-encoded representation of
datato aString. - encoded_
length - Returns the size in bytes of the input data after base32 encoding.