[−][src]Trait subtle_encoding::encoding::Encoding
All encoding types in this crate implement this trait
Required methods
fn encode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
Encode the given slice into the destination buffer.
Returns the size of the encoded output, or Error
if the destination
buffer was too small to hold the encoded output.
fn encoded_len(&self, bytes: &[u8]) -> usize
Calculate the length of the given data after encoding.
fn decode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
Decode hexadecimal (upper or lower case) with branchless / secret-independent logic
fn decoded_len(&self, encoded_bytes: &[u8]) -> Result<usize, Error>
Calculate the length of the given data after decoding.
Provided methods
fn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8>
Encode the given buffer, returning a Vec<u8>
fn encode_to_string<B: AsRef<[u8]>>(&self, bytes: B) -> Result<String, Error>
Encode the given slice to a String
with this Encoding
.
Returns an Error
in the event this encoding does not produce a
well-formed UTF-8 string.
fn encode_to_writer<B, W>(
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
Encode the given slice with this Encoding
, writing the result to the
supplied io::Write
type, returning the number of bytes written or a Error
.
fn encode_to_file<B, P>(&self, bytes: B, path: P) -> Result<File, Error> where
B: AsRef<[u8]>,
P: AsRef<Path>,
B: AsRef<[u8]>,
P: AsRef<Path>,
Encode self
and write it to a file at the given path, returning the
resulting File
or a Error
.
If the file does not exist, it will be created with a mode of
FILE_MODE
(i.e. 600
). If the file does exist, it will be erased
and replaced.
fn decode<B: AsRef<[u8]>>(&self, encoded_bytes: B) -> Result<Vec<u8>, Error>
Decode the given buffer, returning a Vec<u8>
fn decode_from_str<S: AsRef<str>>(&self, encoded: S) -> Result<Vec<u8>, Error>
Decode the given string-alike type with this Encoding
, returning the
decoded value or a Error
.
fn decode_from_reader<R: Read>(&self, reader: &mut R) -> Result<Vec<u8>, Error>
Decode the data read from the given io::Read
type with this
Encoding
, returning the decoded value or a Error
.
fn decode_from_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>, Error>
Read a file at the given path, decoding the data it contains using
the provided Encoding
, returning the decoded value or a Error
.
Implementors
impl Encoding for Base64
[src]
fn encode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
[src]
fn encoded_len(&self, bytes: &[u8]) -> usize
[src]
fn decode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
[src]
fn decoded_len(&self, bytes: &[u8]) -> Result<usize, Error>
[src]
fn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8>
[src]
fn encode_to_string<B: AsRef<[u8]>>(&self, bytes: B) -> Result<String, Error>
[src]
fn encode_to_writer<B, W>(
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
[src]
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
fn encode_to_file<B, P>(&self, bytes: B, path: P) -> Result<File, Error> where
B: AsRef<[u8]>,
P: AsRef<Path>,
[src]
B: AsRef<[u8]>,
P: AsRef<Path>,
fn decode<B: AsRef<[u8]>>(&self, encoded_bytes: B) -> Result<Vec<u8>, Error>
[src]
fn decode_from_str<S: AsRef<str>>(&self, encoded: S) -> Result<Vec<u8>, Error>
[src]
fn decode_from_reader<R: Read>(&self, reader: &mut R) -> Result<Vec<u8>, Error>
[src]
fn decode_from_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>, Error>
[src]
impl Encoding for Hex
[src]
fn encode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
[src]
fn encoded_len(&self, bytes: &[u8]) -> usize
[src]
fn decode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
[src]
fn decoded_len(&self, bytes: &[u8]) -> Result<usize, Error>
[src]
fn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8>
[src]
fn encode_to_string<B: AsRef<[u8]>>(&self, bytes: B) -> Result<String, Error>
[src]
fn encode_to_writer<B, W>(
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
[src]
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
fn encode_to_file<B, P>(&self, bytes: B, path: P) -> Result<File, Error> where
B: AsRef<[u8]>,
P: AsRef<Path>,
[src]
B: AsRef<[u8]>,
P: AsRef<Path>,
fn decode<B: AsRef<[u8]>>(&self, encoded_bytes: B) -> Result<Vec<u8>, Error>
[src]
fn decode_from_str<S: AsRef<str>>(&self, encoded: S) -> Result<Vec<u8>, Error>
[src]
fn decode_from_reader<R: Read>(&self, reader: &mut R) -> Result<Vec<u8>, Error>
[src]
fn decode_from_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>, Error>
[src]
impl Encoding for Identity
[src]
fn encode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
[src]
fn encoded_len(&self, bytes: &[u8]) -> usize
[src]
fn decode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
[src]
fn decoded_len(&self, bytes: &[u8]) -> Result<usize, Error>
[src]
fn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8>
[src]
fn encode_to_string<B: AsRef<[u8]>>(&self, bytes: B) -> Result<String, Error>
[src]
fn encode_to_writer<B, W>(
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
[src]
&self,
bytes: B,
writer: &mut W
) -> Result<usize, Error> where
B: AsRef<[u8]>,
W: Write,
fn encode_to_file<B, P>(&self, bytes: B, path: P) -> Result<File, Error> where
B: AsRef<[u8]>,
P: AsRef<Path>,
[src]
B: AsRef<[u8]>,
P: AsRef<Path>,