diff --git a/src/main/java/org/jruby/ext/openssl/ASN1.java b/src/main/java/org/jruby/ext/openssl/ASN1.java index 6a221049..0dd7e337 100644 --- a/src/main/java/org/jruby/ext/openssl/ASN1.java +++ b/src/main/java/org/jruby/ext/openssl/ASN1.java @@ -1506,7 +1506,7 @@ public Primitive(Ruby runtime, RubyClass type) { @Override @JRubyMethod public IRubyObject to_der(final ThreadContext context) { - if ( value(context).isNil() ) { + if ( value(context).isNil() && !isNull() ) { // MRI compatibility but avoids Java exceptions as well e.g. // Java::JavaLang::NumberFormatException // java.math.BigInteger.(BigInteger.java:296) @@ -1596,7 +1596,7 @@ boolean isExplicitTagging() { @Override boolean isImplicitTagging() { - IRubyObject tagging = getInstanceVariable("@tagging"); + IRubyObject tagging = tagging(); if ( tagging.isNil() ) return true; return "IMPLICIT".equals( tagging.toString() ); } @@ -1606,6 +1606,10 @@ boolean isEOC() { return false; } + private boolean isNull() { + return "Null".equals(getMetaClass().getRealClass().getBaseName()); + } + @Override byte[] toDER(final ThreadContext context) throws IOException { return toASN1(context).toASN1Primitive().getEncoded(ASN1Encoding.DER); diff --git a/src/test/ruby/test_asn1.rb b/src/test/ruby/test_asn1.rb index 0e97f190..9867a4b3 100644 --- a/src/test/ruby/test_asn1.rb +++ b/src/test/ruby/test_asn1.rb @@ -245,9 +245,7 @@ def test_encode_nested_set_to_der end def test_null - # TODO: Import Issue -- Is this related to the comment below in test_encode_all? - # TypeError: nil value - #encode_decode_test B(%w{ 05 00 }), OpenSSL::ASN1::Null.new(nil) + encode_decode_test B(%w{ 05 00 }), OpenSSL::ASN1::Null.new(nil) assert_raise(OpenSSL::ASN1::ASN1Error) { OpenSSL::ASN1.decode(B(%w{ 05 01 00 })) } @@ -384,13 +382,11 @@ def test_simple_to_der def test_sequence encode_decode_test B(%w{ 30 00 }), OpenSSL::ASN1::Sequence.new([]) - # TODO: Import Issue - # TypeError: nil value - #encode_decode_test B(%w{ 30 07 05 00 30 00 04 01 00 }), OpenSSL::ASN1::Sequence.new([ - # OpenSSL::ASN1::Null.new(nil), - # OpenSSL::ASN1::Sequence.new([]), - # OpenSSL::ASN1::OctetString.new(B(%w{ 00 })) - #]) + encode_decode_test B(%w{ 30 07 05 00 30 00 04 01 00 }), OpenSSL::ASN1::Sequence.new([ + OpenSSL::ASN1::Null.new(nil), + OpenSSL::ASN1::Sequence.new([]), + OpenSSL::ASN1::OctetString.new(B(%w{ 00 })) + ]) expected = OpenSSL::ASN1::Sequence.new([OpenSSL::ASN1::OctetString.new(B(%w{ 00 }))]) expected.indefinite_length = true