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
This commit is contained in:
Casey Marshall 2004-08-30 10:25:38 +00:00 committed by Andreas Tobler
parent ce521a9c85
commit 28839b70d0
8 changed files with 52 additions and 54 deletions

View file

@ -1,3 +1,16 @@
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>
* java/util/Arrays.java

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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 &amp; Reference for information about standard
* @param algorithm the standard name of the digest algorithm.
* See Appendix A in the Java Cryptography Architecture API
* Specification &amp; 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();

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}