base64url_nopad

Crates.iobase64url_nopad
lib.rsbase64url_nopad
version0.1.1
created_at2025-08-08 20:11:29.607198+00
updated_at2025-08-26 15:36:59.703874+00
descriptionEfficient and correct base64url without padding encoding and decoding
homepage
repositoryhttps://git.philomathiclife.com/repos/base64url_nopad/
max_upload_size
id1787320
size100,566
philomathic_life (zacknewman)

documentation

https://docs.rs/base64url_nopad/latest/base64url_nopad/

README

base64url_nopad

git crates.io docs.rs

base64url_nopad is a library for efficient and correct encoding and decoding of base64url without padding data. All functions that can be const are const. Great care is made to ensure all arithmetic is free from "side effects" (e.g., overflow). panics are avoided at all costs unless explicitly documented including panics related to memory allocations.

base64url_nopad in action

use base64url_nopad::DecodeErr;
/// Length of our input to encode.
const INPUT_LEN: usize = 259;
/// The base64url encoded value without padding of our input.
const ENCODED_VAL: &str = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0-P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn-AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq-wsbKztLW2t7i5uru8vb6_wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t_g4eLj5OXm5-jp6uvs7e7v8PHy8_T19vf4-fr7_P3-_1MH0Q";
fn main() -> Result<(), DecodeErr> {
    let mut input = [0; INPUT_LEN];
    for i in 0..=255 {
        input[usize::from(i)] = i;
    }
    input[256] = 83;
    input[257] = 7;
    input[258] = 209;
    let mut output = [0; base64url_nopad::encode_len(INPUT_LEN)];
    assert_eq!(base64url_nopad::encode_buffer(&input, &mut output), ENCODED_VAL);
    assert!(base64url_nopad::decode_len(output.len()).is_some_and(|len| len == INPUT_LEN));
    base64url_nopad::decode_buffer(ENCODED_VAL.as_bytes(), &mut output[..INPUT_LEN])?;
    assert_eq!(input, output[..INPUT_LEN]);
}

Cargo "features"

alloc

Enables support for memory allocations via alloc.

Correctness of code

This library is written in a way that is free from any overflow, underflow, or other kinds of "arithmetic side effects". All functions that can panic are explicitly documented as such; and all possible panics are isolated to convenience functions that panic instead of error. Strict encoding and decoding is performed; thus if an input contains any invalid data, it is guaranteed to fail when decoding it (e.g., trailing non-zero bits).

Minimum Supported Rust Version (MSRV)

This will frequently be updated to be the same as stable. Specifically, any time stable is updated and that update has "useful" features or compilation no longer succeeds (e.g., due to new compiler lints), then MSRV will be updated.

MSRV changes will correspond to a SemVer patch version bump pre-1.0.0; otherwise a minor version bump.

SemVer Policy

  • All on-by-default features of this library are covered by SemVer
  • MSRV is considered exempt from SemVer as noted above

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Before any PR is sent, cargo clippy and cargo t should be run for each possible combination of "features" using stable Rust. One easy way to achieve this is by building ci and invoking it with no commands in the base64url_nopad directory or sub-directories. You can fetch ci via git clone https://git.philomathiclife.com/repos/ci, and it can be built with cargo build --release. Additionally, RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features should be run to ensure documentation can be built.

Status

The crate is only tested on the x86_64-unknown-linux-gnu, x86_64-unknown-openbsd, and aarch64-apple-darwin targets; but it should work on most platforms.

Commit count: 0

cargo fmt