Struct der::Decoder

source ·
pub struct Decoder<'a> { /* private fields */ }
Expand description

DER decoder.

Implementations§

source§

impl<'a> Decoder<'a>

source

pub fn new(bytes: &'a [u8]) -> Result<Self>

Create a new decoder for the given byte slice.

source

pub fn decode<T: Decodable<'a>>(&mut self) -> Result<T>

Decode a value which impls the Decodable trait.

source

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

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

source

pub fn value_error(&mut self, tag: Tag) -> Error

Return an error for an invalid value with the given tag.

source

pub fn is_failed(&self) -> bool

Did the decoding operation fail due to an error?

source

pub fn position(&self) -> Length

Get the position within the buffer.

source

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

Peek at the next byte in the decoder without modifying the cursor.

source

pub 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

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

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

Does not modify the decoder’s state.

source

pub 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

pub fn is_finished(&self) -> bool

Have we decoded all of the bytes in this Decoder?

Returns false if we’re not finished decoding or if a fatal error has occurred.

source

pub fn any(&mut self) -> Result<Any<'a>>

Attempt to decode an ASN.1 ANY value.

source

pub fn any_optional(&mut self) -> Result<Option<Any<'a>>>

Attempt to decode an OPTIONAL ASN.1 ANY value.

source

pub fn int8(&mut self) -> Result<i8>

Attempt to decode ASN.1 INTEGER as i8

source

pub fn int16(&mut self) -> Result<i16>

Attempt to decode ASN.1 INTEGER as i16

source

pub fn uint8(&mut self) -> Result<u8>

Attempt to decode unsigned ASN.1 INTEGER as u8

source

pub fn uint16(&mut self) -> Result<u16>

Attempt to decode unsigned ASN.1 INTEGER as u16

source

pub fn bit_string(&mut self) -> Result<BitString<'a>>

Attempt to decode an ASN.1 BIT STRING.

source

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

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

source

pub fn generalized_time(&mut self) -> Result<GeneralizedTime>

Attempt to decode an ASN.1 GeneralizedTime.

source

pub fn ia5_string(&mut self) -> Result<Ia5String<'a>>

Attempt to decode an ASN.1 IA5String.

source

pub fn null(&mut self) -> Result<Null>

Attempt to decode an ASN.1 NULL value.

source

pub fn octet_string(&mut self) -> Result<OctetString<'a>>

Attempt to decode an ASN.1 OCTET STRING.

source

pub fn oid(&mut self) -> Result<ObjectIdentifier>

Attempt to decode an ASN.1 OBJECT IDENTIFIER.

source

pub fn optional<T: Choice<'a>>(&mut self) -> Result<Option<T>>

Attempt to decode an ASN.1 OPTIONAL value.

source

pub fn printable_string(&mut self) -> Result<PrintableString<'a>>

Attempt to decode an ASN.1 PrintableString.

source

pub fn utc_time(&mut self) -> Result<UtcTime>

Attempt to decode an ASN.1 UTCTime.

source

pub fn utf8_string(&mut self) -> Result<Utf8String<'a>>

Attempt to decode an ASN.1 UTF8String.

source

pub fn sequence<F, T>(&mut self, f: F) -> Result<T>
where F: FnOnce(&mut Decoder<'a>) -> Result<T>,

Attempt to decode an ASN.1 SEQUENCE, creating a new nested Decoder and calling the provided argument with it.

Trait Implementations§

source§

impl<'a> Clone for Decoder<'a>

source§

fn clone(&self) -> Decoder<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Decoder<'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 Decoder<'a>

§

impl<'a> RefUnwindSafe for Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnwindSafe for Decoder<'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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.