Skip to main content

DecodeValue

Trait DecodeValue 

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

    // Required method
    fn decode_value<R: Reader<'a>>(
        reader: &mut R,
        header: Header,
    ) -> Result<Self, Self::Error>;
}
Expand description

DecodeValue trait parses the value part of a Tag-Length-Value object, sans the Tag and Length.

As opposed to Decode, implementer is expected to read the inner content only, without the Header, which was decoded beforehand.

§Example

use der::{Decode, DecodeValue, ErrorKind, FixedTag, Header, Reader, Tag};

/// 1-byte month
struct MyByteMonth(u8);

impl<'a> DecodeValue<'a> for MyByteMonth {
    type Error = der::Error;

    fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> der::Result<Self> {
        let month = reader.read_byte()?;
         
        if (0..12).contains(&month) {
            Ok(Self(month))
        } else {
            Err(reader.error(ErrorKind::DateTime))
        }
    }
}

impl FixedTag for MyByteMonth {
    const TAG: Tag = Tag::OctetString;
}

let month = MyByteMonth::from_der(b"\x04\x01\x09").expect("month to decode");

assert_eq!(month.0, 9);

Required Associated Types§

Source

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

Type returned in the event of a decoding error.

Required Methods§

Source

fn decode_value<R: Reader<'a>>( reader: &mut R, header: Header, ) -> Result<Self, Self::Error>

Attempt to decode this value using the provided Reader.

§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, E> DecodeValue<'a> for Cow<'a, T>
where T: ToOwned + ?Sized, &'a T: DecodeValue<'a, Error = E>, T::Owned: for<'b> DecodeValue<'b, Error = E>, E: Error + From<Error> + 'static,

Available on crate feature alloc only.
Source§

type Error = E

Source§

fn decode_value<R: Reader<'a>>( reader: &mut R, header: Header, ) -> Result<Self, Self::Error>

Source§

impl<'a, T> DecodeValue<'a> for Box<T>
where T: DecodeValue<'a>,

Available on crate feature alloc only.
Source§

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

Source§

fn decode_value<R: Reader<'a>>( reader: &mut R, header: Header, ) -> Result<Self, Self::Error>

Source§

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

Available on crate feature alloc only.
Source§

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

Source§

fn decode_value<R: Reader<'a>>( reader: &mut R, _header: Header, ) -> Result<Self, Self::Error>

Source§

impl<'a> DecodeValue<'a> for ()

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for String

Available on crate feature alloc only.
Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for SystemTime

Available on crate feature std only.
Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for bool

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for i8

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for i16

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for i32

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for i64

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for i128

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for u8

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for u16

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for u32

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for u64

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Source§

impl<'a> DecodeValue<'a> for u128

Source§

type Error = Error

Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Implementors§

Source§

impl<'__der: 'a, 'a> DecodeValue<'__der> for Ia5StringRef<'a>

Source§

impl<'__der: 'a, 'a> DecodeValue<'__der> for PrintableStringRef<'a>

Source§

impl<'__der: 'a, 'a> DecodeValue<'__der> for TeletexStringRef<'a>

Source§

impl<'__der: 'a, 'a> DecodeValue<'__der> for Utf8StringRef<'a>

Source§

impl<'__der: 'a, 'a> DecodeValue<'__der> for VideotexStringRef<'a>

Source§

impl<'__der> DecodeValue<'__der> for Ia5String

Source§

impl<'__der> DecodeValue<'__der> for PrintableString

Source§

impl<'__der> DecodeValue<'__der> for TeletexString

Source§

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

Available on crate feature alloc only.
Source§

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

Source§

impl<'a> DecodeValue<'a> for &'a OctetStringRef

Source§

impl<'a> DecodeValue<'a> for &'a SequenceRef

Source§

impl<'a> DecodeValue<'a> for Any

Source§

impl<'a> DecodeValue<'a> for AnyRef<'a>

Source§

impl<'a> DecodeValue<'a> for BitString

Source§

impl<'a> DecodeValue<'a> for BitStringRef<'a>

Source§

impl<'a> DecodeValue<'a> for BmpString

Source§

impl<'a> DecodeValue<'a> for DateTime

Source§

impl<'a> DecodeValue<'a> for GeneralStringRef<'a>

Source§

impl<'a> DecodeValue<'a> for GeneralizedTime

Source§

impl<'a> DecodeValue<'a> for Int

Source§

impl<'a> DecodeValue<'a> for IntRef<'a>

Source§

impl<'a> DecodeValue<'a> for Null

Source§

impl<'a> DecodeValue<'a> for OctetString

Source§

impl<'a> DecodeValue<'a> for Uint

Source§

impl<'a> DecodeValue<'a> for UintRef<'a>

Source§

impl<'a> DecodeValue<'a> for UtcTime