@@ -1049,10 +1049,15 @@ else if ( obj instanceof ASN1GraphicString ) {
1049
1049
if (taggedObj .getTagClass () == BERTags .APPLICATION ) {
1050
1050
IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1051
1051
IRubyObject tag_class = runtime .newSymbol ("APPLICATION" );
1052
- final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1053
- @ SuppressWarnings ("unchecked" )
1054
- final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1055
- return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1052
+ try {
1053
+ final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1054
+ @ SuppressWarnings ("unchecked" )
1055
+ final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1056
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1057
+ } catch (IllegalStateException e ) {
1058
+ IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ()).callMethod (context , "value" );
1059
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { val , tag , tag_class }, Block .NULL_BLOCK );
1060
+ }
1056
1061
} else {
1057
1062
IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ());
1058
1063
IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
@@ -1380,12 +1385,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
1380
1385
vec .add ( data );
1381
1386
}
1382
1387
return new DERTaggedObject (isExplicitTagging (), tag , new DERSequence (vec ));
1388
+ } else if (value instanceof ASN1Data ) {
1389
+ return new DERTaggedObject (isExplicitTagging (), tag , ((ASN1Data ) value ).toASN1 (context ));
1390
+ } else if (value instanceof RubyObject ) {
1391
+ return new DERTaggedObject (isExplicitTagging (), getTagClass (context ), tag , new DERGeneralString (value .asString ().asJavaString ()));
1392
+ } else {
1393
+ throw context .runtime .newTypeError ("no implicit conversion of " + value .getMetaClass ().getBaseName () + " into String" );
1383
1394
}
1384
-
1385
- if (!(value instanceof ASN1Data )) {
1386
- throw new UnsupportedOperationException ("toASN1 " + inspect () + " value: " + value .inspect () + " (" + value .getMetaClass () + ")" );
1387
- }
1388
- return new DERTaggedObject (isExplicitTagging (), tag , ((ASN1Data ) value ).toASN1 (context ));
1389
1395
}
1390
1396
1391
1397
@ JRubyMethod
0 commit comments