Commit 28839b70 by Casey Marshall Committed by Andreas Tobler

DummyKeyPairGenerator.java (clone): Removed useless instanceof check.

2004-08-30  Casey Marshall  <csm@gnu.org>

        * 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
parent ce521a9c
2004-08-30 Casey Marshall <csm@gnu.org>
* 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 <mark@klomp.org> 2004-08-29 Mark Wielaard <mark@klomp.org>
* java/util/Arrays.java * java/util/Arrays.java
......
...@@ -51,11 +51,8 @@ final class DummyKeyPairGenerator extends KeyPairGenerator ...@@ -51,11 +51,8 @@ final class DummyKeyPairGenerator extends KeyPairGenerator
public Object clone() throws CloneNotSupportedException public Object clone() throws CloneNotSupportedException
{ {
if (!(kpgSpi instanceof Cloneable))
throw new CloneNotSupportedException();
KeyPairGenerator result = new DummyKeyPairGenerator KeyPairGenerator result = new DummyKeyPairGenerator
((KeyPairGeneratorSpi) kpgSpi.clone(), this.getAlgorithm()); ((KeyPairGeneratorSpi) kpgSpi.clone(), this.getAlgorithm());
result.provider = this.getProvider(); result.provider = this.getProvider();
return result; return result;
} }
......
...@@ -49,11 +49,8 @@ final class DummyMessageDigest extends MessageDigest ...@@ -49,11 +49,8 @@ final class DummyMessageDigest extends MessageDigest
public Object clone() throws CloneNotSupportedException public Object clone() throws CloneNotSupportedException
{ {
if (!(mdSpi instanceof Cloneable))
throw new CloneNotSupportedException();
MessageDigest result = new DummyMessageDigest MessageDigest result = new DummyMessageDigest
((MessageDigestSpi) mdSpi.clone(), this.getAlgorithm()); ((MessageDigestSpi) mdSpi.clone(), this.getAlgorithm());
result.provider = this.getProvider(); result.provider = this.getProvider();
return result; return result;
} }
......
...@@ -49,11 +49,8 @@ final class DummySignature extends Signature ...@@ -49,11 +49,8 @@ final class DummySignature extends Signature
public Object clone() throws CloneNotSupportedException public Object clone() throws CloneNotSupportedException
{ {
if (!(sigSpi instanceof Cloneable))
throw new CloneNotSupportedException();
Signature result = new DummySignature Signature result = new DummySignature
((SignatureSpi) sigSpi.clone(), this.getAlgorithm()); ((SignatureSpi) sigSpi.clone(), this.getAlgorithm());
result.provider = this.getProvider(); result.provider = this.getProvider();
return result; return result;
} }
......
...@@ -102,9 +102,9 @@ public abstract class MessageDigest extends MessageDigestSpi ...@@ -102,9 +102,9 @@ public abstract class MessageDigest extends MessageDigestSpi
/** /**
* Creates a message digest with the specified algorithm name. * Creates a message digest with the specified algorithm name.
* *
* @param algorithm the standard name of the digest algorithm. * @param algorithm the standard name of the digest algorithm.
* See Appendix A in the Java Cryptography Architecture API * See Appendix A in the Java Cryptography Architecture API
* Specification &amp; Reference for information about standard * Specification &amp; Reference for information about standard
* algorithm names. * algorithm names.
*/ */
protected MessageDigest(String algorithm) protected MessageDigest(String algorithm)
...@@ -134,11 +134,11 @@ public abstract class MessageDigest extends MessageDigestSpi ...@@ -134,11 +134,11 @@ public abstract class MessageDigest extends MessageDigestSpi
Provider[] p = Security.getProviders(); Provider[] p = Security.getProviders();
for (int i = 0; i < p.length; i++) for (int i = 0; i < p.length; i++)
{ {
try try
{ {
return getInstance(algorithm, p[i]); return getInstance(algorithm, p[i]);
} }
catch (NoSuchAlgorithmException ignored) {} catch (NoSuchAlgorithmException ignored) {}
} }
throw new NoSuchAlgorithmException(algorithm); throw new NoSuchAlgorithmException(algorithm);
...@@ -206,17 +206,17 @@ public abstract class MessageDigest extends MessageDigestSpi ...@@ -206,17 +206,17 @@ public abstract class MessageDigest extends MessageDigestSpi
} }
catch (java.lang.reflect.InvocationTargetException ite) catch (java.lang.reflect.InvocationTargetException ite)
{ {
throw new NoSuchAlgorithmException(algorithm); throw new NoSuchAlgorithmException(algorithm);
} }
if (o instanceof MessageDigestSpi) if (o instanceof MessageDigestSpi)
{ {
result = new DummyMessageDigest((MessageDigestSpi) o, algorithm); result = new DummyMessageDigest((MessageDigestSpi) o, algorithm);
} }
else if (o instanceof MessageDigest) else if (o instanceof MessageDigest)
{ {
result = (MessageDigest) o; result = (MessageDigest) o;
result.algorithm = algorithm; result.algorithm = algorithm;
} }
else else
{ {
...@@ -335,7 +335,7 @@ public abstract class MessageDigest extends MessageDigestSpi ...@@ -335,7 +335,7 @@ public abstract class MessageDigest extends MessageDigestSpi
for (int i = digesta.length - 1; i >= 0; --i) for (int i = digesta.length - 1; i >= 0; --i)
if (digesta[i] != digestb[i]) if (digesta[i] != digestb[i])
return false; return false;
return true; return true;
} }
...@@ -383,10 +383,7 @@ public abstract class MessageDigest extends MessageDigestSpi ...@@ -383,10 +383,7 @@ public abstract class MessageDigest extends MessageDigestSpi
*/ */
public Object clone() throws CloneNotSupportedException public Object clone() throws CloneNotSupportedException
{ {
if (this instanceof Cloneable) return super.clone();
return super.clone();
else
throw new CloneNotSupportedException();
} }
private String digestToString() private String digestToString()
...@@ -400,12 +397,12 @@ public abstract class MessageDigest extends MessageDigestSpi ...@@ -400,12 +397,12 @@ public abstract class MessageDigest extends MessageDigestSpi
int len = digest.length; int len = digest.length;
for (int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
byte b = digest[i]; byte b = digest[i];
byte high = (byte) ((b & 0xff) >>> 4); byte high = (byte) ((b & 0xff) >>> 4);
byte low = (byte) (b & 0xf); byte low = (byte) (b & 0xf);
buf.append(high > 9 ? ('a' - 10) + high : '0' + high); buf.append(high > 9 ? ('a' - 10) + high : '0' + high);
buf.append(low > 9 ? ('a' - 10) + low : '0' + low); buf.append(low > 9 ? ('a' - 10) + low : '0' + low);
} }
return buf.toString(); return buf.toString();
......
...@@ -40,15 +40,15 @@ package java.security; ...@@ -40,15 +40,15 @@ package java.security;
/** /**
This is the Service Provider Interface (SPI) for MessageDigest This is the Service Provider Interface (SPI) for MessageDigest
class in java.security. It provides the back end functionality 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 hashes. The default hashes are SHA-1 and MD5. A message hash
takes data of arbitrary length and produces a unique number takes data of arbitrary length and produces a unique number
representing it. representing it.
Cryptography service providers who want to implement their Cryptography service providers who want to implement their
own message digest hashes need only to subclass this class. 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. the programmer of a subclass.
@version 0.0 @version 0.0
...@@ -135,7 +135,7 @@ public abstract class MessageDigestSpi ...@@ -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. and clears sensitive data.
*/ */
protected abstract void engineReset(); protected abstract void engineReset();
...@@ -150,9 +150,6 @@ public abstract class MessageDigestSpi ...@@ -150,9 +150,6 @@ public abstract class MessageDigestSpi
*/ */
public Object clone() throws CloneNotSupportedException public Object clone() throws CloneNotSupportedException
{ {
if (this instanceof Cloneable) return super.clone();
return super.clone();
else
throw new CloneNotSupportedException();
} }
} }
...@@ -206,7 +206,7 @@ public abstract class Signature extends SignatureSpi ...@@ -206,7 +206,7 @@ public abstract class Signature extends SignatureSpi
{ {
if (provider == null || provider.length() == 0) if (provider == null || provider.length() == 0)
throw new IllegalArgumentException("Illegal provider"); throw new IllegalArgumentException("Illegal provider");
Provider p = Security.getProvider(provider); Provider p = Security.getProvider(provider);
if (p == null) if (p == null)
throw new NoSuchProviderException(provider); throw new NoSuchProviderException(provider);
...@@ -251,16 +251,16 @@ public abstract class Signature extends SignatureSpi ...@@ -251,16 +251,16 @@ public abstract class Signature extends SignatureSpi
if (o instanceof SignatureSpi) if (o instanceof SignatureSpi)
{ {
result = new DummySignature((SignatureSpi) o, algorithm); result = new DummySignature((SignatureSpi) o, algorithm);
} }
else if (o instanceof Signature) else if (o instanceof Signature)
{ {
result = (Signature) o; result = (Signature) o;
result.algorithm = algorithm; result.algorithm = algorithm;
} }
else else
{ {
throw new NoSuchAlgorithmException(algorithm); throw new NoSuchAlgorithmException(algorithm);
} }
result.provider = provider; result.provider = provider;
return result; return result;
...@@ -313,9 +313,9 @@ public abstract class Signature extends SignatureSpi ...@@ -313,9 +313,9 @@ public abstract class Signature extends SignatureSpi
if (certificate.getType().equals("X509")) if (certificate.getType().equals("X509"))
{ {
X509Certificate cert = (X509Certificate) certificate; X509Certificate cert = (X509Certificate) certificate;
boolean[]array = cert.getKeyUsage(); boolean[]array = cert.getKeyUsage();
if (array != null && array[0] == false) if (array != null && array[0] == false)
throw new InvalidKeyException( throw new InvalidKeyException(
"KeyUsage of this Certificate indicates it cannot be used for digital signing"); "KeyUsage of this Certificate indicates it cannot be used for digital signing");
} }
this.initVerify(certificate.getPublicKey()); this.initVerify(certificate.getPublicKey());
...@@ -627,6 +627,6 @@ public abstract class Signature extends SignatureSpi ...@@ -627,6 +627,6 @@ public abstract class Signature extends SignatureSpi
*/ */
public Object clone() throws CloneNotSupportedException public Object clone() throws CloneNotSupportedException
{ {
throw new CloneNotSupportedException(); return super.clone();
} }
} }
...@@ -263,7 +263,7 @@ public abstract class SignatureSpi ...@@ -263,7 +263,7 @@ public abstract class SignatureSpi
*/ */
protected AlgorithmParameters engineGetParameters() protected AlgorithmParameters engineGetParameters()
{ {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/** /**
...@@ -297,6 +297,6 @@ public abstract class SignatureSpi ...@@ -297,6 +297,6 @@ public abstract class SignatureSpi
*/ */
public Object clone() throws CloneNotSupportedException public Object clone() throws CloneNotSupportedException
{ {
throw new CloneNotSupportedException(); return super.clone();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment