pub struct Base64;
Expand description
Standard Base64 encoder and decoder with padding.
This implementation follows the standard Base64 encoding as defined in RFC 4648, and includes padding characters (‘=’) when needed.
§Standard Base64 Alphabet
The standard Base64 alphabet uses characters:
- ‘A’ to ‘Z’ (26 characters)
- ‘a’ to ‘z’ (26 characters)
- ‘0’ to ‘9’ (10 characters)
- ‘+’ and ‘/’ (2 characters)
- ‘=’ (padding character)
§Examples
use ct_codecs::{Base64, Encoder, Decoder};
fn example() -> Result<(), ct_codecs::Error> {
let data = b"Hello, world!";
let encoded = Base64::encode_to_string(data)?;
assert_eq!(encoded, "SGVsbG8sIHdvcmxkIQ==");
let decoded = Base64::decode_to_vec(&encoded, None)?;
assert_eq!(decoded, data);
Ok(())
}
Trait Implementations§
Source§impl Decoder for Base64
impl Decoder for Base64
Source§impl Encoder for Base64
impl Encoder for Base64
Source§fn encoded_len(bin_len: usize) -> Result<usize, Error>
fn encoded_len(bin_len: usize) -> Result<usize, Error>
Calculates the length of the encoded output for a given binary input length. Read more
Source§fn encode<IN: AsRef<[u8]>>(b64: &mut [u8], bin: IN) -> Result<&[u8], Error>
fn encode<IN: AsRef<[u8]>>(b64: &mut [u8], bin: IN) -> Result<&[u8], Error>
Encodes binary data into a text representation. Read more
Auto Trait Implementations§
impl Freeze for Base64
impl RefUnwindSafe for Base64
impl Send for Base64
impl Sync for Base64
impl Unpin for Base64
impl UnwindSafe for Base64
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more