Skip to content

Commit

Permalink
Add test for #18 (missing constructed bit when serializing [2] IMPLICIT)
Browse files Browse the repository at this point in the history
  • Loading branch information
chifflier committed Feb 22, 2024
1 parent 95f9921 commit ba0a8c2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/issue-18-constructed-bit-sequence.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![cfg(feature = "std")]

use std::borrow::Cow;

use asn1_rs::*;

#[derive(DerSequence, Debug, PartialEq)]
struct Person {
name: String,
age: u16,
}

#[test]
fn issue_18_1() {
// create a sequence from random data
let seq = Sequence::new(Cow::Borrowed(&[2, 2, 18, 52, 2, 2, 86, 12]));

// now serialize a [2] IMPLICIT Person
type T2<'a> = TaggedValue<Sequence<'a>, Error, Implicit, { Class::UNIVERSAL }, 2>;
let tagged = T2::implicit(seq);

let result = tagged.to_der_vec().expect("Could not serialize sequence");

let (_, header) = Header::from_der(&result).expect("could not parse serialized data");
assert!(header.is_constructed());
}

0 comments on commit ba0a8c2

Please sign in to comment.