File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
main/java/org/jruby/ext/openssl Expand file tree Collapse file tree 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) {
13901390 if ( arr .size () > 1 ) {
13911391 ASN1EncodableVector vec = new ASN1EncodableVector ();
13921392 for ( final IRubyObject obj : arr .toJavaArray () ) {
1393- ASN1Encodable data = ((ASN1Data ) obj ).toASN1 (context );
1393+ ASN1Encodable data = ((ASN1OctetString ) obj ).toASN1 (context );
13941394 if ( data == null ) break ; vec .add ( data );
13951395 }
13961396 return new DERTaggedObject (isExplicitTagging (), tag , new DERSequence (vec ));
13971397 }
13981398 else if ( arr .size () == 1 ) {
1399- ASN1Encodable data = ((ASN1Data ) arr .entry (0 )).toASN1 (context );
1399+ ASN1Encodable data = ((ASN1OctetString ) arr .entry (0 )).toASN1 (context );
14001400 return new DERTaggedObject (isExplicitTagging (), tag , data );
14011401 }
14021402 else {
14031403 throw new IllegalStateException ("empty array detected" );
14041404 }
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" );
14051411 }
1406- return new DERTaggedObject ( isExplicitTagging (), tag , (( ASN1Data ) val ). toASN1 ( context ));
1412+
14071413 }
14081414
14091415 @ JRubyMethod
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ def test_encode_integer
2121 assert_equal i , OpenSSL ::ASN1 . decode ( ai . to_der ) . value
2222 end
2323
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+
2434 def test_encode_nil
2535 #Primitives raise TypeError, Constructives NoMethodError
2636
You can’t perform that action at this time.
0 commit comments