@@ -1072,10 +1072,15 @@ else if ( obj instanceof ASN1GraphicString ) {
1072
1072
}
1073
1073
1074
1074
if (taggedObj .getTagClass () == BERTags .APPLICATION ) {
1075
- final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1076
- @ SuppressWarnings ("unchecked" )
1077
- final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1078
- return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1075
+ try {
1076
+ final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1077
+ @ SuppressWarnings ("unchecked" )
1078
+ final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1079
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1080
+ } catch (IllegalStateException e ) {
1081
+ IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ()).callMethod (context , "value" );
1082
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { val , tag , tag_class }, Block .NULL_BLOCK );
1083
+ }
1079
1084
} else {
1080
1085
IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ());
1081
1086
final RubyArray valArr = runtime .newArray (val );
@@ -1405,12 +1410,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
1405
1410
vec .add ( data );
1406
1411
}
1407
1412
return new DERTaggedObject (isExplicitTagging (), tag , new DERSequence (vec ));
1413
+ } else if (value instanceof ASN1Data ) {
1414
+ return new DERTaggedObject (isExplicitTagging (), tagClass , tag , ((ASN1Data ) value ).toASN1 (context ));
1415
+ } else if (value instanceof RubyObject ) {
1416
+ return new DERTaggedObject (isExplicitTagging (), tagClass , tag , new DERGeneralString (value .asString ().asJavaString ()));
1417
+ } else {
1418
+ throw context .runtime .newTypeError ("no implicit conversion of " + value .getMetaClass ().getBaseName () + " into String" );
1408
1419
}
1409
-
1410
- if (!(value instanceof ASN1Data )) {
1411
- throw new UnsupportedOperationException ("toASN1 " + inspect () + " value: " + value .inspect () + " (" + value .getMetaClass () + ")" );
1412
- }
1413
- return new DERTaggedObject (isExplicitTagging (), tagClass , tag , ((ASN1Data ) value ).toASN1 (context ));
1414
1420
}
1415
1421
1416
1422
@ JRubyMethod
0 commit comments