Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -2387,9 +2387,13 @@ byte[] toDER(final ThreadContext context) throws IOException {
final int tagNo = getTag(context);
final boolean isIndefiniteLength = isInfiniteLength();

if ( isExplicitTagging() && defaultTag().isNil() ) {
throw newASN1Error(context.runtime, "explicit tagging of unknown tag");
}

if ( isIndefiniteLength ) {
if ( isExplicitTagging() && ( isSequence() || isSet() || tagNo == SEQUENCE || tagNo == SET ) ) {
final int innerTag = isSequence() ? SEQUENCE : ( isSet() ? SET : tagNo );
if ( isExplicitTagging() ) {
final int innerTag = RubyNumeric.fix2int(defaultTag());
final ByteArrayOutputStream out = new ByteArrayOutputStream(64);
writeDERIdentifier(tagNo, getTagClass(context) | BERTags.CONSTRUCTED, out);
out.write(0x80);
Expand Down
8 changes: 8 additions & 0 deletions test/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,14 @@ def test_indefinite_length_explicit_tagging
assert_equal "\xE1\x80\x31\x80\x02\x01\x01\x00\x00\x00\x00".b, set.to_der
end

def test_constructive_explicit_tagging_of_unknown_tag
[ false, true ].each do |indefinite|
cons = OpenSSL::ASN1::Constructive.new([OpenSSL::ASN1::Integer.new(1)], 16, :EXPLICIT)
cons.indefinite_length = indefinite
assert_raise(OpenSSL::ASN1::ASN1Error) { cons.to_der }
end
end

def test_universal_asn1_data_constructed_bit
seq_data = OpenSSL::ASN1::ASN1Data.new([OpenSSL::ASN1::Integer.new(1)], 16, :UNIVERSAL)
assert_equal "\x30\x03\x02\x01\x01".b, seq_data.to_der
Expand Down
Loading