Crates.io | base64url_nopad |
lib.rs | base64url_nopad |
version | 0.1.1 |
created_at | 2025-08-08 20:11:29.607198+00 |
updated_at | 2025-08-26 15:36:59.703874+00 |
description | Efficient and correct base64url without padding encoding and decoding |
homepage | |
repository | https://git.philomathiclife.com/repos/base64url_nopad/ |
max_upload_size | |
id | 1787320 |
size | 100,566 |
base64url_nopad
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). panic
s are avoided at all costs unless explicitly documented
including panic
s related to memory allocations.
base64url_nopad
in actionuse 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]);
}
alloc
Enables support for memory allocations via alloc
.
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 panic
s 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).
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.
Licensed under either of
at your option.
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.
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.