Skip to content

Conversation

@dishmaker
Copy link
Contributor

@dishmaker dishmaker commented Oct 21, 2025

use der::{Encode, EncodeValue, ErrorKind, FixedTag, Length, Tag, Writer};

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

impl EncodeValue for MyByteMonth {

    fn value_len(&self) -> der::Result<Length> {
        Ok(Length::new(1))
    }

    fn encode_value(&self, writer: &mut impl Writer) -> der::Result<()> {
        writer.write_byte(self.0)?;
        Ok(())
    }
}

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

let month = MyByteMonth(9);
let mut buf = [0u8; 16];
let month_der = month.encode_to_slice(&mut buf).expect("month to encode");

assert_eq!(month_der, b"\x04\x01\x09");

Contains Note from rusticata/asn1-rs#106 in decode_value

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.

1 participant