From 28839b70d0fa8703311d39ca2ce1f8a17b8d20d6 Mon Sep 17 00:00:00 2001 From: Casey Marshall Date: Mon, 30 Aug 2004 10:25:38 +0000 Subject: [PATCH] DummyKeyPairGenerator.java (clone): Removed useless instanceof check. 2004-08-30 Casey Marshall * java/security/DummyKeyPairGenerator.java (clone): Removed useless instanceof check. * java/security/DummyMessageDigest.java (clone): Likewise. * java/security/DummySignature.java (clone): Likewise. * java/security/MessageDigest.java (clone): Remove useless instanceof check. * java/security/MessageDigestSpi.java (clone): Likewise. * java/security/Signature.java (clone): Provide meaningful implementation. * java/security/SignatureSpi.java (clone): Likewise. From-SVN: r86755 --- libjava/ChangeLog | 13 ++++++ .../java/security/DummyKeyPairGenerator.java | 5 +-- libjava/java/security/DummyMessageDigest.java | 5 +-- libjava/java/security/DummySignature.java | 5 +-- libjava/java/security/MessageDigest.java | 43 +++++++++---------- libjava/java/security/MessageDigestSpi.java | 13 +++--- libjava/java/security/Signature.java | 18 ++++---- libjava/java/security/SignatureSpi.java | 4 +- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 33a66474af3..cee3e61aef3 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,16 @@ +2004-08-30 Casey Marshall + + * java/security/DummyKeyPairGenerator.java (clone): Removed + useless instanceof check. + * java/security/DummyMessageDigest.java (clone): Likewise. + * java/security/DummySignature.java (clone): Likewise. + * java/security/MessageDigest.java (clone): Remove useless + instanceof check. + * java/security/MessageDigestSpi.java (clone): Likewise. + * java/security/Signature.java (clone): Provide meaningful + implementation. + * java/security/SignatureSpi.java (clone): Likewise. + 2004-08-29 Mark Wielaard * java/util/Arrays.java diff --git a/libjava/java/security/DummyKeyPairGenerator.java b/libjava/java/security/DummyKeyPairGenerator.java index 3a88b86e01b..5d3d914cdcd 100644 --- a/libjava/java/security/DummyKeyPairGenerator.java +++ b/libjava/java/security/DummyKeyPairGenerator.java @@ -51,11 +51,8 @@ final class DummyKeyPairGenerator extends KeyPairGenerator public Object clone() throws CloneNotSupportedException { - if (!(kpgSpi instanceof Cloneable)) - throw new CloneNotSupportedException(); - KeyPairGenerator result = new DummyKeyPairGenerator - ((KeyPairGeneratorSpi) kpgSpi.clone(), this.getAlgorithm()); + ((KeyPairGeneratorSpi) kpgSpi.clone(), this.getAlgorithm()); result.provider = this.getProvider(); return result; } diff --git a/libjava/java/security/DummyMessageDigest.java b/libjava/java/security/DummyMessageDigest.java index d7e769d328e..703884f4b55 100644 --- a/libjava/java/security/DummyMessageDigest.java +++ b/libjava/java/security/DummyMessageDigest.java @@ -49,11 +49,8 @@ final class DummyMessageDigest extends MessageDigest public Object clone() throws CloneNotSupportedException { - if (!(mdSpi instanceof Cloneable)) - throw new CloneNotSupportedException(); - MessageDigest result = new DummyMessageDigest - ((MessageDigestSpi) mdSpi.clone(), this.getAlgorithm()); + ((MessageDigestSpi) mdSpi.clone(), this.getAlgorithm()); result.provider = this.getProvider(); return result; } diff --git a/libjava/java/security/DummySignature.java b/libjava/java/security/DummySignature.java index 850f86d9dbc..2f21cd5897f 100644 --- a/libjava/java/security/DummySignature.java +++ b/libjava/java/security/DummySignature.java @@ -49,11 +49,8 @@ final class DummySignature extends Signature public Object clone() throws CloneNotSupportedException { - if (!(sigSpi instanceof Cloneable)) - throw new CloneNotSupportedException(); - Signature result = new DummySignature - ((SignatureSpi) sigSpi.clone(), this.getAlgorithm()); + ((SignatureSpi) sigSpi.clone(), this.getAlgorithm()); result.provider = this.getProvider(); return result; } diff --git a/libjava/java/security/MessageDigest.java b/libjava/java/security/MessageDigest.java index 47b082a19f4..8e4dfecb5eb 100644 --- a/libjava/java/security/MessageDigest.java +++ b/libjava/java/security/MessageDigest.java @@ -102,9 +102,9 @@ public abstract class MessageDigest extends MessageDigestSpi /** * Creates a message digest with the specified algorithm name. * - * @param algorithm the standard name of the digest algorithm. - * See Appendix A in the Java Cryptography Architecture API - * Specification & Reference for information about standard + * @param algorithm the standard name of the digest algorithm. + * See Appendix A in the Java Cryptography Architecture API + * Specification & Reference for information about standard * algorithm names. */ protected MessageDigest(String algorithm) @@ -134,11 +134,11 @@ public abstract class MessageDigest extends MessageDigestSpi Provider[] p = Security.getProviders(); for (int i = 0; i < p.length; i++) { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException ignored) {} + try + { + return getInstance(algorithm, p[i]); + } + catch (NoSuchAlgorithmException ignored) {} } throw new NoSuchAlgorithmException(algorithm); @@ -206,17 +206,17 @@ public abstract class MessageDigest extends MessageDigestSpi } catch (java.lang.reflect.InvocationTargetException ite) { - throw new NoSuchAlgorithmException(algorithm); + throw new NoSuchAlgorithmException(algorithm); } - + if (o instanceof MessageDigestSpi) { - result = new DummyMessageDigest((MessageDigestSpi) o, algorithm); + result = new DummyMessageDigest((MessageDigestSpi) o, algorithm); } else if (o instanceof MessageDigest) { - result = (MessageDigest) o; - result.algorithm = algorithm; + result = (MessageDigest) o; + result.algorithm = algorithm; } else { @@ -335,7 +335,7 @@ public abstract class MessageDigest extends MessageDigestSpi for (int i = digesta.length - 1; i >= 0; --i) if (digesta[i] != digestb[i]) - return false; + return false; return true; } @@ -383,10 +383,7 @@ public abstract class MessageDigest extends MessageDigestSpi */ public Object clone() throws CloneNotSupportedException { - if (this instanceof Cloneable) - return super.clone(); - else - throw new CloneNotSupportedException(); + return super.clone(); } private String digestToString() @@ -400,12 +397,12 @@ public abstract class MessageDigest extends MessageDigestSpi int len = digest.length; for (int i = 0; i < len; ++i) { - byte b = digest[i]; - byte high = (byte) ((b & 0xff) >>> 4); - byte low = (byte) (b & 0xf); + byte b = digest[i]; + byte high = (byte) ((b & 0xff) >>> 4); + byte low = (byte) (b & 0xf); - buf.append(high > 9 ? ('a' - 10) + high : '0' + high); - buf.append(low > 9 ? ('a' - 10) + low : '0' + low); + buf.append(high > 9 ? ('a' - 10) + high : '0' + high); + buf.append(low > 9 ? ('a' - 10) + low : '0' + low); } return buf.toString(); diff --git a/libjava/java/security/MessageDigestSpi.java b/libjava/java/security/MessageDigestSpi.java index a50e0a085ca..509666c6cfd 100644 --- a/libjava/java/security/MessageDigestSpi.java +++ b/libjava/java/security/MessageDigestSpi.java @@ -40,15 +40,15 @@ package java.security; /** This is the Service Provider Interface (SPI) for MessageDigest class in java.security. It provides the back end functionality - for the MessageDigest class so that it can compute message + for the MessageDigest class so that it can compute message hashes. The default hashes are SHA-1 and MD5. A message hash takes data of arbitrary length and produces a unique number - representing it. + representing it. Cryptography service providers who want to implement their own message digest hashes need only to subclass this class. - The implementation of a Cloneable interface is left to up to + The implementation of a Cloneable interface is left to up to the programmer of a subclass. @version 0.0 @@ -135,7 +135,7 @@ public abstract class MessageDigestSpi } /** - Resets the digest engine. Reinitializes internal variables + Resets the digest engine. Reinitializes internal variables and clears sensitive data. */ protected abstract void engineReset(); @@ -150,9 +150,6 @@ public abstract class MessageDigestSpi */ public Object clone() throws CloneNotSupportedException { - if (this instanceof Cloneable) - return super.clone(); - else - throw new CloneNotSupportedException(); + return super.clone(); } } diff --git a/libjava/java/security/Signature.java b/libjava/java/security/Signature.java index b7979791042..39c41263888 100644 --- a/libjava/java/security/Signature.java +++ b/libjava/java/security/Signature.java @@ -206,7 +206,7 @@ public abstract class Signature extends SignatureSpi { if (provider == null || provider.length() == 0) throw new IllegalArgumentException("Illegal provider"); - + Provider p = Security.getProvider(provider); if (p == null) throw new NoSuchProviderException(provider); @@ -251,16 +251,16 @@ public abstract class Signature extends SignatureSpi if (o instanceof SignatureSpi) { - result = new DummySignature((SignatureSpi) o, algorithm); + result = new DummySignature((SignatureSpi) o, algorithm); } else if (o instanceof Signature) { - result = (Signature) o; - result.algorithm = algorithm; + result = (Signature) o; + result.algorithm = algorithm; } else { - throw new NoSuchAlgorithmException(algorithm); + throw new NoSuchAlgorithmException(algorithm); } result.provider = provider; return result; @@ -313,9 +313,9 @@ public abstract class Signature extends SignatureSpi if (certificate.getType().equals("X509")) { X509Certificate cert = (X509Certificate) certificate; - boolean[]array = cert.getKeyUsage(); - if (array != null && array[0] == false) - throw new InvalidKeyException( + boolean[]array = cert.getKeyUsage(); + if (array != null && array[0] == false) + throw new InvalidKeyException( "KeyUsage of this Certificate indicates it cannot be used for digital signing"); } this.initVerify(certificate.getPublicKey()); @@ -627,6 +627,6 @@ public abstract class Signature extends SignatureSpi */ public Object clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); + return super.clone(); } } diff --git a/libjava/java/security/SignatureSpi.java b/libjava/java/security/SignatureSpi.java index bf2382d8e40..0f95e526e4f 100644 --- a/libjava/java/security/SignatureSpi.java +++ b/libjava/java/security/SignatureSpi.java @@ -263,7 +263,7 @@ public abstract class SignatureSpi */ protected AlgorithmParameters engineGetParameters() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } /** @@ -297,6 +297,6 @@ public abstract class SignatureSpi */ public Object clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); + return super.clone(); } } -- 2.30.2