pub trait Reader: Sized {
// Required methods
fn read<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>;
fn remaining_len(&self) -> usize;
fn read_prefixed<T, E, F>(&mut self, f: F) -> Result<T, E>
where E: From<Error>,
F: FnOnce(&mut Self) -> Result<T, E>;
// Provided methods
fn is_finished(&self) -> bool { ... }
fn read_byten<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error> { ... }
fn read_string<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o str, Error> { ... }
fn drain(&mut self, n_bytes: usize) -> Result<(), Error> { ... }
fn drain_prefixed(&mut self) -> Result<usize, Error> { ... }
fn ensure_finished(&self) -> Result<(), Error> { ... }
fn finish<T>(self, value: T) -> Result<T, Error> { ... }
}
Expand description
Reader trait which decodes the binary SSH protocol serialization from various inputs.
Required Methods§
Sourcefn read<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
fn read<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
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 readErr(Error::Length)
if the exact amount of data couldn’t be read
Sourcefn remaining_len(&self) -> usize
fn remaining_len(&self) -> usize
Get the length of the remaining data after Base64 decoding.
Provided Methods§
Sourcefn is_finished(&self) -> bool
fn is_finished(&self) -> bool
Is decoding finished?
Sourcefn read_byten<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
fn read_byten<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
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.
Sourcefn read_string<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o str, Error>
fn read_string<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o str, Error>
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.
Sourcefn drain(&mut self, n_bytes: usize) -> Result<(), Error>
fn drain(&mut self, n_bytes: usize) -> Result<(), Error>
Drain the given number of bytes from the reader, discarding them.
Sourcefn drain_prefixed(&mut self) -> Result<usize, Error>
fn drain_prefixed(&mut self) -> Result<usize, Error>
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).
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.