der

Trait Reader

Source
pub trait Reader<'r>: Sized {
Show 19 methods // Required methods fn input_len(&self) -> Length; fn peek_byte(&self) -> Option<u8>; fn peek_header(&self) -> Result<Header>; fn position(&self) -> Length; fn read_slice(&mut self, len: Length) -> Result<&'r [u8]>; // Provided methods fn context_specific<T>( &mut self, tag_number: TagNumber, tag_mode: TagMode, ) -> Result<Option<T>> where T: DecodeValue<'r> + FixedTag { ... } fn decode<T: Decode<'r>>(&mut self) -> Result<T> { ... } fn error(&mut self, kind: ErrorKind) -> Error { ... } fn finish<T>(self, value: T) -> Result<T> { ... } fn is_finished(&self) -> bool { ... } fn offset(&self) -> Length { ... } fn peek_tag(&self) -> Result<Tag> { ... } fn read_byte(&mut self) -> Result<u8> { ... } fn read_into<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o [u8]> { ... } fn read_nested<'n, T, F>(&'n mut self, len: Length, f: F) -> Result<T> where F: FnOnce(&mut NestedReader<'n, Self>) -> Result<T> { ... } fn read_vec(&mut self, len: Length) -> Result<Vec<u8>> { ... } fn remaining_len(&self) -> Length { ... } fn sequence<'n, F, T>(&'n mut self, f: F) -> Result<T> where F: FnOnce(&mut NestedReader<'n, Self>) -> Result<T> { ... } fn tlv_bytes(&mut self) -> Result<&'r [u8]> { ... }
}
Expand description

Reader trait which reads DER-encoded input.

Required Methods§

Source

fn input_len(&self) -> Length

Get the length of the input.

Source

fn peek_byte(&self) -> Option<u8>

Peek at the next byte of input without modifying the cursor.

Source

fn peek_header(&self) -> Result<Header>

Peek forward in the input data, attempting to decode a Header from the data at the current position in the decoder.

Does not modify the decoder’s state.

Source

fn position(&self) -> Length

Get the position within the buffer.

Source

fn read_slice(&mut self, len: Length) -> Result<&'r [u8]>

Attempt to read data borrowed directly from the input as a slice, updating the internal cursor position.

§Returns
  • Ok(slice) on success
  • Err(ErrorKind::Incomplete) if there is not enough data
  • Err(ErrorKind::Reader) if the reader can’t borrow from the input

Provided Methods§

Source

fn context_specific<T>( &mut self, tag_number: TagNumber, tag_mode: TagMode, ) -> Result<Option<T>>
where T: DecodeValue<'r> + FixedTag,

Attempt to decode an ASN.1 CONTEXT-SPECIFIC field with the provided TagNumber.

Source

fn decode<T: Decode<'r>>(&mut self) -> Result<T>

Decode a value which impls the Decode trait.

Source

fn error(&mut self, kind: ErrorKind) -> Error

Return an error with the given ErrorKind, annotating it with context about where the error occurred.

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

Source

fn is_finished(&self) -> bool

Have we read all of the input data?

Source

fn offset(&self) -> Length

Offset within the original input stream.

This is used for error reporting, and doesn’t need to be overridden by any reader implementations (except for the built-in NestedReader, which consumes nested input messages)

Source

fn peek_tag(&self) -> Result<Tag>

Peek at the next byte in the decoder and attempt to decode it as a Tag value.

Does not modify the decoder’s state.

Source

fn read_byte(&mut self) -> Result<u8>

Read a single byte.

Source

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

Attempt to read input data, writing it into the provided buffer, and returning a slice on success.

§Returns
  • Ok(slice) if there is sufficient data
  • Err(ErrorKind::Incomplete) if there is not enough data
Source

fn read_nested<'n, T, F>(&'n mut self, len: Length, f: F) -> Result<T>
where F: FnOnce(&mut NestedReader<'n, Self>) -> Result<T>,

Read nested data of the given length.

Source

fn read_vec(&mut self, len: Length) -> Result<Vec<u8>>

Read a byte vector of the given length.

Source

fn remaining_len(&self) -> Length

Get the number of bytes still remaining in the buffer.

Source

fn sequence<'n, F, T>(&'n mut self, f: F) -> Result<T>
where F: FnOnce(&mut NestedReader<'n, Self>) -> Result<T>,

Read an ASN.1 SEQUENCE, creating a nested Reader for the body and calling the provided closure with it.

Source

fn tlv_bytes(&mut self) -> Result<&'r [u8]>

Obtain a slice of bytes contain a complete TLV production suitable for parsing later.

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.

Implementors§

Source§

impl<'a> Reader<'a> for SliceReader<'a>

Source§

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