@@ -1072,23 +1072,22 @@ else if ( obj instanceof DERBMPString ) {
10721072 return ASN1 .getClass ("ObjectId" ).newInstance (context , runtime .newString (objId ), Block .NULL_BLOCK );
10731073 }
10741074
1075- if ( obj instanceof ASN1ApplicationSpecific ) { // TODO this will likely break in BC version > 1.71
1076- final ASN1ApplicationSpecific appSpecific = (ASN1ApplicationSpecific ) obj ;
1077- IRubyObject tag = runtime .newFixnum ( appSpecific .getApplicationTag () );
1078- IRubyObject tag_class = runtime .newSymbol ("APPLICATION" );
1079- final ASN1Sequence sequence = (ASN1Sequence ) appSpecific .getObject (SEQUENCE );
1080- @ SuppressWarnings ("unchecked" )
1081- final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1082- return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1083- }
1084-
1085- if ( obj instanceof ASN1TaggedObject ) {
1075+ if (obj instanceof ASN1TaggedObject ) {
10861076 final ASN1TaggedObject taggedObj = (ASN1TaggedObject ) obj ;
1087- IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ());
1088- IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1089- IRubyObject tag_class = runtime .newSymbol ("CONTEXT_SPECIFIC" );
1090- final RubyArray valArr = runtime .newArray (val );
1091- return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1077+ if (taggedObj .getTagClass () == BERTags .APPLICATION ) {
1078+ IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1079+ IRubyObject tag_class = runtime .newSymbol ("APPLICATION" );
1080+ final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1081+ @ SuppressWarnings ("unchecked" )
1082+ final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1083+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1084+ } else {
1085+ IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ());
1086+ IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1087+ IRubyObject tag_class = runtime .newSymbol ("CONTEXT_SPECIFIC" );
1088+ final RubyArray valArr = runtime .newArray (val );
1089+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1090+ }
10921091 }
10931092
10941093 if ( obj instanceof ASN1Sequence ) {
@@ -1698,13 +1697,13 @@ ASN1Encodable toASN1(final ThreadContext context) {
16981697 }
16991698
17001699 if ( type == DERGeneralString .class ) {
1701- return DERGeneralString .getInstance ( val .asString ().getBytes () );
1700+ return ASN1GeneralString .getInstance ( val .asString ().getBytes () );
17021701 }
17031702 if ( type == DERVisibleString .class ) {
1704- return DERVisibleString .getInstance ( val .asString ().getBytes () );
1703+ return ASN1VisibleString .getInstance ( val .asString ().getBytes () );
17051704 }
17061705 if ( type == DERNumericString .class ) {
1707- return DERNumericString .getInstance ( val .asString ().getBytes () );
1706+ return ASN1NumericString .getInstance ( val .asString ().getBytes () );
17081707 }
17091708
17101709 if ( val instanceof RubyString ) {
0 commit comments