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§
Required Methods§
Provided Methods§
Sourcefn from_der(bytes: &'a [u8]) -> Result<Self, Self::Error>
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.
Sourcefn from_der_partial(bytes: &'a [u8]) -> Result<(Self, &'a [u8]), Self::Error>
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,
impl<'__der_lifetime, P> Decode<'__der_lifetime> for TrustAnchorChoice<P>where
P: Profile,
Source§impl<'__der_lifetime> Decode<'__der_lifetime> for DirectoryString
impl<'__der_lifetime> Decode<'__der_lifetime> for DirectoryString
Source§impl<'__der_lifetime> Decode<'__der_lifetime> for DisplayText
impl<'__der_lifetime> Decode<'__der_lifetime> for DisplayText
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.
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.