Skip to content

Commit 9c7828f

Browse files
committed
avoid some deprecations (and compiler warnings/noise)
1 parent 5c821ae commit 9c7828f

File tree

6 files changed

+42
-48
lines changed

6 files changed

+42
-48
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Map;
4040
import java.util.WeakHashMap;
4141

42+
import org.bouncycastle.asn1.ASN1Boolean;
4243
import org.bouncycastle.asn1.ASN1Encodable;
4344
import org.bouncycastle.asn1.ASN1EncodableVector;
4445
import org.bouncycastle.asn1.ASN1Encoding;
@@ -50,6 +51,7 @@
5051
import org.bouncycastle.asn1.DERBitString;
5152
import org.bouncycastle.asn1.DERBoolean;
5253
import org.bouncycastle.asn1.ASN1Integer;
54+
import org.bouncycastle.asn1.ASN1Null;
5355
import org.bouncycastle.asn1.ASN1TaggedObject;
5456
import org.bouncycastle.asn1.DERNull;
5557
import org.bouncycastle.asn1.DEROctetString;
@@ -1117,11 +1119,11 @@ ASN1Encodable toASN1(final ThreadContext context) {
11171119
if ( impl == ASN1ObjectIdentifier.class ) {
11181120
return getObjectIdentifier(context.runtime, val.toString());
11191121
}
1120-
else if ( impl == DERNull.class ) {
1121-
return new DERNull();
1122+
else if ( impl == DERNull.class || impl == ASN1Null.class ) {
1123+
return DERNull.INSTANCE;
11221124
}
1123-
else if ( impl == DERBoolean.class ) {
1124-
return new DERBoolean(val.isTrue());
1125+
else if ( impl == DERBoolean.class || impl == ASN1Boolean.class ) {
1126+
return ASN1Boolean.getInstance(val.isTrue());
11251127
}
11261128
else if ( impl == DERUTCTime.class ) {
11271129
return new DERUTCTime(((RubyTime) val).getJavaDate());

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ ASN1Primitive toASN1() {
9090
ASN1EncodableVector v1 = new ASN1EncodableVector();
9191
v1.add(getObjectIdentifier(oid.toString()));
9292
if(value instanceof ASN1.ASN1Constructive) {
93-
v1.add(((ASN1.ASN1Constructive)value).toASN1());
93+
final ThreadContext context = getRuntime().getCurrentContext();
94+
v1.add( ((ASN1.ASN1Constructive) value).toASN1(context) );
9495
} else {
96+
final ThreadContext context = getRuntime().getCurrentContext();
9597
ASN1EncodableVector v2 = new ASN1EncodableVector();
96-
v2.add(((ASN1.ASN1Data)value).toASN1());
97-
v1.add(new DERSet(v2));
98+
v2.add( ((ASN1.ASN1Data) value).toASN1(context) );
99+
v1.add( new DERSet(v2) );
98100
}
99101
return new DLSequence(v1);
100102
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
7171
}
7272
};
7373

74-
public static void createCipher(final Ruby runtime, final RubyModule mOSSL) {
75-
RubyClass cCipher = mOSSL.defineClassUnder("Cipher", runtime.getObject(), CIPHER_ALLOCATOR);
76-
cCipher.defineAnnotatedMethods(Cipher.class);
77-
RubyClass openSSLError = mOSSL.getClass("OpenSSLError");
78-
cCipher.defineClassUnder("CipherError", openSSLError, openSSLError.getAllocator());
74+
public static void createCipher(final Ruby runtime, final RubyModule _OpenSSL) {
75+
RubyClass _Cipher = _OpenSSL.defineClassUnder("Cipher", runtime.getObject(), CIPHER_ALLOCATOR);
76+
_Cipher.defineAnnotatedMethods(Cipher.class);
77+
RubyClass _OpenSSLError = _OpenSSL.getClass("OpenSSLError");
78+
_Cipher.defineClassUnder("CipherError", _OpenSSLError, _OpenSSLError.getAllocator());
79+
}
80+
81+
static RubyClass _Cipher(final Ruby runtime) {
82+
return (RubyClass) runtime.getModule("OpenSSL").getConstant("Cipher");
7983
}
8084

8185
public static boolean isSupportedCipher(final String name) {
@@ -815,6 +819,6 @@ private boolean isStreamCipher() {
815819
}
816820

817821
private static RaiseException newCipherError(Ruby runtime, String message) {
818-
return Utils.newError(runtime, "OpenSSL::Cipher::CipherError", message);
822+
return Utils.newError(runtime, _Cipher(runtime).getClass("CipherError"), message);
819823
}
820824
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,22 @@ public static PEMHandler getPEMHandler() {
117117
return new BouncyCastlePEMHandler();
118118
}
119119
catch (Exception e) {
120-
if ( isDebug() ) e.printStackTrace();
120+
if ( isDebug() ) e.printStackTrace(System.out);
121121
}
122122
return new DefaultPEMHandler();
123123
}
124124

125125
static KeyAndIv EVP_BytesToKey(int key_len, int iv_len, MessageDigest md, byte[] salt, byte[] data, int count) {
126-
byte[] key = new byte[key_len];
127-
byte[] iv = new byte[iv_len];
126+
final byte[] key = new byte[key_len]; final byte[] iv = new byte[iv_len];
127+
128+
if( data == null ) return new KeyAndIvImpl(key, iv);
129+
128130
int key_ix = 0;
129131
int iv_ix = 0;
130132
byte[] md_buf = null;
131133
int nkey = key_len;
132134
int niv = iv_len;
133-
int i = 0;
134-
if(data == null) {
135-
return new KeyAndIvImpl(key,iv);
136-
}
135+
int i;
137136
int addmd = 0;
138137
for(;;) {
139138
md.reset();
@@ -173,9 +172,9 @@ static KeyAndIv EVP_BytesToKey(int key_len, int iv_len, MessageDigest md, byte[]
173172
break;
174173
}
175174
}
176-
for(i=0;i<md_buf.length;i++) {
177-
md_buf[i] = 0;
178-
}
175+
//for(i=0;i<md_buf.length;i++) {
176+
// md_buf[i] = 0;
177+
//}
179178
return new KeyAndIvImpl(key,iv);
180179
}
181180
}// OpenSSLImpl

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public SSLContext(Ruby runtime, RubyClass type) {
171171
}
172172

173173
public static RaiseException newSSLError(Ruby runtime, String message) {
174-
return Utils.newError(runtime, "OpenSSL::SSL::SSLError", message, false);
174+
final RubyModule _SSL = (RubyModule) runtime.getModule("OpenSSL").getConstant("SSL");
175+
return Utils.newError(runtime, _SSL.getClass("SSLError"), message, false);
175176
}
176177

177178
private String ciphers = CipherStrings.SSL_DEFAULT_CIPHER_LIST;
@@ -483,20 +484,14 @@ private String[] getEnabledProtocols(final SSLEngine engine) {
483484
}
484485

485486
private String sslVersionString(long bits) {
486-
StringBuilder sb = new StringBuilder();
487+
StringBuilder sb = new StringBuilder(17);
487488
boolean first = true;
488-
if ((bits & CipherStrings.SSL_SSLV3) != 0) {
489-
if (!first) {
490-
sb.append("/");
491-
}
492-
first = false;
489+
if ( ( bits & CipherStrings.SSL_SSLV3 ) != 0 ) {
490+
if ( ! first ) sb.append('/'); first = false;
493491
sb.append("TLSv1/SSLv3");
494492
}
495-
if ((bits & CipherStrings.SSL_SSLV2) != 0) {
496-
if (!first) {
497-
sb.append("/");
498-
}
499-
first = false;
493+
if ( ( bits & CipherStrings.SSL_SSLV2 ) != 0 ) {
494+
if ( ! first ) sb.append('/'); // first = false;
500495
sb.append("SSLv2");
501496
}
502497
return sb.toString();

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void signatureVerify(BIO bio, SignerInfoWithPkey si, X509AuxCertificate x
309309
throw e;
310310
} catch(Exception e) {
311311
System.err.println("Other exception");
312-
e.printStackTrace();
312+
e.printStackTrace(System.err);
313313
throw new NotVerifiedPKCS7Exception();
314314
}
315315
}
@@ -372,7 +372,7 @@ public void verify(Collection<X509AuxCertificate> certs, Store store, BIO indata
372372

373373
BIO tmpin = indata;
374374
BIO p7bio = dataInit(tmpin);
375-
BIO tmpout = null;
375+
BIO tmpout;
376376
if((flags & TEXT) != 0) {
377377
tmpout = BIO.mem();
378378
} else {
@@ -627,7 +627,7 @@ public Collection<SignerInfoWithPkey> getSignerInfo() {
627627
public static PKCS7 readPEM(BIO input) throws PKCS7Exception {
628628
try {
629629
byte[] buffer = new byte[SMIME.MAX_SMLEN];
630-
int read = -1;
630+
int read;
631631
read = input.gets(buffer, SMIME.MAX_SMLEN);
632632
if(read > PEM_STRING_PKCS7_START.length) {
633633
byte[] tmp = new byte[PEM_STRING_PKCS7_START.length];
@@ -650,7 +650,7 @@ public static PKCS7 readPEM(BIO input) throws PKCS7Exception {
650650
*/
651651
public BIO bioAddDigest(BIO pbio, AlgorithmIdentifier alg) throws PKCS7Exception {
652652
try {
653-
MessageDigest md = EVP.getDigest(alg.getObjectId());
653+
MessageDigest md = EVP.getDigest(alg.getAlgorithm());
654654
BIO btmp = BIO.mdFilter(md);
655655
if(pbio == null) {
656656
return btmp;
@@ -667,10 +667,7 @@ public BIO bioAddDigest(BIO pbio, AlgorithmIdentifier alg) throws PKCS7Exception
667667
*
668668
*/
669669
public BIO dataDecode(PrivateKey pkey, BIO inBio, X509AuxCertificate pcert) throws PKCS7Exception {
670-
BIO out = null;
671-
BIO btmp = null;
672-
BIO etmp = null;
673-
BIO bio = null;
670+
BIO out = null; BIO btmp; BIO etmp; BIO bio;
674671
byte[] dataBody = null;
675672
Collection<AlgorithmIdentifier> mdSk = null;
676673
Collection<RecipInfo> rsk = null;
@@ -722,7 +719,6 @@ public BIO dataDecode(PrivateKey pkey, BIO inBio, X509AuxCertificate pcert) thro
722719
} else {
723720
out.push(btmp);
724721
}
725-
btmp = null;
726722
} catch(Exception e) {
727723
e.printStackTrace(System.err);
728724
throw new PKCS7Exception(F_PKCS7_DATADECODE, R_UNKNOWN_DIGEST_TYPE, e);
@@ -810,7 +806,6 @@ public BIO dataDecode(PrivateKey pkey, BIO inBio, X509AuxCertificate pcert) thro
810806
} else {
811807
out.push(etmp);
812808
}
813-
etmp = null;
814809
}
815810

816811
if(isDetached() || inBio != null) {
@@ -823,7 +818,6 @@ public BIO dataDecode(PrivateKey pkey, BIO inBio, X509AuxCertificate pcert) thro
823818
}
824819
}
825820
out.push(bio);
826-
bio = null;
827821
return out;
828822
}
829823

@@ -923,7 +917,6 @@ public BIO dataInit(BIO bio) throws PKCS7Exception {
923917
} else {
924918
out.push(btmp);
925919
}
926-
btmp = null;
927920
}
928921

929922
if (bio == null) {
@@ -943,7 +936,6 @@ public BIO dataInit(BIO bio) throws PKCS7Exception {
943936
} else {
944937
out = bio;
945938
}
946-
bio = null;
947939
return out;
948940
}
949941

0 commit comments

Comments
 (0)