Trait ssh_encoding::base64::Encoding
source · pub trait Encoding: Alphabet {
// Required methods
fn decode(src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], Error>;
fn decode_in_place(buf: &mut [u8]) -> Result<&[u8], InvalidEncodingError>;
fn decode_vec(input: &str) -> Result<Vec<u8>, Error>;
fn encode<'a>(
src: &[u8],
dst: &'a mut [u8],
) -> Result<&'a str, InvalidLengthError>;
fn encode_string(input: &[u8]) -> String;
fn encoded_len(bytes: &[u8]) -> usize;
}
Available on crate feature
base64
only.Expand description
Base64 encoding trait.
This trait must be imported to make use of any Base64 alphabet defined in this crate.
The following encoding types impl this trait:
- [
Base64
]: standard Base64 encoding with=
padding. - [
Base64Bcrypt
]: bcrypt Base64 encoding. - [
Base64Crypt
]:crypt(3)
Base64 encoding. - [
Base64Unpadded
]: standard Base64 encoding without padding. - [
Base64Url
]: URL-safe Base64 encoding with=
padding. - [
Base64UrlUnpadded
]: URL-safe Base64 encoding without padding.
Required Methods§
sourcefn decode(src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], Error>
fn decode(src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], Error>
Decode a Base64 string into the provided destination buffer.
sourcefn decode_in_place(buf: &mut [u8]) -> Result<&[u8], InvalidEncodingError>
fn decode_in_place(buf: &mut [u8]) -> Result<&[u8], InvalidEncodingError>
Decode a Base64 string in-place.
NOTE: this method does not (yet) validate that padding is well-formed, if the given Base64 encoding is padded.
sourcefn decode_vec(input: &str) -> Result<Vec<u8>, Error>
Available on crate feature alloc
only.
fn decode_vec(input: &str) -> Result<Vec<u8>, Error>
alloc
only.Decode a Base64 string into a byte vector.
sourcefn encode<'a>(
src: &[u8],
dst: &'a mut [u8],
) -> Result<&'a str, InvalidLengthError>
fn encode<'a>( src: &[u8], dst: &'a mut [u8], ) -> Result<&'a str, InvalidLengthError>
Encode the input byte slice as Base64.
Writes the result into the provided destination slice, returning an ASCII-encoded Base64 string value.
sourcefn encode_string(input: &[u8]) -> String
Available on crate feature alloc
only.
fn encode_string(input: &[u8]) -> String
alloc
only.sourcefn encoded_len(bytes: &[u8]) -> usize
fn encoded_len(bytes: &[u8]) -> usize
Get the length of Base64 produced by encoding the given bytes.
WARNING: this function will return 0
for lengths greater than usize::MAX/4
!
Object Safety§
This trait is not object safe.