Skip to main content
This is unreleased documentation for the main (development) branch of crypto-glue.

DecodeDer

Trait DecodeDer 

Source
pub trait DecodeDer<'a>: Sized + 'a {
    type Error: Error + From<Error> + 'static;

    // Required method
    fn decode<R>(decoder: &mut R) -> Result<Self, Self::Error>
       where R: Reader<'a>;

    // Provided methods
    fn from_der(bytes: &'a [u8]) -> Result<Self, Self::Error> { ... }
    fn from_der_partial(
        bytes: &'a [u8],
    ) -> Result<(Self, &'a [u8]), Self::Error> { ... }
}
Expand description

Decode trait parses a complete TLV (Tag-Length-Value) structure.

This trait provides the core abstraction upon which all decoding operations are based.

When decoding fails, a Decode::Error type is thrown. Most ASN.1 DER objects return a builtin der Error type as Decode::Error, which can be made from [ErrorKind].

§Example

use der::{Any, Decode, Reader};

/// Wrapper around Any, with custom foreign trait support.
///
/// For example: serde Serialize/Deserialize
pub struct AnySerde(pub Any);

impl<'a> Decode<'a> for AnySerde {
    type Error = der::Error;

    fn decode<R: Reader<'a>>(reader: &mut R) -> der::Result<Self> {
        // calls impl Decode for Any
        Ok(Self(Any::decode(reader)?))
    }
}

Required Associated Types§

Source

type Error: Error + From<Error> + 'static

Type returned in the event of a decoding error.

Required Methods§

Source

fn decode<R>(decoder: &mut R) -> Result<Self, Self::Error>
where R: Reader<'a>,

Attempt to decode this TLV message using the provided decoder.

§Errors

Returns Self::Error in the event a decoding error occurred.

Provided Methods§

Source

fn from_der(bytes: &'a [u8]) -> Result<Self, Self::Error>

Parse Self from the provided DER-encoded byte slice.

§Errors

Returns Self::Error in the event a decoding error occurred.

Source

fn from_der_partial(bytes: &'a [u8]) -> Result<(Self, &'a [u8]), Self::Error>

Parse Self from the provided DER-encoded byte slice.

Returns remaining byte slice, without checking for incomplete message.

§Errors

Returns Self::Error in the event a decoding error occurred.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'__der_lifetime, P> Decode<'__der_lifetime> for TrustAnchorChoice<P>
where P: Profile,

Source§

type Error = Error

Source§

fn decode<R>(reader: &mut R) -> Result<TrustAnchorChoice<P>, Error>
where R: Reader<'__der_lifetime>,

Source§

impl<'__der_lifetime> Decode<'__der_lifetime> for DirectoryString

Source§

type Error = Error

Source§

fn decode<R>(reader: &mut R) -> Result<DirectoryString, Error>
where R: Reader<'__der_lifetime>,

Source§

impl<'__der_lifetime> Decode<'__der_lifetime> for DisplayText

Source§

type Error = Error

Source§

fn decode<R>(reader: &mut R) -> Result<DisplayText, Error>
where R: Reader<'__der_lifetime>,

Source§

impl<'a, C> Decode<'a> for Signature<C>

Source§

type Error = Error

Source§

fn decode<R>(reader: &mut R) -> Result<Signature<C>, Error>
where R: Reader<'a>,

Source§

impl<'a, T> Decode<'a> for Option<T>
where T: Choice<'a>,

Source§

type Error = <T as Decode<'a>>::Error

Source§

fn decode<R>( reader: &mut R, ) -> Result<Option<T>, <Option<T> as Decode<'a>>::Error>
where R: Reader<'a>,

Source§

impl<'a, T> Decode<'a> for PhantomData<T>
where T: 'a + ?Sized,

Dummy implementation for PhantomData which allows deriving implementations on structs with phantom fields.

Source§

type Error = Error

Source§

fn decode<R>(_reader: &mut R) -> Result<PhantomData<T>, Error>
where R: Reader<'a>,

Source§

impl<'a> Decode<'a> for EncryptionScheme

Source§

impl<'a> Decode<'a> for Version

Source§

type Error = Error

Source§

fn decode<R>(reader: &mut R) -> Result<Version, Error>
where R: Reader<'a>,

Source§

impl<'a> Decode<'a> for Version

Source§

type Error = Error

Source§

fn decode<R>(reader: &mut R) -> Result<Version, Error>
where R: Reader<'a>,

Implementors§

Source§

impl<'__der_lifetime> Decode<'__der_lifetime> for DistributionPointName

Source§

impl<'__der_lifetime> Decode<'__der_lifetime> for GeneralName

Source§

impl<'__der_lifetime> Decode<'__der_lifetime> for Time

Source§

impl<'a, T> Decode<'a> for Application<T>
where T: Decode<'a>,

Source§

type Error = <T as Decode<'a>>::Error

Source§

impl<'a, T> Decode<'a> for ContextSpecific<T>
where T: Decode<'a>,

Source§

type Error = <T as Decode<'a>>::Error

Source§

impl<'a, T> Decode<'a> for Private<T>
where T: Decode<'a>,

Source§

type Error = <T as Decode<'a>>::Error

Source§

impl<'a, T> Decode<'a> for T
where T: DecodeValue<'a> + FixedTag + 'a,

Source§

type Error = <T as DecodeValue<'a>>::Error

Source§

impl<'a> Decode<'a> for Any

Source§

impl<'a> Decode<'a> for AnyRef<'a>

Source§

impl<'a> Decode<'a> for Document

Source§

impl<'a> Decode<'a> for Header

Source§

impl<'a> Decode<'a> for Length

Source§

impl<'a> Decode<'a> for Tag