@@ -793,117 +793,118 @@ static ASN1ObjectIdentifier toObjectID(final String oid, final boolean silent)
793
793
}
794
794
795
795
@ JRubyMethod (name ="Boolean" , module =true , rest =true )
796
- public static IRubyObject fact_Boolean (IRubyObject self , IRubyObject [] args ) {
797
- return callClassNew ( self , "Boolean" , args );
796
+ public static IRubyObject fact_Boolean (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
797
+ return newInstance ( context , self , "Boolean" , args );
798
798
}
799
799
800
800
@ JRubyMethod (name ="Integer" , module =true , rest =true )
801
- public static IRubyObject fact_Integer (IRubyObject self , IRubyObject [] args ) {
802
- return callClassNew ( self , "Integer" , args );
801
+ public static IRubyObject fact_Integer (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
802
+ return newInstance ( context , self , "Integer" , args );
803
803
}
804
804
805
805
@ JRubyMethod (name ="Enumerated" , module =true , rest =true )
806
- public static IRubyObject fact_Enumerated (IRubyObject self , IRubyObject [] args ) {
807
- return callClassNew ( self , "Enumerated" , args );
806
+ public static IRubyObject fact_Enumerated (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
807
+ return newInstance ( context , self , "Enumerated" , args );
808
808
}
809
809
810
810
@ JRubyMethod (name ="BitString" , module =true , rest =true )
811
- public static IRubyObject fact_BitString (IRubyObject self , IRubyObject [] args ) {
812
- return callClassNew ( self , "BitString" , args );
811
+ public static IRubyObject fact_BitString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
812
+ return newInstance ( context , self , "BitString" , args );
813
813
}
814
814
815
815
@ JRubyMethod (name ="OctetString" , module =true , rest =true )
816
- public static IRubyObject fact_OctetString (IRubyObject self , IRubyObject [] args ) {
817
- return callClassNew ( self , "OctetString" , args );
816
+ public static IRubyObject fact_OctetString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
817
+ return newInstance ( context , self , "OctetString" , args );
818
818
}
819
819
820
820
@ JRubyMethod (name ="UTF8String" , module =true , rest =true )
821
- public static IRubyObject fact_UTF8String (IRubyObject self , IRubyObject [] args ) {
822
- return callClassNew ( self , "UTF8String" , args );
821
+ public static IRubyObject fact_UTF8String (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
822
+ return newInstance ( context , self , "UTF8String" , args );
823
823
}
824
824
825
825
@ JRubyMethod (name ="NumericString" , module =true , rest =true )
826
- public static IRubyObject fact_NumericString (IRubyObject self , IRubyObject [] args ) {
827
- return callClassNew ( self , "NumericString" , args );
826
+ public static IRubyObject fact_NumericString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
827
+ return newInstance ( context , self , "NumericString" , args );
828
828
}
829
829
830
830
@ JRubyMethod (name ="PrintableString" , module =true , rest =true )
831
- public static IRubyObject fact_PrintableString (IRubyObject self , IRubyObject [] args ) {
832
- return callClassNew ( self , "PrintableString" , args );
831
+ public static IRubyObject fact_PrintableString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
832
+ return newInstance ( context , self , "PrintableString" , args );
833
833
}
834
834
835
835
@ JRubyMethod (name ="T61String" , module =true , rest =true )
836
- public static IRubyObject fact_T61String (IRubyObject self , IRubyObject [] args ) {
837
- return callClassNew ( self , "T61String" , args );
836
+ public static IRubyObject fact_T61String (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
837
+ return newInstance ( context , self , "T61String" , args );
838
838
}
839
839
840
840
@ JRubyMethod (name ="VideotexString" , module =true , rest =true )
841
- public static IRubyObject fact_VideotexString (IRubyObject recv , IRubyObject [] args ) {
842
- return (( RubyModule ) recv ). getClass ( "VideotexString" ). callMethod ( recv . getRuntime (). getCurrentContext (), "new" , args );
841
+ public static IRubyObject fact_VideotexString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
842
+ return newInstance ( context , self , "VideotexString" , args );
843
843
}
844
844
845
845
@ JRubyMethod (name ="IA5String" , module =true , rest =true )
846
- public static IRubyObject fact_IA5String (IRubyObject recv , IRubyObject [] args ) {
847
- return (( RubyModule ) recv ). getClass ( "IA5String" ). callMethod ( recv . getRuntime (). getCurrentContext (), "new" , args );
846
+ public static IRubyObject fact_IA5String (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
847
+ return newInstance ( context , self , "IA5String" , args );
848
848
}
849
849
850
850
@ JRubyMethod (name ="GraphicString" , module =true , rest =true )
851
- public static IRubyObject fact_GraphicString (IRubyObject recv , IRubyObject [] args ) {
852
- return (( RubyModule ) recv ). getClass ( "GraphicString" ). callMethod ( recv . getRuntime (). getCurrentContext (), "new" , args );
851
+ public static IRubyObject fact_GraphicString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
852
+ return newInstance ( context , self , "GraphicString" , args );
853
853
}
854
854
855
855
@ JRubyMethod (name ="ISO64String" , module =true , rest =true )
856
- public static IRubyObject fact_ISO64String (IRubyObject recv , IRubyObject [] args ) {
857
- return (( RubyModule ) recv ). getClass ( "ISO64String" ). callMethod ( recv . getRuntime (). getCurrentContext (), "new" , args );
856
+ public static IRubyObject fact_ISO64String (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
857
+ return newInstance ( context , self , "ISO64String" , args );
858
858
}
859
859
860
860
@ JRubyMethod (name ="GeneralString" , module =true , rest =true )
861
- public static IRubyObject fact_GeneralString (IRubyObject self , IRubyObject [] args ) {
862
- return callClassNew ( self , "GeneralString" , args );
861
+ public static IRubyObject fact_GeneralString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
862
+ return newInstance ( context , self , "GeneralString" , args );
863
863
}
864
864
865
865
@ JRubyMethod (name ="UniversalString" , module =true , rest =true )
866
- public static IRubyObject fact_UniversalString (IRubyObject self , IRubyObject [] args ) {
867
- return callClassNew ( self , "UniversalString" , args );
866
+ public static IRubyObject fact_UniversalString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
867
+ return newInstance ( context , self , "UniversalString" , args );
868
868
}
869
869
870
870
@ JRubyMethod (name ="BMPString" , module =true , rest =true )
871
- public static IRubyObject fact_BMPString (IRubyObject self , IRubyObject [] args ) {
872
- return callClassNew ( self , "BMPString" , args );
871
+ public static IRubyObject fact_BMPString (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
872
+ return newInstance ( context , self , "BMPString" , args );
873
873
}
874
874
875
875
@ JRubyMethod (name ="Nul" , module =true , rest =true )
876
- public static IRubyObject fact_Null (IRubyObject self , IRubyObject [] args ) {
877
- return callClassNew ( self , "Null" , args );
876
+ public static IRubyObject fact_Null (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
877
+ return newInstance ( context , self , "Null" , args );
878
878
}
879
879
880
880
@ JRubyMethod (name ="ObjectId" , module =true , rest =true )
881
- public static IRubyObject fact_ObjectId (IRubyObject self , IRubyObject [] args ) {
882
- return callClassNew ( self , "ObjectId" , args );
881
+ public static IRubyObject fact_ObjectId (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
882
+ return newInstance ( context , self , "ObjectId" , args );
883
883
}
884
884
885
885
@ JRubyMethod (name ="UTCTime" , module =true , rest =true )
886
- public static IRubyObject fact_UTCTime (IRubyObject self , IRubyObject [] args ) {
887
- return callClassNew ( self , "UTCTime" , args );
886
+ public static IRubyObject fact_UTCTime (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
887
+ return newInstance ( context , self , "UTCTime" , args );
888
888
}
889
889
890
890
@ JRubyMethod (name ="GeneralizedTime" , module =true , rest =true )
891
- public static IRubyObject fact_GeneralizedTime (IRubyObject self , IRubyObject [] args ) {
892
- return callClassNew ( self , "GeneralizedTime" , args );
891
+ public static IRubyObject fact_GeneralizedTime (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
892
+ return newInstance ( context , self , "GeneralizedTime" , args );
893
893
}
894
894
895
895
@ JRubyMethod (name ="Sequence" , module =true , rest =true )
896
- public static IRubyObject fact_Sequence (IRubyObject self , IRubyObject [] args ) {
897
- return callClassNew ( self , "Sequence" , args );
896
+ public static IRubyObject fact_Sequence (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
897
+ return newInstance ( context , self , "Sequence" , args );
898
898
}
899
899
900
900
@ JRubyMethod (name ="Set" , module =true , rest =true )
901
- public static IRubyObject fact_Set (IRubyObject self , IRubyObject [] args ) {
902
- return callClassNew ( self , "Set" , args );
901
+ public static IRubyObject fact_Set (ThreadContext context , IRubyObject self , IRubyObject [] args ) {
902
+ return newInstance ( context , self , "Set" , args );
903
903
}
904
904
905
- private static IRubyObject callClassNew (final IRubyObject self , final String className , final IRubyObject [] args ) {
906
- return ((RubyModule ) self ).getClass (className ).callMethod (self .getRuntime ().getCurrentContext (), "new" , args );
905
+ private static IRubyObject newInstance (final ThreadContext context , final IRubyObject parent ,
906
+ final String className , final IRubyObject [] args ) {
907
+ return ((RubyModule ) parent ).getClass (className ).newInstance (context , args , Block .NULL_BLOCK );
907
908
}
908
909
909
910
public static class ObjectId {
@@ -964,17 +965,17 @@ static IRubyObject decodeObject(final ThreadContext context,
964
965
965
966
if ( obj instanceof ASN1Integer ) {
966
967
final BN val = BN .newBN (runtime , ((ASN1Integer ) obj ).getValue ());
967
- return ASN1 .getClass ("Integer" ).callMethod (context , "new" , val );
968
+ return ASN1 .getClass ("Integer" ).newInstance (context , val , Block . NULL_BLOCK );
968
969
}
969
970
if ( obj instanceof DERInteger ) {
970
971
final BN val = BN .newBN (runtime , ((DERInteger ) obj ).getValue ());
971
- return ASN1 .getClass ("Integer" ).callMethod (context , "new" , val );
972
+ return ASN1 .getClass ("Integer" ).newInstance (context , val , Block . NULL_BLOCK );
972
973
}
973
974
974
975
if ( obj instanceof DERBitString ) {
975
976
final DERBitString derObj = (DERBitString ) obj ;
976
977
RubyString str = runtime .newString ( new ByteList (derObj .getBytes (), false ) );
977
- IRubyObject bitString = ASN1 .getClass ("BitString" ).callMethod (context , "new" , str );
978
+ IRubyObject bitString = ASN1 .getClass ("BitString" ).newInstance (context , str , Block . NULL_BLOCK );
978
979
bitString .callMethod (context , "unused_bits=" , runtime .newFixnum ( derObj .getPadBits () ));
979
980
return bitString ;
980
981
}
@@ -1016,7 +1017,7 @@ else if ( obj instanceof DERBMPString ) {
1016
1017
}
1017
1018
bytes = ByteList .create (((ASN1String ) obj ).getString ());
1018
1019
}
1019
- return ASN1 .getClass (type ).callMethod (context , "new" , runtime .newString (bytes ));
1020
+ return ASN1 .getClass (type ).newInstance (context , runtime .newString (bytes ), Block . NULL_BLOCK );
1020
1021
}
1021
1022
1022
1023
//if ( obj instanceof DEROctetString ) {
@@ -1028,44 +1029,44 @@ else if ( obj instanceof DERBMPString ) {
1028
1029
final ByteList octets = new ByteList (((ASN1OctetString ) obj ).getOctets (), false );
1029
1030
// NOTE: sometimes MRI does include the tag but it really should not ;( !
1030
1031
//final ByteList octets = new ByteList(((ASN1OctetString) obj).getEncoded(ASN1Encoding.DER), false);
1031
- return ASN1 .getClass ("OctetString" ).callMethod (context , "new" , runtime .newString (octets ));
1032
+ return ASN1 .getClass ("OctetString" ).newInstance (context , runtime .newString (octets ), Block . NULL_BLOCK );
1032
1033
}
1033
1034
1034
1035
if ( obj instanceof ASN1Null ) {
1035
- return ASN1 .getClass ("Null" ).callMethod (context ,"new" , runtime .getNil ());
1036
+ return ASN1 .getClass ("Null" ).newInstance (context , runtime .getNil (), Block . NULL_BLOCK );
1036
1037
}
1037
1038
if ( obj instanceof ASN1Boolean ) {
1038
1039
final boolean val = ((ASN1Boolean ) obj ).isTrue ();
1039
- return ASN1 .getClass ("Boolean" ).callMethod (context , "new" , runtime .newBoolean (val ));
1040
+ return ASN1 .getClass ("Boolean" ).newInstance (context , runtime .newBoolean (val ), Block . NULL_BLOCK );
1040
1041
}
1041
1042
// DERBoolean extends ASN1Boolean only since 1.51 (<= 1.50 the other way around)
1042
1043
if ( obj instanceof DERBoolean ) {
1043
1044
final boolean val = ((DERBoolean ) obj ).isTrue ();
1044
- return ASN1 .getClass ("Boolean" ).callMethod (context , "new" , runtime .newBoolean (val ));
1045
+ return ASN1 .getClass ("Boolean" ).newInstance (context , runtime .newBoolean (val ), Block . NULL_BLOCK );
1045
1046
}
1046
1047
1047
1048
if ( obj instanceof ASN1UTCTime ) {
1048
1049
final Date adjustedTime ;
1049
1050
try { adjustedTime = ((ASN1UTCTime ) obj ).getAdjustedDate (); }
1050
1051
catch (ParseException e ) { throw new IOException (e ); }
1051
1052
final RubyTime time = RubyTime .newTime (runtime , adjustedTime .getTime ());
1052
- return ASN1 .getClass ("UTCTime" ).callMethod (context ,"new" , time );
1053
+ return ASN1 .getClass ("UTCTime" ).newInstance (context , time , Block . NULL_BLOCK );
1053
1054
}
1054
1055
// NOTE: keep for BC versions compatibility ... extends ASN1UTCTime (since BC 1.51)
1055
1056
if ( obj instanceof DERUTCTime ) {
1056
1057
final Date adjustedTime ;
1057
1058
try { adjustedTime = ((DERUTCTime ) obj ).getAdjustedDate (); }
1058
1059
catch (ParseException e ) { throw new IOException (e ); }
1059
1060
final RubyTime time = RubyTime .newTime (runtime , adjustedTime .getTime ());
1060
- return ASN1 .getClass ("UTCTime" ).callMethod (context ,"new" , time );
1061
+ return ASN1 .getClass ("UTCTime" ).newInstance (context , time , Block . NULL_BLOCK );
1061
1062
}
1062
1063
1063
1064
if ( obj instanceof ASN1GeneralizedTime ) {
1064
1065
final Date generalTime ;
1065
1066
try { generalTime = ((ASN1GeneralizedTime ) obj ).getDate (); }
1066
1067
catch (ParseException e ) { throw new IOException (e ); }
1067
1068
final RubyTime time = RubyTime .newTime (runtime , generalTime .getTime ());
1068
- return ASN1 .getClass ("GeneralizedTime" ).callMethod (context ,"new" , time );
1069
+ return ASN1 .getClass ("GeneralizedTime" ).newInstance (context , time , Block . NULL_BLOCK );
1069
1070
}
1070
1071
// NOTE: keep for BC versions compatibility ... extends ASN1GeneralizedTime (since BC 1.51)
1071
1072
if ( obj instanceof DERGeneralizedTime ) {
@@ -1075,18 +1076,18 @@ else if ( obj instanceof DERBMPString ) {
1075
1076
}
1076
1077
catch (ParseException e ) { throw new IOException (e ); }
1077
1078
final RubyTime time = RubyTime .newTime (runtime , generalTime .getTime ());
1078
- return ASN1 .getClass ("GeneralizedTime" ).callMethod (context ,"new" , time );
1079
+ return ASN1 .getClass ("GeneralizedTime" ).newInstance (context , time , Block . NULL_BLOCK );
1079
1080
}
1080
1081
1081
1082
if ( obj instanceof ASN1ObjectIdentifier ) {
1082
1083
final String objId = ((ASN1ObjectIdentifier ) obj ).getId ();
1083
- return ASN1 .getClass ("ObjectId" ).callMethod (context , "new" , runtime .newString (objId ));
1084
+ return ASN1 .getClass ("ObjectId" ).newInstance (context , runtime .newString (objId ), Block . NULL_BLOCK );
1084
1085
}
1085
1086
// ASN1ObjectIdentifier extends DERObjectIdentifier < 1.51
1086
1087
// DERObjectIdentifier extends ASN1ObjectIdentifier = 1.51
1087
1088
if ( obj instanceof DERObjectIdentifier ) {
1088
1089
final String objId = ((DERObjectIdentifier ) obj ).getId ();
1089
- return ASN1 .getClass ("ObjectId" ).callMethod (context , "new" , runtime .newString (objId ));
1090
+ return ASN1 .getClass ("ObjectId" ).newInstance (context , runtime .newString (objId ), Block . NULL_BLOCK );
1090
1091
}
1091
1092
1092
1093
if ( obj instanceof ASN1TaggedObject ) {
@@ -1095,9 +1096,7 @@ else if ( obj instanceof DERBMPString ) {
1095
1096
IRubyObject tag = runtime .newFixnum ( taggedObj .getTagNo () );
1096
1097
IRubyObject tag_class = runtime .newSymbol ("CONTEXT_SPECIFIC" );
1097
1098
final RubyArray valArr = runtime .newArray (val );
1098
- return ASN1 .getClass ("ASN1Data" ).callMethod (context , "new" ,
1099
- new IRubyObject [] { valArr , tag , tag_class }
1100
- );
1099
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1101
1100
}
1102
1101
1103
1102
if ( obj instanceof DERApplicationSpecific ) {
@@ -1107,25 +1106,23 @@ else if ( obj instanceof DERBMPString ) {
1107
1106
final ASN1Sequence sequence = (ASN1Sequence ) appSpecific .getObject (SEQUENCE );
1108
1107
@ SuppressWarnings ("unchecked" )
1109
1108
final RubyArray valArr = decodeObjects (context , ASN1 , sequence .getObjects ());
1110
- return ASN1 .getClass ("ASN1Data" ).callMethod (context , "new" ,
1111
- new IRubyObject [] { valArr , tag , tag_class }
1112
- );
1109
+ return ASN1 .getClass ("ASN1Data" ).newInstance (context , new IRubyObject [] { valArr , tag , tag_class }, Block .NULL_BLOCK );
1113
1110
}
1114
1111
1115
1112
if ( obj instanceof ASN1Sequence ) {
1116
1113
@ SuppressWarnings ("unchecked" )
1117
1114
RubyArray arr = decodeObjects (context , ASN1 , ((ASN1Sequence ) obj ).getObjects ());
1118
- return ASN1 .getClass ("Sequence" ).callMethod (context , "new" , arr );
1115
+ return ASN1 .getClass ("Sequence" ).newInstance (context , arr , Block . NULL_BLOCK );
1119
1116
}
1120
1117
if ( obj instanceof ASN1Set ) {
1121
1118
@ SuppressWarnings ("unchecked" )
1122
1119
RubyArray arr = decodeObjects (context , ASN1 , ((ASN1Set ) obj ).getObjects ());
1123
- return ASN1 .getClass ("Set" ).callMethod (context , "new" , arr );
1120
+ return ASN1 .getClass ("Set" ).newInstance (context , arr , Block . NULL_BLOCK );
1124
1121
}
1125
1122
1126
1123
if ( obj instanceof ASN1Enumerated ) {
1127
1124
final RubyInteger value = RubyBignum .bignorm (runtime , ((ASN1Enumerated ) obj ).getValue ());
1128
- return ASN1 .getClass ("Enumerated" ).callMethod (context , "new" , value );
1125
+ return ASN1 .getClass ("Enumerated" ).newInstance (context , value , Block . NULL_BLOCK );
1129
1126
}
1130
1127
1131
1128
throw new IllegalArgumentException ("unable to decode object: " + obj + " (" + ( obj == null ? "" : obj .getClass ().getName () ) + ")" );
0 commit comments