@@ -253,6 +253,36 @@ def test_null
253
253
}
254
254
end
255
255
256
+ def test_encode_asn1_data
257
+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = "bla" , 0 , :APPLICATION )
258
+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
259
+ assert_equal :APPLICATION , ai2 . tag_class
260
+ assert_equal 0 , ai2 . tag
261
+ assert_equal i , ai2 . value
262
+
263
+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = "bla" , 4 , :UNIVERSAL )
264
+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
265
+ assert_equal :UNIVERSAL , ai2 . tag_class
266
+ assert_equal 4 , ai2 . tag
267
+ assert_equal i , ai2 . value
268
+
269
+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = [ "bla" ] , 0 , :APPLICATION )
270
+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
271
+ assert_equal :APPLICATION , ai2 . tag_class
272
+ assert_equal 0 , ai2 . tag
273
+ assert_equal "bla" , ai2 . value
274
+
275
+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = [ "bla" , "bla" ] , 0 , :APPLICATION )
276
+ ai2 = OpenSSL ::ASN1 . decode ( ai . to_der )
277
+ assert_equal :APPLICATION , ai2 . tag_class
278
+ assert_equal 0 , ai2 . tag
279
+ assert_equal "blabla" , ai2 . value
280
+
281
+ assert_raise ( ArgumentError ) { OpenSSL ::ASN1 ::ASN1Data . new ( 1 ) . to_der }
282
+ assert_raise ( "no implicit conversion of Integer into String" ) { OpenSSL ::ASN1 ::ASN1Data . new ( 1 , 0 , :APPLICATION ) . to_der }
283
+ assert_raise ( "no implicit conversion of Integer into String" ) { OpenSSL ::ASN1 ::ASN1Data . new ( 1 , 0 , :CONTEXT_SPECIFIC ) . to_der }
284
+ end
285
+
256
286
def test_encode_nil
257
287
#Primitives raise TypeError, Constructives NoMethodError
258
288
@@ -1152,7 +1182,7 @@ def test_decode
1152
1182
# This is from the upstream MRI tests, might be superseded by `test_bit_string_infinite_length`?
1153
1183
def test_bitstring
1154
1184
# TODO: Import Issue
1155
- # fails <nil> expected but was <0>
1185
+ # fails <nil> expected but was <0>
1156
1186
#encode_decode_test B(%w{ 03 01 00 }), OpenSSL::ASN1::BitString.new(B(%w{}))
1157
1187
# TODO: Import Issue
1158
1188
# fails with <nil> expected but was <0>
0 commit comments