[][src]Trait subtle_encoding::encoding::Encoding

pub trait Encoding: Send + Sync {
    fn encode_to_slice(
        &self,
        src: &[u8],
        dst: &mut [u8]
    ) -> Result<usize, Error>;
fn encoded_len(&self, bytes: &[u8]) -> usize;
fn decode_to_slice(
        &self,
        src: &[u8],
        dst: &mut [u8]
    ) -> Result<usize, Error>;
fn decoded_len(&self, encoded_bytes: &[u8]) -> Result<usize, Error>; fn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8> { ... }
fn encode_to_string<B: AsRef<[u8]>>(
        &self,
        bytes: B
    ) -> Result<String, Error> { ... }
fn encode_to_writer<B, W>(
        &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>
, { ... }
fn decode<B: AsRef<[u8]>>(&self, encoded_bytes: B) -> Result<Vec<u8>, Error> { ... }
fn decode_from_str<S: AsRef<str>>(
        &self,
        encoded: S
    ) -> Result<Vec<u8>, Error> { ... }
fn decode_from_reader<R: Read>(
        &self,
        reader: &mut R
    ) -> Result<Vec<u8>, Error> { ... }
fn decode_from_file<P: AsRef<Path>>(
        &self,
        path: P
    ) -> Result<Vec<u8>, Error> { ... } }

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.

Loading content...

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

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>, 

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.

Loading content...

Implementors

impl Encoding for Base64[src]

impl Encoding for Hex[src]

impl Encoding for Identity[src]

Loading content...