diff --git a/src/main/java/org/jruby/ext/openssl/ASN1.java b/src/main/java/org/jruby/ext/openssl/ASN1.java index fbe08bb9..79faf133 100644 --- a/src/main/java/org/jruby/ext/openssl/ASN1.java +++ b/src/main/java/org/jruby/ext/openssl/ASN1.java @@ -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++ ) { diff --git a/src/test/ruby/test_asn1.rb b/src/test/ruby/test_asn1.rb index 95f55137..da323f97 100644 --- a/src/test/ruby/test_asn1.rb +++ b/src/test/ruby/test_asn1.rb @@ -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