pub trait Decode<'a>: Sized + 'a {
type Error: Error + From<Error> + 'static;
// Required method
fn decode<R: Reader<'a>>(decoder: &mut R) -> Result<Self, Self::Error>;
// 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<'a, T> Decode<'a> for PhantomData<T>where
T: ?Sized + 'a,
Dummy implementation for PhantomData which allows deriving
implementations on structs with phantom fields.
impl<'a, T> Decode<'a> for PhantomData<T>where
T: ?Sized + 'a,
Dummy implementation for PhantomData which allows deriving
implementations on structs with phantom fields.