Skip to content

Commit

Permalink
Replace methods removed in BC 1.75
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justinstoller committed Sep 27, 2023
1 parent 1913525 commit 5b9798b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
24 changes: 13 additions & 11 deletions src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1072,14 +1072,16 @@ else if ( obj instanceof DERBMPString ) {
return ASN1.getClass("ObjectId").newInstance(context, runtime.newString(objId), Block.NULL_BLOCK);
}

if ( obj instanceof ASN1ApplicationSpecific ) { // TODO this will likely break in BC version > 1.71
final ASN1ApplicationSpecific appSpecific = (ASN1ApplicationSpecific) obj;
IRubyObject tag = runtime.newFixnum( appSpecific.getApplicationTag() );
IRubyObject tag_class = runtime.newSymbol("APPLICATION");
final ASN1Sequence sequence = (ASN1Sequence) appSpecific.getObject(SEQUENCE);
@SuppressWarnings("unchecked")
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
if (obj instanceof ASN1TaggedObject) {
final ASN1TaggedObject taggedObj = (ASN1TaggedObject) obj;
if (taggedObj.getTagClass() == BERTags.APPLICATION) {
IRubyObject tag = runtime.newFixnum( taggedObj.getTagNo() );
IRubyObject tag_class = runtime.newSymbol("APPLICATION");
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(true, SEQUENCE);
@SuppressWarnings("unchecked")
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
}
}

if ( obj instanceof ASN1TaggedObject ) {
Expand Down Expand Up @@ -1696,13 +1698,13 @@ ASN1Encodable toASN1(final ThreadContext context) {
}

if ( type == DERGeneralString.class ) {
return DERGeneralString.getInstance( val.asString().getBytes() );
return new DERGeneralString( val.asString().toString() );
}
if ( type == DERVisibleString.class ) {
return DERVisibleString.getInstance( val.asString().getBytes() );
return new DERVisibleString( val.asString().toString() );
}
if ( type == DERNumericString.class ) {
return DERNumericString.getInstance( val.asString().getBytes() );
return new DERNumericString( val.asString().toString() );
}

if ( val instanceof RubyString ) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jruby/ext/openssl/X509Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1IA5String;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
Expand All @@ -46,7 +47,6 @@
import org.bouncycastle.asn1.ASN1String;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.BERTags;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERUniversalString;
import org.bouncycastle.asn1.DLSequence;
Expand Down Expand Up @@ -620,7 +620,7 @@ private static boolean formatGeneralName(final GeneralName name, final ByteList
case GeneralName.uniformResourceIdentifier:
if ( ! tagged ) out.append('U').append('R').append('I').
append(':');
val = DERIA5String.getInstance(obj).getString();
val = ASN1IA5String.getInstance(obj).getString();
out.append( ByteList.plain(val) );
break;
case GeneralName.directoryName:
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jruby/ext/openssl/impl/PKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.bouncycastle.asn1.DLSequence;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.sec.ECPrivateKeyStructure;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.DSAParameter;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
Expand Down

0 comments on commit 5b9798b

Please sign in to comment.