Skip to content

Commit ab34440

Browse files
adding basic constructive tests from upstream
commenting out the one I could only half port, as no BC parser supports random tagged objects
1 parent 5140acd commit ab34440

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/main/java/org/jruby/ext/openssl/ASN1.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,10 @@ private static IRubyObject decodeImpl(final ThreadContext context, final RubyMod
12041204
}
12051205
final int length = asn1[ ++offset ] & 0xFF;
12061206
final boolean isIndefiniteLength = length == 0x80;
1207+
IRubyObject decoded;
1208+
1209+
decoded = decodeObject(context, ASN1, readObject(in));
12071210

1208-
IRubyObject decoded = decodeObject(context, ASN1, readObject(in));
12091211
final boolean isUniversal = ((ASN1Data) decoded).isUniversal(context);
12101212

12111213
if (isIndefiniteLength) {

src/test/ruby/test_asn1.rb

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -553,27 +553,19 @@ def test_basic_primitive
553553
#
554554

555555
def test_basic_constructed
556-
#octet_string = OpenSSL::ASN1::OctetString.new(B(%w{ AB CD }))
557-
# TODO: Import Issue
558-
# OpenSSL::ASN1::ASN1Error: Constructive shall only be used with indefinite length
559-
#encode_test B(%w{ 20 00 }), OpenSSL::ASN1::Constructive.new([], 0)
560-
#encode_test B(%w{ 21 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :UNIVERSAL)
561-
#encode_test B(%w{ A1 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :CONTEXT_SPECIFIC)
562-
#encode_test B(%w{ 21 04 04 02 AB CD }), OpenSSL::ASN1::Constructive.new([octet_string], 1)
563-
# Java::JavaLang::UnsupportedOperationException:
564-
# #<OpenSSL::ASN1::Constructive:0x4fc256ec @tag=1, @value=[#<OpenSSL::ASN1::OctetString:0x7fc56d61
565-
# @tag=4, @value="\xAB\xCD", @tag_class=:UNIVERSAL, @tagging=nil, @indefinite_length=false>],
566-
# @tag_class=:CONTEXT_SPECIFIC, @tagging=:EXPLICIT, @indefinite_length=true>
567-
# org.jruby.ext.openssl.ASN1$Constructive.toDER(ASN1.java:1881)
568-
# org.jruby.ext.openssl.ASN1$ASN1Data.to_der(ASN1.java:1414)
569-
# org.jruby.ext.openssl.ASN1$Constructive.to_der(ASN1.java:1858)
570-
#obj = OpenSSL::ASN1::Constructive.new([octet_string], 1)
571-
#obj.indefinite_length = true
572-
#encode_decode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
573-
# (see above) Java::JavaLang::UnsupportedOperationException
574-
#obj = OpenSSL::ASN1::Constructive.new([octet_string, OpenSSL::ASN1::EndOfContent.new], 1)
575-
#obj.indefinite_length = true
576-
#encode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
556+
octet_string = OpenSSL::ASN1::OctetString.new(B(%w{ AB CD }))
557+
encode_test B(%w{ 20 00 }), OpenSSL::ASN1::Constructive.new([], 0)
558+
encode_test B(%w{ 21 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :UNIVERSAL)
559+
encode_test B(%w{ A1 00 }), OpenSSL::ASN1::Constructive.new([], 1, nil, :CONTEXT_SPECIFIC)
560+
encode_test B(%w{ 21 04 04 02 AB CD }), OpenSSL::ASN1::Constructive.new([octet_string], 1)
561+
obj = OpenSSL::ASN1::Constructive.new([octet_string], 1)
562+
obj.indefinite_length = true
563+
encode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
564+
# TODO: BC doesn't support decoding indef constructive asn1s from unsupported tag types.
565+
# encode_decode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
566+
obj = OpenSSL::ASN1::Constructive.new([octet_string, OpenSSL::ASN1::EndOfContent.new], 1)
567+
obj.indefinite_length = true
568+
encode_test B(%w{ 21 80 04 02 AB CD 00 00 }), obj
577569
end
578570

579571
def test_constructive

0 commit comments

Comments
 (0)