Skip to content

Commit dd3e170

Browse files
committed
Replace methods removed in BC 1.75
Several methods and classes were deprecated in BC 1.70 and many of those in the org.bouncycastle.asn1.* were removed in 1.75. This commit moves away from removed method and classes so BouncyCastle can be updated to 1.76.
1 parent 1913525 commit dd3e170

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/main/java/org/jruby/ext/openssl/ASN1.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,24 +1072,23 @@ 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 ) {
1086-
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);
1092-
}
1075+
if (obj instanceof ASN1TaggedObject) {
1076+
final ASN1TaggedObject taggedObj = (ASN1TaggedObject) obj;
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+
}
1091+
}
10931092

10941093
if ( obj instanceof ASN1Sequence ) {
10951094
@SuppressWarnings("unchecked")
@@ -1696,13 +1695,13 @@ ASN1Encodable toASN1(final ThreadContext context) {
16961695
}
16971696

16981697
if ( type == DERGeneralString.class ) {
1699-
return DERGeneralString.getInstance( val.asString().getBytes() );
1698+
return new DERGeneralString( val.asString().toString() );
17001699
}
17011700
if ( type == DERVisibleString.class ) {
1702-
return DERVisibleString.getInstance( val.asString().getBytes() );
1701+
return new DERVisibleString( val.asString().toString() );
17031702
}
17041703
if ( type == DERNumericString.class ) {
1705-
return DERNumericString.getInstance( val.asString().getBytes() );
1704+
return new DERNumericString( val.asString().toString() );
17061705
}
17071706

17081707
if ( val instanceof RubyString ) {

src/main/java/org/jruby/ext/openssl/X509Extension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.bouncycastle.asn1.ASN1EncodableVector;
3939
import org.bouncycastle.asn1.ASN1Encoding;
4040
import org.bouncycastle.asn1.ASN1Integer;
41+
import org.bouncycastle.asn1.ASN1IA5String;
4142
import org.bouncycastle.asn1.ASN1Object;
4243
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
4344
import org.bouncycastle.asn1.ASN1OctetString;
@@ -46,7 +47,6 @@
4647
import org.bouncycastle.asn1.ASN1String;
4748
import org.bouncycastle.asn1.ASN1TaggedObject;
4849
import org.bouncycastle.asn1.BERTags;
49-
import org.bouncycastle.asn1.DERIA5String;
5050
import org.bouncycastle.asn1.DEROctetString;
5151
import org.bouncycastle.asn1.DERUniversalString;
5252
import org.bouncycastle.asn1.DLSequence;
@@ -620,7 +620,7 @@ private static boolean formatGeneralName(final GeneralName name, final ByteList
620620
case GeneralName.uniformResourceIdentifier:
621621
if ( ! tagged ) out.append('U').append('R').append('I').
622622
append(':');
623-
val = DERIA5String.getInstance(obj).getString();
623+
val = ASN1IA5String.getInstance(obj).getString();
624624
out.append( ByteList.plain(val) );
625625
break;
626626
case GeneralName.directoryName:

src/main/java/org/jruby/ext/openssl/impl/PKey.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import org.bouncycastle.asn1.DLSequence;
6868
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
6969
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
70-
import org.bouncycastle.asn1.sec.ECPrivateKeyStructure;
7170
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
7271
import org.bouncycastle.asn1.x509.DSAParameter;
7372
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;

0 commit comments

Comments
 (0)