Skip to content

Conversation

dishmaker
Copy link
Contributor

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_der = MyByteMonth(9).to_der().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