bare64 0.1.0

A minimal, zero-dependency Base64 encoder/decoder in pure Rust
Documentation
  • Coverage
  • 17.65%
    3 out of 17 items documented0 out of 4 items with examples
  • Size
  • Source code size: 49.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.52 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • tankyleo
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 inputencode() and pem::encode() accept anything that implements AsRef<[u8]> (&[u8], Vec<u8>, String, etc.)

Usage

// Encode
let encoded = baz64::encode(b"Hello, world!");
assert_eq!(encoded, "SGVsbG8sIHdvcmxkIQ==");

// Decode
let decoded = baz64::decode("SGVsbG8sIHdvcmxkIQ==").unwrap();
assert_eq!(decoded, b"Hello, world!");

URL-safe base64

// Encode (no padding, uses - and _ instead of + and /)
let encoded = baz64::encode_url_safe(b"Hello, world!");
assert_eq!(encoded, "SGVsbG8sIHdvcmxkIQ");

// Decode (accepts input with or without padding)
let decoded = baz64::decode_url_safe("SGVsbG8sIHdvcmxkIQ").unwrap();
assert_eq!(decoded, b"Hello, world!");

PEM

use baz64::pem;

// Wrap DER bytes in a PEM block
let pem_str = pem::encode(b"\xDE\xAD\xBE\xEF", "CERTIFICATE");
// -----BEGIN CERTIFICATE-----
// 3q2+7w==
// -----END CERTIFICATE-----

// Decode the first matching PEM block
let der = pem::decode(&pem_str, "CERTIFICATE").unwrap();

// Decode all matching PEM blocks (returns empty Vec if none match)
let all_certs = pem::decode_all(&pem_str, "CERTIFICATE").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.