@@ -251,6 +251,36 @@ def test_null
251251 }
252252 end
253253
254+ def test_encode_asn1_data
255+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = "bla" , 0 , :APPLICATION )
256+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
257+ assert_equal :APPLICATION , ai2 . tag_class
258+ assert_equal 0 , ai2 . tag
259+ assert_equal i , ai2 . value
260+
261+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = "bla" , 4 , :UNIVERSAL )
262+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
263+ assert_equal :UNIVERSAL , ai2 . tag_class
264+ assert_equal 4 , ai2 . tag
265+ assert_equal i , ai2 . value
266+
267+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = [ "bla" ] , 0 , :APPLICATION )
268+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
269+ assert_equal :APPLICATION , ai2 . tag_class
270+ assert_equal 0 , ai2 . tag
271+ assert_equal "bla" , ai2 . value
272+
273+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = [ "bla" , "bla" ] , 0 , :APPLICATION )
274+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
275+ assert_equal :APPLICATION , ai2 . tag_class
276+ assert_equal 0 , ai2 . tag
277+ assert_equal "blabla" , ai2 . value
278+
279+ assert_raise ( ArgumentError ) { OpenSSL ::ASN1 ::ASN1Data . new ( 1 ) . to_der }
280+ assert_raise ( "no implicit conversion of Integer into String" ) { OpenSSL ::ASN1 ::ASN1Data . new ( 1 , 0 , :APPLICATION ) . to_der }
281+ assert_raise ( "no implicit conversion of Integer into String" ) { OpenSSL ::ASN1 ::ASN1Data . new ( 1 , 0 , :CONTEXT_SPECIFIC ) . to_der }
282+ end
283+
254284 def test_encode_nil
255285 #Primitives raise TypeError, Constructives NoMethodError
256286
@@ -1161,7 +1191,7 @@ def test_decode
11611191 # This is from the upstream MRI tests, might be superseded by `test_bit_string_infinite_length`?
11621192 def test_bitstring
11631193 # TODO: Import Issue
1164- # fails <nil> expected but was <0>
1194+ # fails <nil> expected but was <0>
11651195 #encode_decode_test B(%w{ 03 01 00 }), OpenSSL::ASN1::BitString.new(B(%w{}))
11661196 # TODO: Import Issue
11671197 # fails with <nil> expected but was <0>
0 commit comments