diff options
Diffstat (limited to 'gnu/java/security/key')
-rw-r--r-- | gnu/java/security/key/KeyPairCodecFactory.java | 10 | ||||
-rw-r--r-- | gnu/java/security/key/dss/DSSKey.java | 23 | ||||
-rw-r--r-- | gnu/java/security/key/dss/DSSKeyPairGenerator.java | 10 | ||||
-rw-r--r-- | gnu/java/security/key/dss/DSSKeyPairRawCodec.java | 8 | ||||
-rw-r--r-- | gnu/java/security/key/dss/DSSKeyPairX509Codec.java | 7 | ||||
-rw-r--r-- | gnu/java/security/key/dss/DSSPrivateKey.java | 26 | ||||
-rw-r--r-- | gnu/java/security/key/dss/DSSPublicKey.java | 26 | ||||
-rw-r--r-- | gnu/java/security/key/rsa/GnuRSAKey.java | 21 | ||||
-rw-r--r-- | gnu/java/security/key/rsa/GnuRSAPrivateKey.java | 30 | ||||
-rw-r--r-- | gnu/java/security/key/rsa/GnuRSAPublicKey.java | 26 | ||||
-rw-r--r-- | gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java | 7 | ||||
-rw-r--r-- | gnu/java/security/key/rsa/RSAKeyPairRawCodec.java | 8 |
12 files changed, 168 insertions, 34 deletions
diff --git a/gnu/java/security/key/KeyPairCodecFactory.java b/gnu/java/security/key/KeyPairCodecFactory.java index b4d96e2e2..70d8ea44c 100644 --- a/gnu/java/security/key/KeyPairCodecFactory.java +++ b/gnu/java/security/key/KeyPairCodecFactory.java @@ -1,5 +1,5 @@ /* KeyPairCodecFactory.java -- - Copyright 2001, 2002, 2006, 2014 Free Software Foundation, Inc. + Copyright 2001, 2002, 2006, 2014, 2015 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -154,13 +154,14 @@ public class KeyPairCodecFactory return getX509Codec(name); case Registry.PKCS8_ENCODING_ID: return getPKCS8Codec(name); + default: + return null; } - return null; } /** - * Returns an instance of a keypair codec given a key. + * Returns an instance of a keypair codec, given a key. * * @param key the key to encode. * @return an instance of the keypair codec, or <code>null</code> if none @@ -184,9 +185,10 @@ public class KeyPairCodecFactory return getX509Codec(key); case Registry.PKCS8_ENCODING_ID: return getPKCS8Codec(key); + default: + return null; } - return null; } /** diff --git a/gnu/java/security/key/dss/DSSKey.java b/gnu/java/security/key/dss/DSSKey.java index ed356ef38..e46ec0a72 100644 --- a/gnu/java/security/key/dss/DSSKey.java +++ b/gnu/java/security/key/dss/DSSKey.java @@ -1,5 +1,5 @@ /* DSSKey.java -- - Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014, 2015 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -50,6 +50,7 @@ import java.security.Key; import java.security.interfaces.DSAKey; import java.security.interfaces.DSAParams; import java.security.spec.DSAParameterSpec; +import java.util.Objects; /** * A base asbtract class for both public and private DSS (Digital Signature @@ -128,22 +129,26 @@ public abstract class DSSKey this.g = g; } + @Override public DSAParams getParams() { return new DSAParameterSpec(p, q, g); } + @Override public String getAlgorithm() { return "DSA"; } /** @deprecated see getEncoded(int). */ + @Override @Deprecated public byte[] getEncoded() { return getEncoded(defaultFormat); } + @Override public String getFormat() { return FormatUtil.getEncodingShortName(defaultFormat); @@ -163,6 +168,7 @@ public abstract class DSSKey * @return <code>true</code> if the designated object is of the same type * and value as this one. */ + @Override public boolean equals(Object obj) { if (hasInheritedParameters()) @@ -180,11 +186,24 @@ public abstract class DSSKey && g.equals(that.getParams().getG()); } + /** + * Returns the hash code of the key, computed from its + * parameter values. + * + * @return the hash code. + */ + @Override + public int hashCode() + { + return Objects.hash(p, q, g); + } + + @Override public String toString() { if (str == null) { - String ls = (String) AccessController.doPrivileged(new GetPropertyAction("line.separator")); + String ls = AccessController.doPrivileged(new GetPropertyAction("line.separator")); CPStringBuilder sb = new CPStringBuilder(ls) .append("defaultFormat=").append(defaultFormat).append(",") .append(ls); diff --git a/gnu/java/security/key/dss/DSSKeyPairGenerator.java b/gnu/java/security/key/dss/DSSKeyPairGenerator.java index fe1eeb683..439377d6b 100644 --- a/gnu/java/security/key/dss/DSSKeyPairGenerator.java +++ b/gnu/java/security/key/dss/DSSKeyPairGenerator.java @@ -288,12 +288,9 @@ public class DSSKeyPairGenerator throw new IllegalArgumentException( "Does not provide default parameters for " + L + "-bit modulus length"); - else - { - p = null; - q = null; - g = null; - } + p = null; + q = null; + g = null; } } else @@ -326,7 +323,6 @@ public class DSSKeyPairGenerator { if (p == null) { - System.err.println("Attempting to generate parameters for modulus of length " + L); BigInteger[] params = new FIPS186(L, rnd).generateParameters(); seed = params[FIPS186.DSA_PARAMS_SEED]; counter = params[FIPS186.DSA_PARAMS_COUNTER]; diff --git a/gnu/java/security/key/dss/DSSKeyPairRawCodec.java b/gnu/java/security/key/dss/DSSKeyPairRawCodec.java index 5b93c6b1e..f0dc0d7a3 100644 --- a/gnu/java/security/key/dss/DSSKeyPairRawCodec.java +++ b/gnu/java/security/key/dss/DSSKeyPairRawCodec.java @@ -1,5 +1,6 @@ /* DSSKeyPairRawCodec.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2015 + Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -55,6 +56,7 @@ public class DSSKeyPairRawCodec { // implicit 0-arguments constructor + @Override public int getFormatID() { return RAW_FORMAT; @@ -99,6 +101,7 @@ public class DSSKeyPairRawCodec * (Digital Signature Standard) one. * @see Registry#MAGIC_RAW_DSS_PUBLIC_KEY */ + @Override public byte[] encodePublicKey(PublicKey key) { if (! (key instanceof DSSPublicKey)) @@ -148,6 +151,7 @@ public class DSSKeyPairRawCodec return baos.toByteArray(); } + @Override public PublicKey decodePublicKey(byte[] k) { // magic @@ -241,6 +245,7 @@ public class DSSKeyPairRawCodec * @throws IllegalArgumentException if the designated key is not a DSS * (Digital Signature Standard) one. */ + @Override public byte[] encodePrivateKey(PrivateKey key) { if (! (key instanceof DSSPrivateKey)) @@ -290,6 +295,7 @@ public class DSSKeyPairRawCodec return baos.toByteArray(); } + @Override public PrivateKey decodePrivateKey(byte[] k) { // magic diff --git a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java index 678924851..11bd22ef1 100644 --- a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java +++ b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java @@ -1,5 +1,5 @@ /* DSSKeyPairX509Codec.java -- X.509 Encoding/Decoding handler - Copyright (C) 2006, 2014 Free Software Foundation, Inc. + Copyright (C) 2006, 2014, 2015 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -67,6 +67,7 @@ public class DSSKeyPairX509Codec // implicit 0-arguments constructor + @Override public int getFormatID() { return X509_FORMAT; @@ -116,6 +117,7 @@ public class DSSKeyPairX509Codec * of {@link DSSPublicKey} or if an exception occurs during the * marshalling process. */ + @Override public byte[] encodePublicKey(PublicKey key) { if (! (key instanceof DSSPublicKey)) @@ -179,6 +181,7 @@ public class DSSKeyPairX509Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public byte[] encodePrivateKey(PrivateKey key) { throw new InvalidParameterException("Wrong format for private keys"); @@ -192,6 +195,7 @@ public class DSSKeyPairX509Codec * @throw InvalidParameterException if an exception occurs during the * unmarshalling process. */ + @Override public PublicKey decodePublicKey(byte[] input) { if (input == null) @@ -269,6 +273,7 @@ public class DSSKeyPairX509Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public PrivateKey decodePrivateKey(byte[] input) { throw new InvalidParameterException("Wrong format for private keys"); diff --git a/gnu/java/security/key/dss/DSSPrivateKey.java b/gnu/java/security/key/dss/DSSPrivateKey.java index 4b3ccc72d..134c977ec 100644 --- a/gnu/java/security/key/dss/DSSPrivateKey.java +++ b/gnu/java/security/key/dss/DSSPrivateKey.java @@ -1,5 +1,6 @@ /* DSSPrivateKey.java -- - Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014, 2015 + Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,7 +48,6 @@ import gnu.java.security.key.IKeyPairCodec; import java.math.BigInteger; import java.security.AccessController; -import java.security.PrivateKey; import java.security.interfaces.DSAPrivateKey; /** @@ -57,7 +57,7 @@ import java.security.interfaces.DSAPrivateKey; */ public class DSSPrivateKey extends DSSKey - implements PrivateKey, DSAPrivateKey + implements DSAPrivateKey { private static final long serialVersionUID = -4273348785094844114L; @@ -135,6 +135,7 @@ public class DSSPrivateKey return (DSSPrivateKey) new DSSKeyPairPKCS8Codec().decodePrivateKey(k); } + @Override public BigInteger getX() { return x; @@ -150,6 +151,7 @@ public class DSSPrivateKey * @exception IllegalArgumentException if the format is not supported. * @see DSSKeyPairRawCodec */ + @Override public byte[] getEncoded(int format) { byte[] result; @@ -177,6 +179,7 @@ public class DSSPrivateKey * @return <code>true</code> if the designated object is of the same type * and value as this one. */ + @Override public boolean equals(Object obj) { if (obj == null) @@ -189,11 +192,26 @@ public class DSSPrivateKey return super.equals(that) && x.equals(that.getX()); } + /** + * Provides a hash code for this object using the DSA + * parameter values, mirroring the {@link #equals(Object)} + * implementation. + * + * @return the hash code of this object. + * @see #equals(Object) + */ + @Override + public int hashCode() + { + return 31 * super.hashCode() + x.hashCode(); + } + + @Override public String toString() { if (str == null) { - String ls = (String) AccessController.doPrivileged + String ls = AccessController.doPrivileged (new GetPropertyAction("line.separator")); str = new CPStringBuilder(this.getClass().getName()).append("(") .append(super.toString()).append(",").append(ls) diff --git a/gnu/java/security/key/dss/DSSPublicKey.java b/gnu/java/security/key/dss/DSSPublicKey.java index 0f4c08e78..91031c9e7 100644 --- a/gnu/java/security/key/dss/DSSPublicKey.java +++ b/gnu/java/security/key/dss/DSSPublicKey.java @@ -1,5 +1,6 @@ /* DSSPublicKey.java -- - Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014, 2015 + Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -46,7 +47,6 @@ import gnu.java.security.key.IKeyPairCodec; import java.math.BigInteger; import java.security.AccessController; -import java.security.PublicKey; import java.security.interfaces.DSAPublicKey; /** @@ -56,7 +56,7 @@ import java.security.interfaces.DSAPublicKey; */ public class DSSPublicKey extends DSSKey - implements PublicKey, DSAPublicKey + implements DSAPublicKey { private static final long serialVersionUID = 4662188565230532792L; @@ -134,6 +134,7 @@ public class DSSPublicKey return (DSSPublicKey) new DSSKeyPairX509Codec().decodePublicKey(k); } + @Override public BigInteger getY() { return y; @@ -149,6 +150,7 @@ public class DSSPublicKey * @exception IllegalArgumentException if the format is not supported. * @see DSSKeyPairRawCodec */ + @Override public byte[] getEncoded(int format) { byte[] result; @@ -176,6 +178,7 @@ public class DSSPublicKey * @return <code>true</code> if the designated object is of the same type * and value as this one. */ + @Override public boolean equals(Object obj) { if (obj == null) @@ -188,11 +191,26 @@ public class DSSPublicKey return super.equals(that) && y.equals(that.getY()); } + /** + * Provides a hash code for this object using the DSA + * parameter values, mirroring the {@link #equals(Object)} + * implementation. + * + * @return the hash code of this object. + * @see #equals(Object) + */ + @Override + public int hashCode() + { + return 31 * super.hashCode() + y.hashCode(); + } + + @Override public String toString() { if (str == null) { - String ls = (String) AccessController.doPrivileged + String ls = AccessController.doPrivileged (new GetPropertyAction("line.separator")); str = new CPStringBuilder(this.getClass().getName()).append("(") .append(super.toString()).append(",").append(ls) diff --git a/gnu/java/security/key/rsa/GnuRSAKey.java b/gnu/java/security/key/rsa/GnuRSAKey.java index 543ebdc56..8954f7574 100644 --- a/gnu/java/security/key/rsa/GnuRSAKey.java +++ b/gnu/java/security/key/rsa/GnuRSAKey.java @@ -48,6 +48,7 @@ import java.math.BigInteger; import java.security.AccessController; import java.security.Key; import java.security.interfaces.RSAKey; +import java.util.Objects; /** * A base asbtract class for both public and private RSA keys. @@ -90,22 +91,26 @@ public abstract class GnuRSAKey this.e = e; } + @Override public BigInteger getModulus() { return getN(); } + @Override public String getAlgorithm() { return "RSA"; } /** @deprecated see getEncoded(int). */ + @Override @Deprecated public byte[] getEncoded() { return getEncoded(defaultFormat); } + @Override public String getFormat() { return FormatUtil.getEncodingShortName(defaultFormat); @@ -149,6 +154,7 @@ public abstract class GnuRSAKey * @return <code>true</code> if the designated object is of the same type * and value as this one. */ + @Override public boolean equals(final Object obj) { if (obj == null) @@ -161,11 +167,24 @@ public abstract class GnuRSAKey return n.equals(that.getModulus()); } + /** + * Provides a hash code for this object using the RSA + * modulus. + * + * @return the hash code of this object. + */ + @Override + public int hashCode() + { + return Objects.hash(n); + } + + @Override public String toString() { if (str == null) { - String ls = (String) AccessController.doPrivileged + String ls = AccessController.doPrivileged (new GetPropertyAction("line.separator")); str = new CPStringBuilder(ls) .append("defaultFormat=").append(defaultFormat).append(",").append(ls) diff --git a/gnu/java/security/key/rsa/GnuRSAPrivateKey.java b/gnu/java/security/key/rsa/GnuRSAPrivateKey.java index 379650a81..5bc4dd878 100644 --- a/gnu/java/security/key/rsa/GnuRSAPrivateKey.java +++ b/gnu/java/security/key/rsa/GnuRSAPrivateKey.java @@ -1,5 +1,6 @@ /* GnuRSAPrivateKey.java -- - Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014, 2015 + Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,9 +48,9 @@ import gnu.java.security.key.IKeyPairCodec; import java.math.BigInteger; import java.security.AccessController; -import java.security.PrivateKey; import java.security.interfaces.RSAPrivateCrtKey; import java.security.interfaces.RSAPrivateKey; +import java.util.Objects; /** * An object that embodies an RSA private key. @@ -65,7 +66,7 @@ import java.security.interfaces.RSAPrivateKey; */ public class GnuRSAPrivateKey extends GnuRSAKey - implements PrivateKey, RSAPrivateCrtKey + implements RSAPrivateCrtKey { private static final long serialVersionUID = -2208207842306185913L; @@ -198,31 +199,37 @@ public class GnuRSAPrivateKey return (GnuRSAPrivateKey) new RSAKeyPairPKCS8Codec().decodePrivateKey(k); } + @Override public BigInteger getPrimeP() { return p; } + @Override public BigInteger getPrimeQ() { return q; } + @Override public BigInteger getPrimeExponentP() { return dP; } + @Override public BigInteger getPrimeExponentQ() { return dQ; } + @Override public BigInteger getCrtCoefficient() { return qInv; } + @Override public BigInteger getPrivateExponent() { return d; @@ -239,6 +246,7 @@ public class GnuRSAPrivateKey * @see RSAKeyPairRawCodec * @see RSAKeyPairPKCS8Codec */ + @Override public byte[] getEncoded(int format) { final byte[] result; @@ -265,6 +273,7 @@ public class GnuRSAPrivateKey * @return <code>true</code> if the designated object is of the same type * and value as this one. */ + @Override public boolean equals(final Object obj) { if (obj == null) @@ -287,11 +296,24 @@ public class GnuRSAPrivateKey return false; } + /** + * Provides a hash code for this object using the RSA + * parameter values. + * + * @return the hash code of this object. + */ + @Override + public int hashCode() + { + return Objects.hash(p, q, dP, dQ, qInv); + } + + @Override public String toString() { if (str == null) { - String ls = (String) AccessController.doPrivileged + String ls = AccessController.doPrivileged (new GetPropertyAction("line.separator")); str = new CPStringBuilder(this.getClass().getName()).append("(") .append(super.toString()).append(",").append(ls) diff --git a/gnu/java/security/key/rsa/GnuRSAPublicKey.java b/gnu/java/security/key/rsa/GnuRSAPublicKey.java index b8e1ea5b1..917012ce3 100644 --- a/gnu/java/security/key/rsa/GnuRSAPublicKey.java +++ b/gnu/java/security/key/rsa/GnuRSAPublicKey.java @@ -1,5 +1,6 @@ /* GnuRSAPublicKey.java -- - Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014, 2015 + Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -46,7 +47,6 @@ import gnu.java.security.key.IKeyPairCodec; import java.math.BigInteger; import java.security.AccessController; -import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; /** @@ -63,7 +63,7 @@ import java.security.interfaces.RSAPublicKey; */ public class GnuRSAPublicKey extends GnuRSAKey - implements PublicKey, RSAPublicKey + implements RSAPublicKey { private static final long serialVersionUID = -1206860366945100193L; @@ -137,6 +137,7 @@ public class GnuRSAPublicKey * @throws IllegalArgumentException if the format is not supported. * @see RSAKeyPairRawCodec */ + @Override public byte[] getEncoded(final int format) { final byte[] result; @@ -163,6 +164,7 @@ public class GnuRSAPublicKey * @return <code>true</code> if the designated object is of the same type * and value as this one. */ + @Override public boolean equals(final Object obj) { if (obj == null) @@ -176,11 +178,27 @@ public class GnuRSAPublicKey && getPublicExponent().equals(that.getPublicExponent()); } + /** + * Provides a hash code for this object using the RSA + * modulus and public exponent, matching the comparisons + * used for the {@link #equals(Object)} implementation. + * + * @return the hash code of this object. + * @see #equals(Object) + */ + + @Override + public int hashCode() + { + return 31 * super.hashCode() + getPublicExponent().hashCode(); + } + + @Override public String toString() { if (str == null) { - String ls = (String) AccessController.doPrivileged + String ls = AccessController.doPrivileged (new GetPropertyAction("line.separator")); str = new CPStringBuilder(this.getClass().getName()).append("(") .append(super.toString()).append(",").append(ls) diff --git a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java index ec9874d80..0eece5645 100644 --- a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java +++ b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java @@ -1,5 +1,5 @@ /* RSAKeyPairPKCS8Codec.java -- PKCS#8 Encoding/Decoding handler - Copyright (C) 2006, 2010, 2014 Free Software Foundation, Inc. + Copyright (C) 2006, 2010, 2014, 2015 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -71,6 +71,7 @@ public class RSAKeyPairPKCS8Codec // implicit 0-arguments constructor + @Override public int getFormatID() { return PKCS8_FORMAT; @@ -79,6 +80,7 @@ public class RSAKeyPairPKCS8Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public byte[] encodePublicKey(PublicKey key) { throw new InvalidParameterException("Wrong format for public keys"); @@ -124,6 +126,7 @@ public class RSAKeyPairPKCS8Codec * @throw InvalidParameterException if an error occurs during the marshalling * process. */ + @Override public byte[] encodePrivateKey(PrivateKey key) { if (Configuration.DEBUG) @@ -203,6 +206,7 @@ public class RSAKeyPairPKCS8Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public PublicKey decodePublicKey(byte[] input) { throw new InvalidParameterException("Wrong format for public keys"); @@ -216,6 +220,7 @@ public class RSAKeyPairPKCS8Codec * @throw InvalidParameterException if an exception occurs during the * unmarshalling process. */ + @Override public PrivateKey decodePrivateKey(byte[] input) { if (Configuration.DEBUG) diff --git a/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java b/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java index f088e794e..b3fb95334 100644 --- a/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java +++ b/gnu/java/security/key/rsa/RSAKeyPairRawCodec.java @@ -1,5 +1,6 @@ /* RSAKeyPairRawCodec.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2015 + Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -55,6 +56,7 @@ public class RSAKeyPairRawCodec { // implicit 0-arguments constructor + @Override public int getFormatID() { return RAW_FORMAT; @@ -87,6 +89,7 @@ public class RSAKeyPairRawCodec * @exception IllegalArgumentException if the designated key is not an RSA * one. */ + @Override public byte[] encodePublicKey(PublicKey key) { if (! (key instanceof GnuRSAPublicKey)) @@ -120,6 +123,7 @@ public class RSAKeyPairRawCodec return baos.toByteArray(); } + @Override public PublicKey decodePublicKey(byte[] k) { // magic @@ -194,6 +198,7 @@ public class RSAKeyPairRawCodec * @param key the key to encode. * @return the <i>Raw</i> format encoding of the designated key. */ + @Override public byte[] encodePrivateKey(PrivateKey key) { if (! (key instanceof GnuRSAPrivateKey)) @@ -243,6 +248,7 @@ public class RSAKeyPairRawCodec return baos.toByteArray(); } + @Override public PrivateKey decodePrivateKey(byte[] k) { // magic |