< prev index next >
src/share/classes/sun/security/pkcs11/P11Key.java
Print this page
rev 1387 : 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
Reviewed-by: xuelei, mullan
Contributed-by: alexandre.boulgakov@oracle.com
@@ -127,11 +127,11 @@
}
// see JCA spec
public final byte[] getEncoded() {
byte[] b = getEncodedInternal();
- return (b == null) ? null : (byte[])b.clone();
+ return (b == null) ? null : b.clone();
}
abstract byte[] getEncodedInternal();
public boolean equals(Object obj) {
@@ -302,20 +302,20 @@
}
// we assume that all components of public keys are always accessible
static PublicKey publicKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
- if (algorithm.equals("RSA")) {
+ if ("RSA".equals(algorithm)) {
return new P11RSAPublicKey
(session, keyID, algorithm, keyLength, attributes);
- } else if (algorithm.equals("DSA")) {
+ } else if ("DSA".equals(algorithm)) {
return new P11DSAPublicKey
(session, keyID, algorithm, keyLength, attributes);
- } else if (algorithm.equals("DH")) {
+ } else if ("DH".equals(algorithm)) {
return new P11DHPublicKey
(session, keyID, algorithm, keyLength, attributes);
- } else if (algorithm.equals("EC")) {
+ } else if ("EC".equals(algorithm)) {
return new P11ECPublicKey
(session, keyID, algorithm, keyLength, attributes);
} else {
throw new ProviderException
("Unknown public key algorithm " + algorithm);
@@ -331,11 +331,11 @@
});
if (attributes[1].getBoolean() || (attributes[2].getBoolean() == false)) {
return new P11PrivateKey
(session, keyID, algorithm, keyLength, attributes);
} else {
- if (algorithm.equals("RSA")) {
+ if ("RSA".equals(algorithm)) {
// XXX better test for RSA CRT keys (single getAttributes() call)
// we need to determine whether this is a CRT key
// see if we can obtain the public exponent
// this should also be readable for sensitive/extractable keys
CK_ATTRIBUTE[] attrs2 = new CK_ATTRIBUTE[] {
@@ -355,17 +355,17 @@
(session, keyID, algorithm, keyLength, attributes);
} else {
return new P11RSAPrivateNonCRTKey
(session, keyID, algorithm, keyLength, attributes);
}
- } else if (algorithm.equals("DSA")) {
+ } else if ("DSA".equals(algorithm)) {
return new P11DSAPrivateKey
(session, keyID, algorithm, keyLength, attributes);
- } else if (algorithm.equals("DH")) {
+ } else if ("DH".equals(algorithm)) {
return new P11DHPrivateKey
(session, keyID, algorithm, keyLength, attributes);
- } else if (algorithm.equals("EC")) {
+ } else if ("EC".equals(algorithm)) {
return new P11ECPrivateKey
(session, keyID, algorithm, keyLength, attributes);
} else {
throw new ProviderException
("Unknown private key algorithm " + algorithm);
@@ -374,10 +374,12 @@
}
// class for sensitive and unextractable private keys
private static final class P11PrivateKey extends P11Key
implements PrivateKey {
+ private static final long serialVersionUID = -2138581185214187615L;
+
P11PrivateKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
}
// XXX temporary encoding for serialization purposes
@@ -390,10 +392,11 @@
return null;
}
}
private static class P11SecretKey extends P11Key implements SecretKey {
+ private static final long serialVersionUID = -7828241727014329084L;
private volatile byte[] encoded;
P11SecretKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
super(SECRET, session, keyID, algorithm, keyLength, attributes);
}
@@ -437,10 +440,12 @@
}
}
private static class P11TlsMasterSecretKey extends P11SecretKey
implements TlsMasterSecret {
+ private static final long serialVersionUID = -1318560923770573441L;
+
private final int majorVersion, minorVersion;
P11TlsMasterSecretKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes, int major, int minor) {
super(session, keyID, algorithm, keyLength, attributes);
this.majorVersion = major;
@@ -456,10 +461,12 @@
}
// RSA CRT private key
private static final class P11RSAPrivateKey extends P11Key
implements RSAPrivateCrtKey {
+ private static final long serialVersionUID = 9215872438913515220L;
+
private BigInteger n, e, d, p, q, pe, qe, coeff;
private byte[] encoded;
P11RSAPrivateKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
@@ -545,10 +552,12 @@
}
// RSA non-CRT private key
private static final class P11RSAPrivateNonCRTKey extends P11Key
implements RSAPrivateKey {
+ private static final long serialVersionUID = 1137764983777411481L;
+
private BigInteger n, d;
private byte[] encoded;
P11RSAPrivateNonCRTKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
@@ -597,10 +606,12 @@
}
}
private static final class P11RSAPublicKey extends P11Key
implements RSAPublicKey {
+ private static final long serialVersionUID = -826726289023854455L;
+
private BigInteger n, e;
private byte[] encoded;
P11RSAPublicKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
super(PUBLIC, session, keyID, algorithm, keyLength, attributes);
@@ -649,10 +660,12 @@
}
}
private static final class P11DSAPublicKey extends P11Key
implements DSAPublicKey {
+ private static final long serialVersionUID = 5989753793316396637L;
+
private BigInteger y;
private DSAParams params;
private byte[] encoded;
P11DSAPublicKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
@@ -710,10 +723,12 @@
}
}
private static final class P11DSAPrivateKey extends P11Key
implements DSAPrivateKey {
+ private static final long serialVersionUID = 3119629997181999389L;
+
private BigInteger x;
private DSAParams params;
private byte[] encoded;
P11DSAPrivateKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
@@ -766,10 +781,12 @@
}
}
private static final class P11DHPrivateKey extends P11Key
implements DHPrivateKey {
+ private static final long serialVersionUID = -1698576167364928838L;
+
private BigInteger x;
private DHParameterSpec params;
private byte[] encoded;
P11DHPrivateKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
@@ -823,10 +840,12 @@
}
}
private static final class P11DHPublicKey extends P11Key
implements DHPublicKey {
+ static final long serialVersionUID = -598383872153843657L;
+
private BigInteger y;
private DHParameterSpec params;
private byte[] encoded;
P11DHPublicKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
@@ -885,10 +904,12 @@
}
}
private static final class P11ECPrivateKey extends P11Key
implements ECPrivateKey {
+ private static final long serialVersionUID = -7786054399510515515L;
+
private BigInteger s;
private ECParameterSpec params;
private byte[] encoded;
P11ECPrivateKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
@@ -939,10 +960,12 @@
}
}
private static final class P11ECPublicKey extends P11Key
implements ECPublicKey {
+ private static final long serialVersionUID = -6371481375154806089L;
+
private ECPoint w;
private ECParameterSpec params;
private byte[] encoded;
P11ECPublicKey(Session session, long keyID, String algorithm,
int keyLength, CK_ATTRIBUTE[] attributes) {
< prev index next >