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§
Sourceconst CAN_READ_SLICE: bool
const CAN_READ_SLICE: bool
Does this reader support the read_slice method? (i.e. can it borrow from his input?)
Required Methods§
Sourcefn encoding_rules(&self) -> EncodingRules
fn encoding_rules(&self) -> EncodingRules
Get the EncodingRules which should be applied when decoding the input.
Sourcefn read_nested<T, F, E>(&mut self, len: Length, f: F) -> Result<T, E>
fn read_nested<T, F, E>(&mut self, len: Length, f: F) -> Result<T, E>
Sourcefn read_slice(&mut self, len: Length) -> Result<&'r [u8], Error>
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 dataErr(ErrorKind::Reader)if the reader can’t borrow from the input
Provided Methods§
Sourcefn context_specific<T>(
&mut self,
tag_number: TagNumber,
tag_mode: TagMode,
) -> Result<Option<T>, T::Error>where
T: DecodeValue<'r> + FixedTag + 'r,
fn context_specific<T>(
&mut self,
tag_number: TagNumber,
tag_mode: TagMode,
) -> Result<Option<T>, T::Error>where
T: DecodeValue<'r> + FixedTag + 'r,
Sourcefn drain(&mut self, amount: Length) -> Result<(), Error>
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.
Sourcefn error(&mut self, kind: ErrorKind) -> Error
fn error(&mut self, kind: ErrorKind) -> Error
Return an error with the given ErrorKind, annotating it with
context about where the error occurred.
Sourcefn finish(self) -> Result<(), Error>
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.
Sourcefn is_finished(&self) -> bool
fn is_finished(&self) -> bool
Have we read all input data?
Sourcefn offset(&self) -> Length
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)
Sourcefn peek_into(&self, buf: &mut [u8]) -> Result<(), Error>
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.
Sourcefn peek_header(&self) -> Result<Header, Error>
👎Deprecated since 0.8.0: use Header::peek instead
fn peek_header(&self) -> Result<Header, Error>
Header::peek insteadPeek 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.
Sourcefn read_into<'o>(&mut self, buf: &'o mut [u8]) -> Result<&'o [u8], Error>
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::Incompleteif there is not enough data
Sourcefn read_vec(&mut self, len: Length) -> Result<Vec<u8>, Error>
Available on crate feature alloc only.
fn read_vec(&mut self, len: Length) -> Result<Vec<u8>, Error>
alloc only.Sourcefn remaining_len(&self) -> Length
fn remaining_len(&self) -> Length
Get the number of bytes still remaining in the buffer.
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.