Skip to main content

Crate base58_turbo

Crate base58_turbo 

Source
Expand description

§Base58 Turbo

Crates.io Documentation License MIRI Verified Logic Tests

A high-performance Base58 encoder/decoder for Rust, optimized for high-throughput systems.

This crate provides highly optimized scalar kernels for encoding and decoding, supporting no_std environments and zero-allocation processing.

§Usage

Add this to your Cargo.toml:

[dependencies]
base58-turbo = "0.1"

§Basic API (Allocating)

Standard usage for general applications. Requires the std feature (enabled by default).

use base58_turbo::BITCOIN;

let data = b"Hello World";
let encoded = BITCOIN.encode(data).unwrap();
assert_eq!(encoded, "JxF12TrwUP45BMd");

let decoded = BITCOIN.decode(&encoded).unwrap();
assert_eq!(decoded, data);

§Zero-Allocation API (Slice-based)

For low-latency scenarios or no_std environments where heap allocation is undesirable. These methods write directly into a user-provided mutable slice.

use base58_turbo::BITCOIN;

let data = b"Hello World";
let mut output = [0u8; 32];

let len = BITCOIN.encode_into(data, &mut output).unwrap();
let encoded = std::str::from_utf8(&output[..len]).unwrap();
assert_eq!(encoded, "JxF12TrwUP45BMd");

§Feature Flags

This crate is lightweight and configurable via Cargo features:

FeatureDefaultDescription
serdeNoEnables serde serialization/deserialization for Config and Engine.
stdYesEnables String and Vec support. Disable this for no_std environments.

§Safety & Verification

This crate utilizes unsafe code for pointer arithmetic and optimized kernels to achieve maximum performance.

  • MIRI Tests: Core logic and fallbacks are verified with MIRI (Undefined Behavior checker) in CI.
  • MSan Audited: MemorySanitizer confirms no logic is ever performed on uninitialized memory.
  • Fuzzing: The codebase is continuously fuzz-tested via cargo-fuzz.

Learn More: Details on our threat model and strict verification strategy.

Structs§

Config
Internal configuration containing pre-computed tables for an alphabet.
Engine
A Base58 Encoder/Decoder Engine.

Enums§

Error
Errors that can occur during Base58 encoding or decoding operations or alphabet creation.

Constants§

BITCOIN
Standard Bitcoin Base58 Engine.
FLICKR
Flickr Base58 Engine.
MONERO
Monero Base58 Engine.
RIPPLE
Ripple Base58 Engine.