ssh_encoding

Trait Reader

Source
pub trait Reader: Sized {
    // Required methods
    fn read<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8]>;
    fn remaining_len(&self) -> usize;

    // Provided methods
    fn is_finished(&self) -> bool { ... }
    fn read_prefixed<'r, T, E, F>(&'r mut self, f: F) -> Result<T, E>
       where E: From<Error>,
             F: FnOnce(&mut NestedReader<'r, Self>) -> Result<T, E> { ... }
    fn read_byten<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8]> { ... }
    fn read_string<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o str> { ... }
    fn drain(&mut self, n_bytes: usize) -> Result<()> { ... }
    fn drain_prefixed(&mut self) -> Result<usize> { ... }
    fn finish<T>(self, value: T) -> Result<T> { ... }
}
Expand description

Reader trait which decodes the binary SSH protocol serialization from various inputs.

Required Methods§

Source

fn read<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8]>

Read as much data as is needed to exactly fill out.

This is the base decoding method on which the rest of the trait is implemented in terms of.

§Returns
  • Ok(bytes) if the expected amount of data was read
  • Err(Error::Length) if the exact amount of data couldn’t be read
Source

fn remaining_len(&self) -> usize

Get the length of the remaining data after Base64 decoding.

Provided Methods§

Source

fn is_finished(&self) -> bool

Is decoding finished?

Source

fn read_prefixed<'r, T, E, F>(&'r mut self, f: F) -> Result<T, E>
where E: From<Error>, F: FnOnce(&mut NestedReader<'r, Self>) -> Result<T, E>,

Decode length-prefixed data.

Decodes a uint32 which identifies the length of some encapsulated data, then calls the given reader function with the length of the remaining data.

Source

fn read_byten<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8]>

Decodes [u8] from byte[n] as described in RFC4251 § 5:

A byte represents an arbitrary 8-bit value (octet). Fixed length data is sometimes represented as an array of bytes, written byte[n], where n is the number of bytes in the array.

Storage for the byte array must be provided as mutable byte slice in order to accommodate no_std use cases.

The Decode impl on Vec<u8> can be used to allocate a buffer for the result.

Source

fn read_string<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o str>

Decode a string as described in RFC4251 § 5:

Arbitrary length binary string. Strings are allowed to contain arbitrary binary data, including null characters and 8-bit characters. They are stored as a uint32 containing its length (number of bytes that follow) and zero (= empty string) or more bytes that are the value of the string. Terminating null characters are not used.

Strings are also used to store text. In that case, US-ASCII is used for internal names, and ISO-10646 UTF-8 for text that might be displayed to the user. The terminating null character SHOULD NOT normally be stored in the string. For example: the US-ASCII string “testing” is represented as 00 00 00 07 t e s t i n g. The UTF-8 mapping does not alter the encoding of US-ASCII characters.

Storage for the string data must be provided as mutable byte slice in order to accommodate no_std use cases.

The Decode impl on String can be used to allocate a buffer for the result.

Source

fn drain(&mut self, n_bytes: usize) -> Result<()>

Drain the given number of bytes from the reader, discarding them.

Source

fn drain_prefixed(&mut self) -> Result<usize>

Decode a u32 length prefix, and then drain the length of the body.

Upon success, returns the number of bytes drained sans the length of the u32 length prefix (4-bytes).

Source

fn finish<T>(self, value: T) -> Result<T>

Finish decoding, returning the given value if there is no remaining data, or an error otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Reader for &[u8]

Source§

fn read<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8]>

Source§

fn remaining_len(&self) -> usize

Source§

impl Reader for Decoder<'_>

Available on crate feature pem only.
Source§

fn read<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8]>

Source§

fn remaining_len(&self) -> usize

Implementors§

Source§

impl Reader for Base64Reader<'_>

Available on crate feature base64 only.
Source§

impl<'r, R: Reader> Reader for NestedReader<'r, R>