Skip to main content

DerReader

Struct DerReader 

Source
pub struct DerReader<'a> { /* private fields */ }
Available on crate feature rustcrypto only.
Expand description

A cursor over a sequence of DER elements.

Implementations§

Source§

impl<'a> DerReader<'a>

Source

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

Starts reading at the beginning of buf.

Source

pub const fn is_empty(&self) -> bool

Whether every element has been consumed.

Source

pub fn remaining(&self) -> &'a [u8] ⓘ

The octets not yet consumed.

Source

pub fn peek_tag(&self) -> Option<u8>

Returns the next element’s identifier octet without consuming it.

Source

pub fn next_element(&mut self) -> Result<Element<'a>>

Reads the next element, whatever it is.

Source

pub fn expect(&mut self, tag: u8) -> Result<Element<'a>>

Reads the next element and requires it to have this identifier octet.

Source

pub fn expect_sequence(&mut self) -> Result<Self>

Reads a SEQUENCE and returns a reader over its members.

Source

pub fn expect_set(&mut self) -> Result<Self>

Reads a SET and returns a reader over its members.

Source

pub fn expect_oid(&mut self, expected: &[u8]) -> Result<()>

Reads an OBJECT IDENTIFIER and requires it to be expected.

Source

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

Reads a non-negative INTEGER and returns its magnitude with the sign octet removed.

DER’s INTEGER is two’s-complement and minimally encoded, which means a positive value whose top bit is set carries a leading 0x00 so that it does not read as negative. That octet is part of the encoding, not of the number, so a 256-bit scalar arrives as 33 octets about half the time.

Both minimality rules are enforced: a leading 0x00 is legal only when the next octet has its top bit set, and a leading 0x80-or-above is a negative number.

Source

pub fn expect_uint(&mut self) -> Result<u64>

Reads a non-negative INTEGER that must fit in a u64.

Source

pub fn take_if(&mut self, tag: u8) -> Result<Option<Element<'a>>>

Reads the next element only if it has this identifier octet.

This is how an OPTIONAL or a DEFAULT field is read: a look before the leap, since what follows an absent field is the next field and consuming it would desynchronise the parse.

Source

pub fn finish(&self) -> Result<()>

Requires every element to have been consumed.

Trailing octets after a complete structure are not a harmless suffix: in a signed document they are data the signature does not cover.

Trait Implementations§

Source§

impl<'a> Clone for DerReader<'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 DerReader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for DerReader<'a>

§

impl<'a> Freeze for DerReader<'a>

§

impl<'a> Move for DerReader<'a>

§

impl<'a> RefUnwindSafe for DerReader<'a>

§

impl<'a> Send for DerReader<'a>

§

impl<'a> Sync for DerReader<'a>

§

impl<'a> Unpin for DerReader<'a>

§

impl<'a> UnsafeUnpin for DerReader<'a>

§

impl<'a> UnwindSafe for DerReader<'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> Same for T

Source§

type Output = T

Should always be Self
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.