Skip to content

Commit efbdb42

Browse files
committed
[refactor] rename + cleanup X509Object implementers
1 parent 5810a4d commit efbdb42

File tree

7 files changed

+36
-32
lines changed

7 files changed

+36
-32
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
import static org.jruby.ext.openssl.OpenSSL.debug;
8787
import static org.jruby.ext.openssl.OpenSSL.debugStackTrace;
8888
import static org.jruby.ext.openssl.OpenSSL.warn;
89-
import static org.jruby.ext.openssl.Utils.hasNonNilInstanceVariable;
9089

9190
/**
9291
* @author <a href="mailto:[email protected]">Ola Bini</a>
@@ -974,7 +973,7 @@ else if ( internalContext.cert != null ) {
974973
if (storeCtx.getBySubject(X509Utils.X509_LU_X509, name, s_obj) <= 0) {
975974
break;
976975
}
977-
x = ((Certificate) s_obj[0]).x509;
976+
x = ((Certificate) s_obj[0]).cert;
978977
}
979978
catch (RuntimeException e) {
980979
debugStackTrace(e);

src/main/java/org/jruby/ext/openssl/x509store/CRL.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@
3636
*/
3737
public class CRL extends X509Object {
3838

39-
public /* final */ java.security.cert.CRL crl;
39+
public final java.security.cert.CRL crl;
4040

41-
@Deprecated // not-used
42-
public CRL() { /* */ }
43-
44-
public CRL(X509CRL crl) {
41+
public CRL(java.security.cert.CRL crl) {
4542
this.crl = crl;
4643
}
4744

src/main/java/org/jruby/ext/openssl/x509store/Certificate.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
*/
3535
public class Certificate extends X509Object {
3636

37-
public final X509AuxCertificate x509;
37+
public final X509AuxCertificate cert;
3838

3939
public Certificate(final X509AuxCertificate cert) {
40-
this.x509 = cert;
40+
this.cert = cert;
4141
}
4242

4343
@Override
@@ -47,15 +47,15 @@ public int type() {
4747

4848
@Override
4949
public boolean isName(final Name name) {
50-
return name.equalToCertificateSubject(x509);
50+
return name.equalToCertificateSubject(cert);
5151
}
5252

5353
@Override
5454
public boolean matches(final X509Object other) {
5555
if (other instanceof Certificate) {
5656
final Certificate that = (Certificate) other;
57-
if (X509AuxCertificate.equalSubjects(this.x509, that.x509)) {
58-
return this.x509.hashCode() == that.x509.hashCode();
57+
if (X509AuxCertificate.equalSubjects(this.cert, that.cert)) {
58+
return this.cert.hashCode() == that.cert.hashCode();
5959
};
6060
}
6161
return false;
@@ -65,7 +65,7 @@ public boolean matches(final X509Object other) {
6565
public int compareTo(final X509Object other) {
6666
int cmp = super.compareTo(other);
6767
if (cmp != 0) return cmp;
68-
return x509.equals( ( (Certificate) other ).x509 ) ? 0 : -1;
68+
return cert.equals( ((Certificate) other).cert ) ? 0 : -1;
6969
}
7070

7171
}// X509_OBJECT_CERT

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@
3636
*/
3737
public class PKey extends X509Object {
3838

39-
public /* final */ java.security.PrivateKey pkey;
40-
41-
@Deprecated // not-used
42-
public PKey() { /* no-op */ }
39+
public final java.security.PrivateKey pkey;
4340

4441
public PKey(PrivateKey pkey) {
4542
this.pkey = pkey;
@@ -48,4 +45,19 @@ public PKey(PrivateKey pkey) {
4845
public int type() {
4946
return X509Utils.X509_LU_PKEY;
5047
}
48+
49+
@Override
50+
public boolean isName(final Name nm) {
51+
return false;
52+
}
53+
54+
@Override
55+
public boolean matches(final X509Object other) {
56+
if (other instanceof PKey) {
57+
final PKey that = (PKey) other;
58+
return this.pkey.equals( that.pkey );
59+
}
60+
return false;
61+
}
62+
5163
}// X509_OBJECT_PKEY

src/main/java/org/jruby/ext/openssl/x509store/Store.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public int addCertificate(final X509Certificate cert) {
304304
public int addCRL(final java.security.cert.CRL crl) {
305305
if ( crl == null ) return 0;
306306

307-
final CRL crlObj = new CRL(); crlObj.crl = crl;
307+
final CRL crlObj = new CRL(crl);
308308

309309
final X509Object[] objects = this.objects;
310310
if ( matchedObject(objects, crlObj) ) {
@@ -334,14 +334,14 @@ private synchronized int addObject(final X509Object xObject, final int prevLengt
334334

335335
int idx = length;
336336
if (xObject instanceof Certificate) {
337-
final X500Principal p1 = ((Certificate) xObject).x509.getIssuerX500Principal();
337+
final X500Principal p1 = ((Certificate) xObject).cert.getIssuerX500Principal();
338338
final Name n1 = new Name(p1);
339339

340340
for (idx = 0; idx < objects.length; idx++) {
341341
X509Object xMember = objects[idx];
342342
if (xMember instanceof Certificate) {
343-
X500Principal p2 = ((Certificate) xMember).x509.getIssuerX500Principal();
344-
if(n1.equalTo(p2)) break;
343+
X500Principal p2 = ((Certificate) xMember).cert.getIssuerX500Principal();
344+
if (n1.equalTo(p2)) break;
345345
}
346346
}
347347
}
@@ -438,7 +438,7 @@ public X509Certificate[] getAcceptedIssuers() {
438438
for ( int i = 0; i< objects.length; i++ ) {
439439
final X509Object object = objects[i];
440440
if ( object instanceof Certificate ) {
441-
issuers.add( ( (Certificate) object ).x509 );
441+
issuers.add(( (Certificate) object ).cert);
442442
}
443443
}
444444
return issuers.toArray( new X509Certificate[ issuers.size() ] );

src/main/java/org/jruby/ext/openssl/x509store/StoreContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ else if ( ok != X509Utils.X509_LU_FAIL ) {
150150
}
151151

152152
X509Object obj = s_obj[0];
153-
if ( checkIssued.call(this, x, ((Certificate) obj).x509) != 0 ) {
154-
issuers[0] = ((Certificate) obj).x509;
153+
if ( checkIssued.call(this, x, ((Certificate) obj).cert) != 0 ) {
154+
issuers[0] = ((Certificate) obj).cert;
155155
return 1;
156156
}
157157

@@ -165,7 +165,7 @@ else if ( ok != X509Utils.X509_LU_FAIL ) {
165165
if ( pobj.type() != X509Utils.X509_LU_X509 ) {
166166
return 0;
167167
}
168-
final X509AuxCertificate x509 = ((Certificate) pobj).x509;
168+
final X509AuxCertificate x509 = ((Certificate) pobj).cert;
169169
if ( ! xn.equalTo( x509.getSubjectX500Principal() ) ) {
170170
return 0;
171171
}

src/main/java/org/jruby/ext/openssl/x509store/X509Object.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,11 @@ public static X509Object retrieveMatch(final Collection<? extends X509Object> li
6868
return null;
6969
}
7070

71-
public boolean isName(Name nm) {
72-
return false;
73-
}
71+
public abstract boolean isName(Name nm) ;
7472

75-
public boolean matches(X509Object o) {
76-
return false;
77-
}
73+
public abstract boolean matches(X509Object o) ;
7874

79-
public abstract int type();
75+
public abstract int type() ;
8076

8177
public int compareTo(X509Object other) {
8278
return type() - other.type();

0 commit comments

Comments
 (0)