File tree Expand file tree Collapse file tree
main/java/org/jruby/ext/openssl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1678,13 +1678,10 @@ private ASN1Encodable toASN1Primitive(final ThreadContext context) {
16781678 }
16791679 if ( type == DERBitString .class ) {
16801680 final byte [] data = val .asString ().getBytes ();
1681- int padBits = 0 ; // padBits < 8 && padBits >= 0
1682- for (int i = (data .length - 1 ); i > -1 ; i --) {
1683- int b = Byte .toUnsignedInt (data [i ]);
1684- if (b != 0 ) {
1685- padBits = Integer .numberOfTrailingZeros (b );
1686- break ;
1687- }
1681+ int padBits = 0 ;
1682+ IRubyObject unused_bits = getInstanceVariable ("@unused_bits" );
1683+ if (unused_bits != null ) {
1684+ padBits = unused_bits .convertToInteger ("to_i" ).getIntValue ();
16881685 }
16891686 return new DERBitString (data , padBits );
16901687 }
Original file line number Diff line number Diff line change @@ -1189,6 +1189,16 @@ def test_bitstring
11891189 #}
11901190 end
11911191
1192+ def test_bit_string_unused_length
1193+ asn = "\x00 \x04 " . b
1194+ asn . prepend "\x03 #{ asn . bytesize . chr } "
1195+ bs = OpenSSL ::ASN1 . decode ( asn )
1196+ assert_equal asn , bs . to_der
1197+
1198+ bs . unused_bits = 6
1199+ assert_equal "\x03 \x02 \x06 \x00 " , bs . to_der
1200+ end
1201+
11921202 def test_bit_string_infinite_length
11931203 begin
11941204 content = [ OpenSSL ::ASN1 ::BitString . new ( "\x01 " ) , OpenSSL ::ASN1 ::EndOfContent . new ( ) ]
You can’t perform that action at this time.
0 commit comments