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 Aug 15, 2023
1 parent 1913525 commit 7d528b4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/ruby/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ def test_encode_integer
assert_equal i, OpenSSL::ASN1.decode(ai.to_der).value
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

0 comments on commit 7d528b4

Please sign in to comment.