Skip to main content

Reader

Trait Reader 

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

Reader trait which reads DER-encoded input.

Required Associated Constants§

Source

const CAN_READ_SLICE: bool

Does this reader support the read_slice method? (i.e. can it borrow from his input?)

Required Methods§

Source

fn encoding_rules(&self) -> EncodingRules

Get the EncodingRules which should be applied when decoding the input.

Source

fn input_len(&self) -> Length

Get the length of the input.

Source

fn position(&self) -> Length

Get the position within the buffer.

Source

fn read_nested<T, F, E>(&mut self, len: Length, f: F) -> Result<T, E>
where E: From<Error>, F: FnOnce(&mut Self) -> Result<T, E>,

Read nested data of the given length.

§Errors

If f returns an error.

Source

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

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

§Errors
  • 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>, T::Error>
where T: DecodeValue<'r> + FixedTag + 'r,

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

§Errors

If a decoding error occurred.

Source

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

Decode a value which impls the Decode trait.

§Errors

Returns T::Error if a decoding error occurred.

Source

fn drain(&mut self, amount: Length) -> Result<(), Error>

Drain the given amount of data from the reader, discarding it.

§Errors

If an error occurred reading the given amount of data.

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(self) -> Result<(), Error>

Finish decoding, returning Ok(()) if there is no remaining data, or an error otherwise.

§Errors

If there is trailing data remaining in the reader.

Source

fn is_finished(&self) -> bool

Have we read all 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_byte(&self) -> Option<u8>

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

Source

fn peek_into(&self, buf: &mut [u8]) -> Result<(), Error>

Peek at the decoded data without updating the internal state, writing into the provided output buffer. Attempts to fill the entire buffer.

§Errors

If there is not enough data.

Source

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

👎Deprecated since 0.8.0: use Header::peek instead

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.

§Errors

If Header::peek returns an error.

Source

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

👎Deprecated since 0.8.0: use Tag::peek instead

Peek at the next tag in the reader.

§Errors

If Tag::peek returns an error.

Source

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

Read a single byte.

§Errors

If the byte could not be read.

Source

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

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

§Errors
  • ErrorKind::Incomplete if there is not enough data
Source

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

Available on crate feature alloc only.

Read a byte vector of the given length.

§Errors

If a read error occurred.

Source

fn remaining_len(&self) -> Length

Get the number of bytes still remaining in the buffer.

Source

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

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

§Errors

If f returns an error, or if a decoding error occurred.

Source

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

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

§Errors

If a decoding error occurred, or a length calculation overflowed.

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> Reader<'static> for PemReader<'i>

Available on crate feature pem only.