@@ -111,9 +111,10 @@ mod choice {
111
111
112
112
/// `Choice` with `IMPLICIT` tagging.
113
113
mod implicit {
114
+ use der:: asn1:: Null ;
114
115
use der:: {
115
116
Choice , Decode , Encode , Sequence , SliceWriter ,
116
- asn1:: { BitStringRef , GeneralizedTime } ,
117
+ asn1:: { BitStringRef , GeneralizedTime , SequenceOf } ,
117
118
} ;
118
119
use hex_literal:: hex;
119
120
@@ -129,6 +130,9 @@ mod choice {
129
130
130
131
#[ asn1( context_specific = "2" , type = "UTF8String" ) ]
131
132
Utf8String ( String ) ,
133
+
134
+ #[ asn1( context_specific = "3" , constructed = "true" ) ]
135
+ SequenceOfNulls ( SequenceOf < Null , 1 > ) ,
132
136
}
133
137
134
138
impl < ' a > ImplicitChoice < ' a > {
@@ -180,6 +184,24 @@ mod choice {
180
184
assert_eq ! ( TIME_DER , encoder. finish( ) . unwrap( ) ) ;
181
185
}
182
186
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
+
183
205
/// Test case for `CHOICE` inside `[0]` `EXPLICIT` tag in `SEQUENCE`.
184
206
#[ derive( Sequence , Debug , Eq , PartialEq ) ]
185
207
pub struct ExplicitChoiceInsideSequence < ' a > {
0 commit comments