bare64 0.1.0

A minimal, zero-dependency Base64 encoder/decoder in pure Rust
Documentation
# baz64

A zero-dependency base64 encoding/decoding library for Rust, implementing [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648).

## 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()` and `pem::encode()` accept anything that implements `AsRef<[u8]>` (`&[u8]`, `Vec<u8>`, `String`, etc.)

## Usage

```rust
// 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

```rust
// 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

```rust
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](API.md) for the full public API surface.

## License

See repository for license details.