Skip to main content

Crate base64_ng

Crate base64_ng 

Source
Expand description

base64-ng is a no_std-first Base64 encoder and decoder.

This initial release provides strict scalar RFC 4648-style behavior and caller-owned output buffers. Future SIMD fast paths, including AVX, NEON, and wasm simd128 candidates, will be required to match this scalar module byte-for-byte.

§Examples

Encode and decode with caller-owned buffers:

use base64_ng::{STANDARD, checked_encoded_len};

let input = b"hello";
const ENCODED_CAPACITY: usize = match checked_encoded_len(5, true) {
    Some(len) => len,
    None => panic!("encoded length overflow"),
};
let mut encoded = [0u8; ENCODED_CAPACITY];
let encoded_len = STANDARD.encode_slice(input, &mut encoded).unwrap();
assert_eq!(&encoded[..encoded_len], b"aGVsbG8=");

let mut decoded = [0u8; 5];
let decoded_len = STANDARD.decode_slice(&encoded, &mut decoded).unwrap();
assert_eq!(&decoded[..decoded_len], input);

Use the URL-safe no-padding engine:

use base64_ng::URL_SAFE_NO_PAD;

let mut encoded = [0u8; 3];
let encoded_len = URL_SAFE_NO_PAD.encode_slice(b"\xfb\xff", &mut encoded).unwrap();
assert_eq!(&encoded[..encoded_len], b"-_8");

Modules§

ct
Constant-time-oriented scalar decoding APIs.
runtime
Runtime backend reporting for security-sensitive deployments.
stream
Streaming Base64 wrappers for std::io.

Macros§

define_alphabet
Defines a custom Alphabet from a 64-byte string literal.

Structs§

Bcrypt
The bcrypt Base64 alphabet.
Crypt
The Unix crypt(3) Base64 alphabet.
DecodedBuffer
Stack-backed decoded Base64 output.
EncodedBuffer
Stack-backed encoded Base64 output.
Engine
A zero-sized Base64 engine parameterized by alphabet and padding policy.
LineWrap
Base64 line wrapping policy.
Profile
A named Base64 profile with an engine and optional strict line wrapping.
SecretBuffer
Owned sensitive bytes with redacted formatting and drop-time cleanup.
Standard
The RFC 4648 standard Base64 alphabet.
UrlSafe
The RFC 4648 URL-safe Base64 alphabet.

Enums§

AlphabetError
Alphabet validation error.
DecodeError
Decoding error.
EncodeError
Encoding error.
LineEnding
Line ending used by wrapped Base64 output.

Constants§

BCRYPT
bcrypt-style no-padding Base64 profile.
BCRYPT_NO_PAD
bcrypt-style Base64 engine without padding.
CRYPT
Unix crypt(3)-style no-padding Base64 profile.
CRYPT_NO_PAD
Unix crypt(3)-style Base64 engine without padding.
MIME
MIME Base64 profile: standard alphabet, padding, 76-column CRLF wrapping.
PEM
PEM Base64 profile: standard alphabet, padding, 64-column LF wrapping.
PEM_CRLF
PEM Base64 profile with CRLF line endings.
STANDARD
Standard Base64 engine with padding.
STANDARD_NO_PAD
Standard Base64 engine without padding.
URL_SAFE
URL-safe Base64 engine with padding.
URL_SAFE_NO_PAD
URL-safe Base64 engine without padding.

Traits§

Alphabet
A Base64 alphabet.

Functions§

checked_encoded_len
Returns the encoded length, or None if it would overflow usize.
checked_wrapped_encoded_len
Returns the encoded length after line wrapping, or None on overflow or invalid line wrapping.
decode_alphabet_byte
Decodes one byte by scanning a caller-provided alphabet table.
decoded_capacity
Returns the maximum decoded length for an encoded input length.
decoded_len
Returns the exact decoded length implied by input length and padding.
encoded_len
Returns the encoded length for an input length and padding policy.
validate_alphabet
Validates a 64-byte Base64 alphabet table.
wrapped_encoded_len
Returns the encoded length after applying a line wrapping policy.