@@ -934,7 +934,7 @@ private static RubyString name(final ThreadContext context, IRubyObject value,
934
934
} // ObjectId
935
935
936
936
static IRubyObject decodeObject (final ThreadContext context ,
937
- final RubyModule ASN1 , final ASN1Encodable obj )
937
+ final RubyModule ASN1 , final org . bouncycastle . asn1 . ASN1Encodable obj )
938
938
throws IOException , IllegalArgumentException {
939
939
final Ruby runtime = context .runtime ;
940
940
@@ -1046,34 +1046,20 @@ else if ( obj instanceof ASN1GraphicString ) {
1046
1046
1047
1047
if (obj instanceof ASN1TaggedObject ) {
1048
1048
final ASN1TaggedObject taggedObj = (ASN1TaggedObject ) obj ;
1049
- // IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject());
1050
- IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1051
- IRubyObject tag_class ;
1052
- switch (taggedObj .getTagClass ()) {
1053
- case BERTags .PRIVATE :
1054
- tag_class = runtime .newSymbol ("PRIVATE" );
1055
- break ;
1056
- case BERTags .APPLICATION :
1057
- tag_class = runtime .newSymbol ("APPLICATION" );
1058
- break ;
1059
- case BERTags .CONTEXT_SPECIFIC :
1060
- tag_class = runtime .newSymbol ("CONTEXT_SPECIFIC" );
1061
- break ;
1062
- default :
1063
- tag_class = runtime .newSymbol ("UNIVERSAL" );
1064
- break ;
1065
- }
1066
-
1067
- final ASN1Encodable taggedBaseObj = taggedObj .getBaseObject ();
1068
-
1069
- // TODO: how to infer that this tagged object is constructed
1070
- if (taggedBaseObj instanceof ASN1Sequence ) {
1071
- final ASN1Sequence sequence = (ASN1Sequence ) taggedBaseObj ;
1049
+ if (taggedObj .getTagClass () == BERTags .APPLICATION ) {
1050
+ IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1051
+ IRubyObject tag_class = runtime .newSymbol ("APPLICATION" );
1052
+ final ASN1Sequence sequence = (ASN1Sequence ) taggedObj .getBaseUniversal (false , SEQUENCE );
1053
+ @ SuppressWarnings ("unchecked" )
1072
1054
final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1073
1055
return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1056
+ } else {
1057
+ IRubyObject val = decodeObject (context , ASN1 , taggedObj .getBaseObject ());
1058
+ IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1059
+ IRubyObject tag_class = runtime .newSymbol ("CONTEXT_SPECIFIC" );
1060
+ final RubyArray valArr = runtime .newArray (val );
1061
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1074
1062
}
1075
-
1076
- return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { decodeObject (context , ASN1 , taggedBaseObj ).callMethod (context , "value" ), tag , tag_class }, Block .NULL_BLOCK );
1077
1063
}
1078
1064
1079
1065
if ( obj instanceof ASN1Sequence ) {
@@ -1381,23 +1367,8 @@ ASN1Encodable toASN1(final ThreadContext context) {
1381
1367
1382
1368
final ASN1TaggedObject toASN1TaggedObject (final ThreadContext context ) {
1383
1369
final int tag = getTag (context );
1384
- final RubyModule ASN1 = _ASN1 (context .runtime );
1385
-
1386
- IRubyObject value = callMethod (context , "value" );
1387
- final IRubyObject tagClass = callMethod (context , "tag_class" );
1388
- int berTag ;
1389
- String tagClassName = tagClass .toString ();
1390
-
1391
- if (tagClassName .equals ("PRIVATE" )) {
1392
- berTag = BERTags .PRIVATE ;
1393
- } else if (tagClassName .equals ("APPLICATION" )) {
1394
- berTag = BERTags .APPLICATION ;
1395
- } else if (tagClassName .equals ("CONTEXT_SPECIFIC" )) {
1396
- berTag = BERTags .CONTEXT_SPECIFIC ;
1397
- } else {
1398
- berTag = BERTags .UNIVERSAL ;
1399
- }
1400
1370
1371
+ final IRubyObject value = callMethod (context , "value" );
1401
1372
if (value instanceof RubyArray ) {
1402
1373
final RubyArray arr = (RubyArray ) value ;
1403
1374
assert ! arr .isEmpty ();
@@ -1408,16 +1379,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
1408
1379
if ( data == null ) break ;
1409
1380
vec .add ( data );
1410
1381
}
1411
-
1412
- // TODO: it's not possible to generate a constructed tagged object, bc raises exception
1413
- // berTag = berTag | BERTags.CONSTRUCTED;
1414
- return new DERTaggedObject (isExplicitTagging (), berTag , tag , new DERSequence (vec ));
1382
+ return new DERTaggedObject (isExplicitTagging (), tag , new DERSequence (vec ));
1415
1383
}
1416
1384
1417
1385
if (!(value instanceof ASN1Data )) {
1418
1386
throw new UnsupportedOperationException ("toASN1 " + inspect () + " value: " + value .inspect () + " (" + value .getMetaClass () + ")" );
1419
1387
}
1420
- return new DERTaggedObject (isExplicitTagging (), berTag , tag , ((ASN1Data ) value ).toASN1 (context ));
1388
+ return new DERTaggedObject (isExplicitTagging (), tag , ((ASN1Data ) value ).toASN1 (context ));
1421
1389
}
1422
1390
1423
1391
@ JRubyMethod
0 commit comments