Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> { /* private fields */ }
Expand description

A cursor over a DER input that yields borrowed value contents.

The reader is checked: every method validates the tag, the length, and the available input before returning, so it never panics on malformed data.

Implementations§

Source§

impl<'a> Reader<'a>

Source

pub const fn new(data: &'a [u8]) -> Self

Creates a reader over data.

Source

pub fn is_empty(&self) -> bool

Returns true when all input has been consumed.

Source

pub fn remaining(&self) -> usize

Returns the number of unread bytes.

Source

pub fn peek_tag(&self) -> Result<u8, DerError>

Returns the tag of the next value without consuming it.

Returns DerError::Truncated when no value remains.

Source

pub fn read_tlv(&mut self) -> Result<(u8, &'a [u8]), DerError>

Reads one tag-length-value, returning its tag and content.

Returns DerError when the value is truncated, uses an indefinite or non-minimal length, or has a high-tag-number form.

Source

pub fn read_expected(&mut self, tag: u8) -> Result<&'a [u8], DerError>

Reads one value and requires it to have tag, returning its content.

Source

pub fn read_sequence(&mut self) -> Result<Reader<'a>, DerError>

Reads a SEQUENCE and returns a reader over its content.

Source

pub fn read_integer(&mut self) -> Result<&'a [u8], DerError>

Reads an INTEGER, returning its canonical content bytes.

The content may start with a single 0x00 when required to keep the sign bit clear. Empty or non-minimal encodings are rejected.

Source

pub fn read_octet_string(&mut self) -> Result<&'a [u8], DerError>

Reads an OCTET STRING, returning its content bytes.

Source

pub fn read_bit_string(&mut self) -> Result<&'a [u8], DerError>

Reads a BIT STRING, returning its bytes with the unused-bits count byte removed.

Returns DerError::Unsupported when the value declares unused bits (only byte-aligned bit strings are supported).

Source

pub fn read_oid(&mut self) -> Result<&'a [u8], DerError>

Reads an OBJECT IDENTIFIER, returning its content bytes (without the leading tag/length). Compare against known OID byte strings.

Source

pub fn read_explicit(&mut self, tag: u8) -> Result<Reader<'a>, DerError>

Reads a context-specific [tag] explicit wrapper and returns a reader over the wrapped value. tag is the full identifier byte, e.g. 0xa0.

Source

pub fn finish(self) -> Result<(), DerError>

Asserts that all input was consumed.

Returns DerError::TrailingData otherwise.

Trait Implementations§

Source§

impl<'a> Clone for Reader<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Reader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.