Skip to content

Commit

Permalink
call to_der when trying to call on a singlular unwrapped object
Browse files Browse the repository at this point in the history
  • Loading branch information
skunkworker authored and kares committed Feb 13, 2024
1 parent 0068b77 commit 5d944aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,10 @@ private ASN1EncodableVector toASN1EncodableVector(final ThreadContext context) {
if ( addEntry(context, vec, val.entry(i)) ) break;
}
}
else if (respondsTo("to_der")) {
IRubyObject entry = value.callMethod(context, "to_der");
addEntry(context, vec, entry);
}
else {
final int size = RubyInteger.num2int(value.callMethod(context, "size"));
for ( int i = 0; i < size; i++ ) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/ruby/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ def test_encode_integer
assert_equal i, OpenSSL::ASN1.decode(ai.to_der).value
end

def test_encode_nested_sequence_to_der
data_sequence = ::OpenSSL::ASN1::Sequence([::OpenSSL::ASN1::Integer(0)])
asn1 = ::OpenSSL::ASN1::Sequence(data_sequence)
assert_equal "0\x03\x02\x01\x00", asn1.to_der
end

def test_encode_nested_set_to_der
data_set = ::OpenSSL::ASN1::Set([::OpenSSL::ASN1::Integer(0)])
asn1 = ::OpenSSL::ASN1::Set(data_set)
assert_equal "1\x03\x02\x01\x00", asn1.to_der
end

def test_encode_nil
#Primitives raise TypeError, Constructives NoMethodError

Expand Down

0 comments on commit 5d944aa

Please sign in to comment.