B58UUID for Rust
Base58-encoded UUID library for Rust with minimal dependencies.
Why This Library?
- Compact: 22 characters instead of 36
- URL-safe: No special characters that need escaping
- Unambiguous: Uses Bitcoin's Base58 alphabet (excludes 0, O, I, l)
- Fast: Optimized encoding/decoding with lookup tables
- Safe: Memory-safe by design (Rust guarantees)
- Cross-platform: Works on Linux, macOS, Windows, iOS, Android, WASM
Installation
Add to your Cargo.toml:
[]
= "1.0"
Usage
use b58uuid;
API
Functions
generate() -> String- Generate a new random UUID and return Base58 encodingencode_uuid(uuid_str: &str) -> Result<String, B58UUIDError>- Encode UUID string to Base58decode_to_uuid(b58_str: &str) -> Result<String, B58UUIDError>- Decode Base58 string to UUIDencode(data: &[u8; 16]) -> String- Encode 16-byte array to Base58decode(b58_str: &str) -> Result<[u8; 16], B58UUIDError>- Decode Base58 string to 16-byte array
Error Type
B58UUIDError enum with variants:
InvalidUUID(String)- Invalid UUID formatInvalidBase58(String)- Invalid Base58 stringInvalidLength { expected: usize, got: usize }- Invalid lengthOverflow- Arithmetic overflow during conversion
Features
- Minimal dependencies: Only uses
getrandomfor secure random number generation - Always 22 characters: Consistent, predictable output length
- Bitcoin Base58 alphabet: No confusing characters (0, O, I, l)
- Memory safe: Rust's compile-time guarantees prevent common bugs
- Full error handling: All operations return
Resulttypes - Cross-platform: Works on all major platforms including embedded systems
Dependencies
This library has only one dependency: getrandom
Why getrandom?
Rust's standard library intentionally does not provide cryptographically secure random number generation. The getrandom crate is the de facto standard solution in the Rust ecosystem for this purpose.
Benefits of using getrandom:
- ✅ Cryptographically secure on all platforms (Linux, macOS, Windows, iOS, Android, WASM)
- ✅ Minimal overhead: Small, well-audited crate with no transitive dependencies
- ✅ Widely trusted: Used by the
randcrate and thousands of other projects - ✅ Platform abstraction: Automatically uses the best random source for each platform:
- Linux:
getrandom()syscall - macOS/BSD:
/dev/urandom - Windows:
BCryptGenRandom() - WASM:
crypto.getRandomValues()
- Linux:
Without getrandom, we would need to manually implement platform-specific code for each operating system, which would be error-prone and harder to maintain.
Testing
License
MIT License - see LICENSE file for details.