File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
main/java/org/jruby/ext/openssl Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -1678,13 +1678,10 @@ private ASN1Encodable toASN1Primitive(final ThreadContext context) {
1678
1678
}
1679
1679
if ( type == DERBitString .class ) {
1680
1680
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 ();
1688
1685
}
1689
1686
return new DERBitString (data , padBits );
1690
1687
}
Original file line number Diff line number Diff line change @@ -1189,6 +1189,16 @@ def test_bitstring
1189
1189
#}
1190
1190
end
1191
1191
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
+
1192
1202
def test_bit_string_infinite_length
1193
1203
begin
1194
1204
content = [ OpenSSL ::ASN1 ::BitString . new ( "\x01 " ) , OpenSSL ::ASN1 ::EndOfContent . new ( ) ]
You can’t perform that action at this time.
0 commit comments