pub struct Base64UrlSafeNoPadding;
Expand description
URL-safe Base64 encoder and decoder without padding.
This implementation follows the URL-safe Base64 encoding variant as defined in RFC 4648, but omits padding characters (‘=’). This is particularly useful for URLs, where the padding character may need to be percent-encoded.
§Examples
use ct_codecs::{Base64UrlSafeNoPadding, Encoder, Decoder};
fn example() -> Result<(), ct_codecs::Error> {
let data = b"Hello, world!";
let encoded = Base64UrlSafeNoPadding::encode_to_string(data)?;
assert_eq!(encoded, "SGVsbG8sIHdvcmxkIQ");
// With binary data containing characters that would be escaped in URLs
let binary_data = &[251, 239, 190, 222];
let encoded = Base64UrlSafeNoPadding::encode_to_string(binary_data)?;
assert_eq!(encoded, "----3g");
Ok(())
}
Trait Implementations§
Source§impl Decoder for Base64UrlSafeNoPadding
impl Decoder for Base64UrlSafeNoPadding
Source§impl Encoder for Base64UrlSafeNoPadding
impl Encoder for Base64UrlSafeNoPadding
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 Base64UrlSafeNoPadding
impl RefUnwindSafe for Base64UrlSafeNoPadding
impl Send for Base64UrlSafeNoPadding
impl Sync for Base64UrlSafeNoPadding
impl Unpin for Base64UrlSafeNoPadding
impl UnwindSafe for Base64UrlSafeNoPadding
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