This is a simple Base64 implementation in rust.
It is meant to be copied into your rust project.
It cannot be installed from crates.io.
This is based on RFC 4648
encode()
includes padding.
decode()
supports padding and no padding.
- Copy
base64.rs
into your project - Add
pub mod base64;
into yourlib.rs
- Use
base64::encode()
andbase64::decode()
- See docs
use vendor_base64::base64; // Replace vendor_base64 with your project name
// Encode
let bytes = "rust".as_bytes();
let encoded = base64::encode(bytes);
assert_eq!(encoded, "cnVzdA==");
// Decode
let decoded = base64::decode(&encoded).unwrap();
assert_eq!(decoded, bytes);
// Decode without padding
let decoded = base64::decode("cnVzdA").unwrap();
assert_eq!(decoded, bytes);
You don't want the API to suddenly break.
You just want the standard Base64 encode/decode.
You want to remove a dependency that is downloaded from crates.io.
There is no:
- URL safe encode
- Encode without padding
- Custom alphabet support
This implementation seems to be about 2-4x slower than the base64 crate. ~50ms vs ~16ms in some simple tests.
base64 crate has more features.
Run $ cargo test
See docs
Run $ cargo doc --open
MIT-0