Skip to content

Commit

Permalink
to_der on ASN1Data should convert ruby strings into java strings befo…
Browse files Browse the repository at this point in the history
…re encoding
  • Loading branch information
HoneyryderChuck committed May 10, 2024
1 parent c201ae3 commit 4c57f18
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/test/ruby/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,36 @@ def test_null
}
end

def test_encode_asn1_data
ai = OpenSSL::ASN1::ASN1Data.new(i = "bla", 0, :APPLICATION)
ai2 = OpenSSL::ASN1.decode(ai.to_der)
assert_equal :APPLICATION, ai2.tag_class
assert_equal 0, ai2.tag
assert_equal i, ai2.value

ai = OpenSSL::ASN1::ASN1Data.new(i = "bla", 4, :UNIVERSAL)
ai2 = OpenSSL::ASN1.decode(ai.to_der)
assert_equal :UNIVERSAL, ai2.tag_class
assert_equal 4, ai2.tag
assert_equal i, ai2.value

ai = OpenSSL::ASN1::ASN1Data.new(i = ["bla"], 0, :APPLICATION)
ai2 = OpenSSL::ASN1.decode(ai.to_der)
assert_equal :APPLICATION, ai2.tag_class
assert_equal 0, ai2.tag
assert_equal "bla", ai2.value

ai = OpenSSL::ASN1::ASN1Data.new(i = ["bla", "bla"], 0, :APPLICATION)
ai2 = OpenSSL::ASN1.decode(ai.to_der)
assert_equal :APPLICATION, ai2.tag_class
assert_equal 0, ai2.tag
assert_equal "blabla", ai2.value

assert_raise(ArgumentError) { OpenSSL::ASN1::ASN1Data.new(1).to_der }
assert_raise("no implicit conversion of Integer into String") { OpenSSL::ASN1::ASN1Data.new(1, 0, :APPLICATION).to_der }
assert_raise("no implicit conversion of Integer into String") { OpenSSL::ASN1::ASN1Data.new(1, 0, :CONTEXT_SPECIFIC).to_der }
end

def test_encode_nil
#Primitives raise TypeError, Constructives NoMethodError

Expand Down Expand Up @@ -1161,7 +1191,7 @@ def test_decode
# This is from the upstream MRI tests, might be superseded by `test_bit_string_infinite_length`?
def test_bitstring
# TODO: Import Issue
# fails <nil> expected but was <0>
# fails <nil> expected but was <0>
#encode_decode_test B(%w{ 03 01 00 }), OpenSSL::ASN1::BitString.new(B(%w{}))
# TODO: Import Issue
# fails with <nil> expected but was <0>
Expand Down

0 comments on commit 4c57f18

Please sign in to comment.