diff --git a/der/src/decode.rs b/der/src/decode.rs index 58b6b4ba3..700c3145a 100644 --- a/der/src/decode.rs +++ b/der/src/decode.rs @@ -158,6 +158,36 @@ impl + PemLabel> DecodePem for T { /// /// 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>(reader: &mut R, header: Header) -> der::Result { +/// 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); +/// ``` pub trait DecodeValue<'a>: Sized { /// Type returned in the event of a decoding error. type Error: From + 'static; diff --git a/der/src/tag.rs b/der/src/tag.rs index b0c316b9b..34644892e 100644 --- a/der/src/tag.rs +++ b/der/src/tag.rs @@ -86,7 +86,7 @@ impl Tagged for T { /// if let Some(year) = year { /// Ok(Self(year)) /// } else { -/// Err(ErrorKind::DateTime.into()) +/// Err(reader.error(ErrorKind::DateTime)) /// } /// } /// }