@@ -442,11 +442,11 @@ static ASN1ObjectIdentifier sym2Oid(final Ruby runtime, final String name) {
442
442
return getOIDLookup (runtime ).get (name );
443
443
}
444
444
445
- static Map <String , ASN1ObjectIdentifier > getOIDLookup (final Ruby runtime ) {
445
+ private static Map <String , ASN1ObjectIdentifier > getOIDLookup (final Ruby runtime ) {
446
446
return symToOid (runtime );
447
447
}
448
448
449
- static Map <ASN1ObjectIdentifier , String > getSymLookup (final Ruby runtime ) {
449
+ private static Map <ASN1ObjectIdentifier , String > getSymLookup (final Ruby runtime ) {
450
450
return oidToSym (runtime );
451
451
}
452
452
@@ -483,8 +483,8 @@ static Map<ASN1ObjectIdentifier, String> getSymLookup(final Ruby runtime) {
483
483
{"CHARACTER_STRING" , null , null },
484
484
{"BMPSTRING" , org .bouncycastle .asn1 .DERBMPString .class , "BMPString" }};
485
485
486
- private final static Map <Class , Integer > CLASS_TO_ID = new HashMap <Class , Integer >();
487
- private final static Map <String , Integer > RUBYNAME_TO_ID = new HashMap <String , Integer >();
486
+ private final static Map <Class <?> , Integer > CLASS_TO_ID = new HashMap <Class <?> , Integer >(24 );
487
+ private final static Map <String , Integer > RUBYNAME_TO_ID = new HashMap <String , Integer >(24 );
488
488
489
489
static {
490
490
for ( int i = 0 ; i < ASN1_INFO .length ; i ++ ) {
@@ -498,7 +498,7 @@ static Map<ASN1ObjectIdentifier, String> getSymLookup(final Ruby runtime) {
498
498
}
499
499
}
500
500
501
- static int idForClass (Class type ) {
501
+ static int idForJava (Class <?> type ) {
502
502
Integer v = null ;
503
503
while ( type != Object .class && v == null ) {
504
504
v = CLASS_TO_ID .get (type );
@@ -507,11 +507,19 @@ static int idForClass(Class type) {
507
507
return v == null ? -1 : v .intValue ();
508
508
}
509
509
510
- static int idForRubyName (String name ) {
510
+ static int idForJava (final Object obj ) {
511
+ return idForJava ( obj .getClass () );
512
+ }
513
+
514
+ private static int idForRuby (final String name ) {
511
515
Integer v = RUBYNAME_TO_ID .get (name );
512
516
return v == null ? -1 : v .intValue ();
513
517
}
514
518
519
+ static int idForRuby (final RubyClass metaClass ) {
520
+ return idForRuby ( metaClass .getRealClass ().getBaseName () );
521
+ }
522
+
515
523
static Class <? extends ASN1Encodable > classForId (int id ) {
516
524
@ SuppressWarnings ("unchecked" )
517
525
Class <? extends ASN1Encodable > result = (Class <? extends ASN1Encodable >)(ASN1_INFO [id ][1 ]);
@@ -779,7 +787,7 @@ public static IRubyObject oid(final ThreadContext context, final IRubyObject sel
779
787
private static IRubyObject decodeObject (final ThreadContext context , final RubyModule _ASN1 , final Object obj )
780
788
throws IOException , IllegalArgumentException {
781
789
782
- int ix = idForClass (obj .getClass ());
790
+ int ix = idForJava (obj .getClass ());
783
791
final String className = ix == -1 ? null : (String ) ( ASN1_INFO [ix ][2 ] );
784
792
785
793
if ( className != null ) {
@@ -987,7 +995,7 @@ public IRubyObject to_der(final ThreadContext context) {
987
995
}
988
996
989
997
protected IRubyObject defaultTag () {
990
- int i = idForRubyName ( getMetaClass (). getRealClass (). getBaseName () );
998
+ int i = idForRuby ( getMetaClass () );
991
999
if (i != -1 ) {
992
1000
return getRuntime ().newFixnum (i );
993
1001
} else {
@@ -1098,8 +1106,8 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
1098
1106
tag_class = runtime .newSymbol ("UNIVERSAL" );
1099
1107
}
1100
1108
if ( "ObjectId" .equals ( getMetaClass ().getRealClass ().getBaseName () ) ) {
1101
- String v = getSymLookup ( runtime ). get ( getObjectIdentifier (runtime , value .toString ()) );
1102
- if ( v != null ) value = runtime .newString (v );
1109
+ String name = oid2Sym ( runtime , getObjectIdentifier (runtime , value .toString ()) );
1110
+ if ( name != null ) value = runtime .newString (name );
1103
1111
}
1104
1112
1105
1113
this .callMethod (context , "tag=" , tag );
@@ -1111,7 +1119,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
1111
1119
1112
1120
@ Override
1113
1121
ASN1Encodable toASN1 (final ThreadContext context ) {
1114
- final int tag = idForRubyName ( getMetaClass (). getRealClass (). getBaseName () );
1122
+ final int tag = idForRuby ( getMetaClass () );
1115
1123
@ SuppressWarnings ("unchecked" )
1116
1124
Class <? extends ASN1Encodable > impl = (Class <? extends ASN1Encodable >) ASN1_INFO [tag ][1 ];
1117
1125
@@ -1258,7 +1266,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
1258
1266
1259
1267
@ Override
1260
1268
ASN1Encodable toASN1 (final ThreadContext context ) {
1261
- final int id = idForRubyName ( getMetaClass (). getRealClass (). getBaseName () );
1269
+ final int id = idForRuby ( getMetaClass () );
1262
1270
if ( id != -1 ) {
1263
1271
final ASN1EncodableVector vec = new ASN1EncodableVector ();
1264
1272
final RubyArray value = value (context );
0 commit comments