@@ -1064,10 +1064,15 @@ else if ( obj instanceof ASN1GraphicString ) {
1064
1064
}
1065
1065
1066
1066
if (taggedObj .getTagClass () == BERTags .APPLICATION ) {
1067
- final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1068
- @ SuppressWarnings ("unchecked" )
1069
- final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1070
- return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1067
+ try {
1068
+ final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1069
+ @ SuppressWarnings ("unchecked" )
1070
+ final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1071
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1072
+ } catch (IllegalStateException e ) {
1073
+ IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ()).callMethod (context , "value" );
1074
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { val , tag , tag_class }, Block .NULL_BLOCK );
1075
+ }
1071
1076
} else {
1072
1077
IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ());
1073
1078
final RubyArray valArr = runtime .newArray (val );
@@ -1397,12 +1402,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
1397
1402
vec .add ( data );
1398
1403
}
1399
1404
return new DERTaggedObject (isExplicitTagging (), tag , new DERSequence (vec ));
1405
+ } else if (value instanceof ASN1Data ) {
1406
+ return new DERTaggedObject (isExplicitTagging (), tagClass , tag , ((ASN1Data ) value ).toASN1 (context ));
1407
+ } else if (value instanceof RubyObject ) {
1408
+ return new DERTaggedObject (isExplicitTagging (), tagClass , tag , new DERGeneralString (value .asString ().asJavaString ()));
1409
+ } else {
1410
+ throw context .runtime .newTypeError ("no implicit conversion of " + value .getMetaClass ().getBaseName () + " into String" );
1400
1411
}
1401
-
1402
- if (!(value instanceof ASN1Data )) {
1403
- throw new UnsupportedOperationException ("toASN1 " + inspect () + " value: " + value .inspect () + " (" + value .getMetaClass () + ")" );
1404
- }
1405
- return new DERTaggedObject (isExplicitTagging (), tagClass , tag , ((ASN1Data ) value ).toASN1 (context ));
1406
1412
}
1407
1413
1408
1414
@ JRubyMethod
0 commit comments