Skip to content

Commit

Permalink
[fix] raise ASN1Error when unused_bits out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Jan 9, 2025
1 parent ea06253 commit 86daed3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,11 @@ private ASN1Encodable toASN1Primitive(final ThreadContext context) {
if (unused_bits != null) {
padBits = unused_bits.convertToInteger("to_i").getIntValue();
}
return new DERBitString(data, padBits);
try {
return new DERBitString(data, padBits);
} catch (IllegalArgumentException e) {
throw newASN1Error(context.runtime, e.getMessage());
}
}
if ( type == DERIA5String.class ) {
return new DERIA5String( val.asString().toString() );
Expand Down
12 changes: 5 additions & 7 deletions src/test/ruby/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1180,13 +1180,11 @@ def test_bitstring
OpenSSL::ASN1.decode(B(%w{ 03 03 08 FF 00 }))
}

# TODO: Import Issue
# exception was expected but none was thrown.
#assert_raise(OpenSSL::ASN1::ASN1Error) {
# obj = OpenSSL::ASN1::BitString.new(B(%w{ FF FF }))
# obj.unused_bits = 8
# obj.to_der
#}
assert_raise(OpenSSL::ASN1::ASN1Error) {
obj = OpenSSL::ASN1::BitString.new(B(%w{ FF FF }))
obj.unused_bits = 8
obj.to_der
}
end

def test_bit_string_unused_length
Expand Down

0 comments on commit 86daed3

Please sign in to comment.