@@ -778,7 +778,9 @@ mod bitstring {
778778 assert_eq ! ( reencoded, BITSTRING_EXAMPLE ) ;
779779 }
780780
781- /// this BitString will allow only 3..=4 bits
781+ /// this BitString will allow only 3..=4 bits in Decode
782+ ///
783+ /// but will always Encode 4 bits
782784 #[ derive( BitString ) ]
783785 pub struct MyBitString3or4 {
784786 pub bit_0 : bool ,
@@ -844,8 +846,8 @@ mod bitstring {
844846 . to_der ( )
845847 . unwrap ( ) ;
846848
847- // 3 bits used, 5 unused
848- assert_eq ! ( encoded_3_zeros, hex!( "03 02 05 00" ) ) ;
849+ // 4 bits used, 4 unused
850+ assert_eq ! ( encoded_3_zeros, hex!( "03 02 04 00" ) ) ;
849851 }
850852
851853 #[ test]
@@ -859,8 +861,8 @@ mod bitstring {
859861 . to_der ( )
860862 . unwrap ( ) ;
861863
862- // 3 bits used, 5 unused
863- assert_eq ! ( encoded_3_zeros, hex!( "03 02 05 E0" ) ) ;
864+ // 4 bits used, 4 unused
865+ assert_eq ! ( encoded_3_zeros, hex!( "03 02 04 E0" ) ) ;
864866 }
865867
866868 #[ test]
@@ -892,6 +894,107 @@ mod bitstring {
892894 // 4 bits used, 4 unused
893895 assert_eq ! ( encoded_4_zeros, hex!( "03 02 04 10" ) ) ;
894896 }
897+
898+ /// ```asn1
899+ /// PasswordFlags ::= BIT STRING {
900+ /// case-sensitive (0),
901+ /// local (1),
902+ /// change-disabled (2),
903+ /// unblock-disabled (3),
904+ /// initialized (4),
905+ /// needs-padding (5),
906+ /// unblockingPassword (6),
907+ /// soPassword (7),
908+ /// disable-allowed (8),
909+ /// integrity-protected (9),
910+ /// confidentiality-protected (10),
911+ /// exchangeRefData (11),
912+ /// resetRetryCounter1 (12),
913+ /// resetRetryCounter2 (13),
914+ /// context-dependent (14),
915+ /// multiStepProtocol (15)
916+ /// }
917+ /// ```
918+ #[ derive( Clone , Debug , Eq , PartialEq , BitString ) ]
919+ pub struct PasswordFlags {
920+ /// case-sensitive (0)
921+ pub case_sensitive : bool ,
922+
923+ /// local (1)
924+ pub local : bool ,
925+
926+ /// change-disabled (2)
927+ pub change_disabled : bool ,
928+
929+ /// unblock-disabled (3)
930+ pub unblock_disabled : bool ,
931+
932+ /// initialized (4)
933+ pub initialized : bool ,
934+
935+ /// needs-padding (5)
936+ pub needs_padding : bool ,
937+
938+ /// unblockingPassword (6)
939+ pub unblocking_password : bool ,
940+
941+ /// soPassword (7)
942+ pub so_password : bool ,
943+
944+ /// disable-allowed (8)
945+ pub disable_allowed : bool ,
946+
947+ /// integrity-protected (9)
948+ pub integrity_protected : bool ,
949+
950+ /// confidentiality-protected (10)
951+ pub confidentiality_protected : bool ,
952+
953+ /// exchangeRefData (11)
954+ pub exchange_ref_data : bool ,
955+
956+ /// Second edition 2016-05-15
957+ /// resetRetryCounter1 (12)
958+ #[ asn1( optional = "true" ) ]
959+ pub reset_retry_counter1 : bool ,
960+
961+ /// resetRetryCounter2 (13)
962+ #[ asn1( optional = "true" ) ]
963+ pub reset_retry_counter2 : bool ,
964+
965+ /// context-dependent (14)
966+ #[ asn1( optional = "true" ) ]
967+ pub context_dependent : bool ,
968+
969+ /// multiStepProtocol (15)
970+ #[ asn1( optional = "true" ) ]
971+ pub multi_step_protocol : bool ,
972+
973+ /// fake_bit_for_testing (16)
974+ #[ asn1( optional = "true" ) ]
975+ pub fake_bit_for_testing : bool ,
976+ }
977+
978+ const PASS_FLAGS_EXAMPLE_IN : & [ u8 ] = & hex ! ( "03 03 04 FF FF" ) ;
979+ const PASS_FLAGS_EXAMPLE_OUT : & [ u8 ] = & hex ! ( "03 04 07 FF F0 00" ) ;
980+
981+ #[ test]
982+ fn decode_short_bitstring_2_bytes ( ) {
983+ let pass_flags = PasswordFlags :: from_der ( PASS_FLAGS_EXAMPLE_IN ) . unwrap ( ) ;
984+
985+ // case-sensitive (0)
986+ assert ! ( pass_flags. case_sensitive) ;
987+
988+ // exchangeRefData (11)
989+ assert ! ( pass_flags. exchange_ref_data) ;
990+
991+ // resetRetryCounter1 (12)
992+ assert ! ( !pass_flags. reset_retry_counter1) ;
993+
994+ let reencoded = pass_flags. to_der ( ) . unwrap ( ) ;
995+
996+ assert_eq ! ( reencoded, PASS_FLAGS_EXAMPLE_OUT ) ;
997+ }
895998}
896999mod infer_default {
8971000 //! When another crate might define a PartialEq for another type, the use of
0 commit comments