File tree 2 files changed +19
-3
lines changed
main/java/org/jruby/ext/openssl
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -1390,20 +1390,26 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
1390
1390
if ( arr .size () > 1 ) {
1391
1391
ASN1EncodableVector vec = new ASN1EncodableVector ();
1392
1392
for ( final IRubyObject obj : arr .toJavaArray () ) {
1393
- ASN1Encodable data = ((ASN1Data ) obj ).toASN1 (context );
1393
+ ASN1Encodable data = ((ASN1OctetString ) obj ).toASN1 (context );
1394
1394
if ( data == null ) break ; vec .add ( data );
1395
1395
}
1396
1396
return new DERTaggedObject (isExplicitTagging (), tag , new DERSequence (vec ));
1397
1397
}
1398
1398
else if ( arr .size () == 1 ) {
1399
- ASN1Encodable data = ((ASN1Data ) arr .entry (0 )).toASN1 (context );
1399
+ ASN1Encodable data = ((ASN1OctetString ) arr .entry (0 )).toASN1 (context );
1400
1400
return new DERTaggedObject (isExplicitTagging (), tag , data );
1401
1401
}
1402
1402
else {
1403
1403
throw new IllegalStateException ("empty array detected" );
1404
1404
}
1405
+ } else if (val instanceof RubyString || val instanceof java .lang .String ) {
1406
+ return new DERTaggedObject (isExplicitTagging (), tag , ((ASN1OctetString ) val ).toASN1 (context ));
1407
+ } else if (val instanceof ASN1OctetString ) {
1408
+ return new DERTaggedObject (isExplicitTagging (), tag , val .toASN1 (context ));
1409
+ } else {
1410
+ throw runtime .newTypeError ("no implicit conversion of " + val .getMetaClass ().getName () + " into String" );
1405
1411
}
1406
- return new DERTaggedObject ( isExplicitTagging (), tag , (( ASN1Data ) val ). toASN1 ( context ));
1412
+
1407
1413
}
1408
1414
1409
1415
@ JRubyMethod
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ def test_encode_integer
21
21
assert_equal i , OpenSSL ::ASN1 . decode ( ai . to_der ) . value
22
22
end
23
23
24
+ def test_encode_asn1_data
25
+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = "bla" , 0 , :APPLICATION )
26
+ assert_equal i , OpenSSL ::ASN1 . decode ( ai . to_der ) . value
27
+
28
+ ai = OpenSSL ::ASN1 ::ASN1Data . new ( i = [ "bla" ] , 0 , :APPLICATION )
29
+ assert_equal i , OpenSSL ::ASN1 . decode ( ai . to_der ) . value
30
+
31
+ assert_raise ( TypeError ) { OpenSSL ::ASN1 ::ASN1Data . new ( 1 ) . to_der }
32
+ end
33
+
24
34
def test_encode_nil
25
35
#Primitives raise TypeError, Constructives NoMethodError
26
36
You can’t perform that action at this time.
0 commit comments