Skip to content

Commit 6cd020a

Browse files
authored
der: test: add ImplicitChoice constructed: true variant (#1809)
1 parent 76a97a6 commit 6cd020a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

der/tests/derive.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ mod choice {
111111

112112
/// `Choice` with `IMPLICIT` tagging.
113113
mod implicit {
114+
use der::asn1::Null;
114115
use der::{
115116
Choice, Decode, Encode, Sequence, SliceWriter,
116-
asn1::{BitStringRef, GeneralizedTime},
117+
asn1::{BitStringRef, GeneralizedTime, SequenceOf},
117118
};
118119
use hex_literal::hex;
119120

@@ -129,6 +130,9 @@ mod choice {
129130

130131
#[asn1(context_specific = "2", type = "UTF8String")]
131132
Utf8String(String),
133+
134+
#[asn1(context_specific = "3", constructed = "true")]
135+
SequenceOfNulls(SequenceOf<Null, 1>),
132136
}
133137

134138
impl<'a> ImplicitChoice<'a> {
@@ -180,6 +184,24 @@ mod choice {
180184
assert_eq!(TIME_DER, encoder.finish().unwrap());
181185
}
182186

187+
#[test]
188+
fn roundtrip_implicit_constructed_variant() {
189+
let mut seq = SequenceOf::new();
190+
seq.add(Null).unwrap();
191+
let obj = ImplicitChoice::SequenceOfNulls(seq);
192+
let mut buf = [0u8; 128];
193+
194+
let mut encoder = SliceWriter::new(&mut buf);
195+
obj.encode(&mut encoder).unwrap();
196+
197+
let encoded = encoder.finish().unwrap();
198+
println!("encoded: {:02X?}", encoded);
199+
200+
let decoded = ImplicitChoice::from_der(encoded).unwrap();
201+
202+
assert_eq!(decoded, obj);
203+
}
204+
183205
/// Test case for `CHOICE` inside `[0]` `EXPLICIT` tag in `SEQUENCE`.
184206
#[derive(Sequence, Debug, Eq, PartialEq)]
185207
pub struct ExplicitChoiceInsideSequence<'a> {

0 commit comments

Comments
 (0)