base-n 0.1.0

A Base32 library supporting multiple alphabats.
Documentation
  • Coverage
  • 16.13%
    5 out of 31 items documented2 out of 15 items with examples
  • Size
  • Source code size: 42.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 202.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Leawind/base-n
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Leawind

base-n

A Base32 encoding/decoding library supporting multiple alphabats.

It is #![no_std] compatible.

Usage

Encode data using RFC 4648 with padding

use base_n::{Encoder, base32, Decoder};

fn main() {
    let data = 0xB93246A429u64.to_be_bytes().to_vec();
    assert_eq!(&data, &[0, 0, 0, 0xB9, 0x32, 0x46, 0xa4, 0x29]);
    
    // Encoding
    let encoded = base32::RFC4648_PAD.encode(&data);
    assert_eq!(encoded, "AAAABOJSI2SCS===");
    
    // Decoding
    let decoded = base32::RFC4648_PAD.decode(&encoded).unwrap();
    assert_eq!(data, decoded);
}

Customized alphabet

use base_n::{Encoder, base32::Base32Variant};
const CUSTOM_BASE32: Base32Variant = Base32Variant::builder()
    .name("Custom")
    .mapping(b"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456")
    .build();
println!("{}", CUSTOM_BASE32.encode(b"Hello, world!")); // JBSWY2DPFQQHO22SNRSCC

Multiple Base32 variants support