@@ -453,6 +453,92 @@ mod sequence {
453
453
assert_eq ! ( obj, obj_decoded) ;
454
454
}
455
455
456
+ #[ derive( Sequence , Default , Eq , PartialEq , Debug ) ]
457
+ #[ asn1( tag_mode = "IMPLICIT" ) ]
458
+ pub struct TypeCheckOwnedSequenceFieldAttributeCombinations {
459
+ /// Without deref = "true" macro generates an error:
460
+ ///
461
+ /// the trait `From<Vec<u8>>` is not implemented for `BitStringRef<'_>`
462
+ #[ asn1( type = "OCTET STRING" , deref = "true" ) ]
463
+ pub owned_bytes : Vec < u8 > ,
464
+
465
+ #[ asn1( type = "BIT STRING" , deref = "true" ) ]
466
+ pub owned_bits : Vec < u8 > ,
467
+
468
+ /// pure Vec<.> Needs additional deref in the derive macro
469
+ /// for the `OctetStringRef::try_from`
470
+ #[ asn1( type = "OCTET STRING" , context_specific = "0" , deref = "true" ) ]
471
+ pub owned_implicit_bytes : Vec < u8 > ,
472
+
473
+ /// deref
474
+ #[ asn1( type = "BIT STRING" , context_specific = "1" , deref = "true" ) ]
475
+ pub owned_implicit_bits : Vec < u8 > ,
476
+
477
+ /// deref
478
+ #[ asn1(
479
+ type = "OCTET STRING" ,
480
+ context_specific = "2" ,
481
+ deref = "true" ,
482
+ tag_mode = "EXPLICIT"
483
+ ) ]
484
+ pub owned_explicit_bytes : Vec < u8 > ,
485
+
486
+ /// deref
487
+ #[ asn1(
488
+ type = "BIT STRING" ,
489
+ context_specific = "3" ,
490
+ deref = "true" ,
491
+ tag_mode = "EXPLICIT"
492
+ ) ]
493
+ pub owned_explicit_bits : Vec < u8 > ,
494
+
495
+ /// Option<Vec<..>> does not need deref
496
+ #[ asn1( type = "BIT STRING" , context_specific = "4" , optional = "true" ) ]
497
+ pub owned_optional_implicit_bits : Option < Vec < u8 > > ,
498
+ #[ asn1( type = "OCTET STRING" , context_specific = "5" , optional = "true" ) ]
499
+ pub owned_optional_implicit_bytes : Option < Vec < u8 > > ,
500
+
501
+ #[ asn1(
502
+ type = "OCTET STRING" ,
503
+ context_specific = "6" ,
504
+ optional = "true" ,
505
+ tag_mode = "EXPLICIT"
506
+ ) ]
507
+ pub owned_optional_explicit_bits : Option < Vec < u8 > > ,
508
+ #[ asn1(
509
+ type = "OCTET STRING" ,
510
+ context_specific = "7" ,
511
+ optional = "true" ,
512
+ tag_mode = "EXPLICIT"
513
+ ) ]
514
+ pub owned_optional_explicit_bytes : Option < Vec < u8 > > ,
515
+ }
516
+
517
+ #[ test]
518
+ fn type_combinations_alloc_instance ( ) {
519
+ let obj = TypeCheckOwnedSequenceFieldAttributeCombinations {
520
+ owned_bytes : vec ! [ 0xAA , 0xBB ] ,
521
+ owned_bits : vec ! [ 0xCC , 0xDD ] ,
522
+
523
+ owned_implicit_bytes : vec ! [ 0 , 1 ] ,
524
+ owned_implicit_bits : vec ! [ 2 , 3 ] ,
525
+
526
+ owned_explicit_bytes : vec ! [ 4 , 5 ] ,
527
+ owned_explicit_bits : vec ! [ 6 , 7 ] ,
528
+
529
+ owned_optional_implicit_bits : Some ( vec ! [ 8 , 9 ] ) ,
530
+ owned_optional_implicit_bytes : Some ( vec ! [ 10 , 11 ] ) ,
531
+
532
+ owned_optional_explicit_bits : Some ( vec ! [ 12 , 13 ] ) ,
533
+ owned_optional_explicit_bytes : Some ( vec ! [ 14 , 15 ] ) ,
534
+ } ;
535
+
536
+ let der_encoded = obj. to_der ( ) . unwrap ( ) ;
537
+ let obj_decoded =
538
+ TypeCheckOwnedSequenceFieldAttributeCombinations :: from_der ( & der_encoded) . unwrap ( ) ;
539
+ assert_eq ! ( obj, obj_decoded) ;
540
+ }
541
+
456
542
#[ derive( Sequence ) ]
457
543
#[ asn1( error = CustomError ) ]
458
544
pub struct TypeWithCustomError {
0 commit comments