Skip to content

Conversation

dishmaker
Copy link
Contributor

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);

@baloo baloo merged commit 6f3f780 into RustCrypto:master Oct 16, 2025
107 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants