bare64-0.1.0 has been yanked.
baz64
A zero-dependency base64 encoding/decoding library for Rust, implementing RFC 4648.
Features
- Zero dependencies — pure Rust, no external crates
- Encode & decode — standard base64 with
=padding - URL-safe base64 — RFC 4648 Section 5 alphabet (
-_instead of+/), no padding - PEM support — encode/decode PEM (Privacy-Enhanced Mail) blocks
- Strict validation — rejects invalid bytes, bad padding, incorrect lengths, and non-zero trailing bits
- Flexible input —
encode()andpem::encode()accept anything that implementsAsRef<[u8]>(&[u8],Vec<u8>,String, etc.)
Usage
// Encode
let encoded = encode;
assert_eq!;
// Decode
let decoded = decode.unwrap;
assert_eq!;
URL-safe base64
// Encode (no padding, uses - and _ instead of + and /)
let encoded = encode_url_safe;
assert_eq!;
// Decode (accepts input with or without padding)
let decoded = decode_url_safe.unwrap;
assert_eq!;
PEM
use pem;
// Wrap DER bytes in a PEM block
let pem_str = encode;
// -----BEGIN CERTIFICATE-----
// 3q2+7w==
// -----END CERTIFICATE-----
// Decode the first matching PEM block
let der = decode.unwrap;
// Decode all matching PEM blocks (returns empty Vec if none match)
let all_certs = decode_all.unwrap;
Error Handling
decode() and decode_url_safe() return Result<Vec<u8>, DecodeError>:
| Error | Meaning |
|---|---|
InvalidByte(u8, usize) |
Non-base64 byte at the given position |
InvalidLength(usize) |
Input length is not valid for the decoding mode |
InvalidPadding |
Padding is malformed or has non-zero trailing bits |
PEM operations return Result<_, PemError>:
| Error | Meaning |
|---|---|
NoBlockFound |
No PEM block with the requested label was found (decode only) |
MalformedBlock |
BEGIN marker found but no matching END marker |
InvalidBase64(DecodeError) |
The base64 content within the block is invalid |
API Reference
See API.md for the full public API surface.
License
See repository for license details.