summaryrefslogtreecommitdiff
path: root/gnu/java/security/sig/BaseSignature.java
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-06-24 00:09:26 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-06-24 00:09:26 +0000
commitc6a7fb5cb0459d9cfdb13834868c4b3c87fa7b7e (patch)
tree25d8bec8afc47cbf7f95d62517939fbbf1383a87 /gnu/java/security/sig/BaseSignature.java
parent6c181a1fd8daf166b48fa352fb3d8963d182c3d5 (diff)
downloadclasspath-c6a7fb5cb0459d9cfdb13834868c4b3c87fa7b7e.tar.gz
2006-06-24 Raif S. Naffah <raif@swiftdsl.com.au>
* gnu/java/security/util/Util.java: Source formatting. * gnu/java/security/util/SimpleList.java: Likewise. * gnu/java/security/util/Sequence.java: Likewise. * gnu/java/security/util/PRNG.java: Likewise. * gnu/java/security/util/ExpirableObject.java: Likewise. * gnu/java/security/util/Base64.java: Likewise. * gnu/java/security/sig/SignatureFactory.java: Likewise. * gnu/java/security/sig/ISignatureCodec.java: Likewise. * gnu/java/security/sig/ISignature.java: Likewise. * gnu/java/security/sig/BaseSignature.java: Likewise. * gnu/java/security/sig/rsa/RSAPSSSignatureRawCodec.java: Likewise. * gnu/java/security/sig/rsa/RSAPSSSignature.java: Likewise. * gnu/java/security/sig/rsa/RSAPKCS1V1_5Signature.java: Likewise. * gnu/java/security/sig/rsa/RSA.java: Likewise. * gnu/java/security/sig/rsa/EMSA_PSS.java: Likewise. * gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java: Likewise. * gnu/java/security/sig/rsa/EME_PKCS1_V1_5.java: Likewise. * gnu/java/security/sig/dss/DSSSignatureRawCodec.java: Likewise. * gnu/java/security/sig/dss/DSSSignature.java: Likewise. * gnu/java/security/provider/X509CertificateFactory.java: Likewise. * gnu/java/security/provider/PKIXCertPathValidatorImpl.java: Likewise. * gnu/java/security/provider/Gnu.java: Likewise. * gnu/java/security/prng/RandomEventListener.java: Likewise. * gnu/java/security/prng/RandomEvent.java: Likewise. * gnu/java/security/prng/PRNGFactory.java: Likewise. * gnu/java/security/prng/MDGenerator.java: Likewise. * gnu/java/security/prng/LimitReachedException.java: Likewise. * gnu/java/security/prng/IRandom.java: Likewise. * gnu/java/security/prng/EntropySource.java: Likewise. * gnu/java/security/prng/BasePRNG.java: Likewise.
Diffstat (limited to 'gnu/java/security/sig/BaseSignature.java')
-rw-r--r--gnu/java/security/sig/BaseSignature.java98
1 files changed, 28 insertions, 70 deletions
diff --git a/gnu/java/security/sig/BaseSignature.java b/gnu/java/security/sig/BaseSignature.java
index dd964d481..9c76cacba 100644
--- a/gnu/java/security/sig/BaseSignature.java
+++ b/gnu/java/security/sig/BaseSignature.java
@@ -49,15 +49,11 @@ import java.util.Map;
import java.util.Random;
/**
- * <p>A base abstract class to facilitate implementations of concrete
- * Signatures.</p>
+ * A base abstract class to facilitate implementations of concrete Signatures.
*/
-public abstract class BaseSignature implements ISignature
+public abstract class BaseSignature
+ implements ISignature
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The canonical name of this signature scheme. */
protected String schemeName;
@@ -79,9 +75,6 @@ public abstract class BaseSignature implements ISignature
/** Our default source of randomness. */
private PRNG prng = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Trivial constructor.
*
@@ -101,14 +94,6 @@ public abstract class BaseSignature implements ISignature
this.md = md;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // gnu.crypto.sig.ISignature interface implementation ----------------------
-
public String name()
{
return schemeName + "-" + md.name();
@@ -117,51 +102,41 @@ public abstract class BaseSignature implements ISignature
public void setupVerify(Map attributes) throws IllegalArgumentException
{
setup(attributes);
-
// do we have a public key?
PublicKey key = (PublicKey) attributes.get(VERIFIER_KEY);
if (key != null)
- {
- setupForVerification(key);
- }
+ setupForVerification(key);
}
public void setupSign(Map attributes) throws IllegalArgumentException
{
setup(attributes);
-
// do we have a private key?
PrivateKey key = (PrivateKey) attributes.get(SIGNER_KEY);
if (key != null)
- {
- setupForSigning(key);
- }
+ setupForSigning(key);
}
public void update(byte b)
{
if (md == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
+
md.update(b);
}
public void update(byte[] b, int off, int len)
{
if (md == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
+
md.update(b, off, len);
}
public Object sign()
{
if (md == null || privateKey == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return generateSignature();
}
@@ -169,15 +144,11 @@ public abstract class BaseSignature implements ISignature
public boolean verify(Object sig)
{
if (md == null || publicKey == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return verifySignature(sig);
}
- // abstract methods to be implemented by concrete subclasses ---------------
-
public abstract Object clone();
protected abstract void setupForVerification(PublicKey key)
@@ -191,8 +162,6 @@ public abstract class BaseSignature implements ISignature
protected abstract boolean verifySignature(Object signature)
throws IllegalStateException;
- // Other instance methods --------------------------------------------------
-
/** Initialises the internal fields of this instance. */
protected void init()
{
@@ -204,33 +173,27 @@ public abstract class BaseSignature implements ISignature
}
/**
- * <p>Fills the designated byte array with random data.</p>
- *
+ * Fills the designated byte array with random data.
+ *
* @param buffer the byte array to fill with random data.
*/
protected void nextRandomBytes(byte[] buffer)
{
if (rnd != null)
- {
- rnd.nextBytes(buffer);
- }
+ rnd.nextBytes(buffer);
else if (irnd != null)
- {
- try
- {
- irnd.nextBytes(buffer, 0, buffer.length);
- }
- catch (IllegalStateException x)
- {
- throw new RuntimeException("nextRandomBytes(): "
- + String.valueOf(x));
- }
- catch (LimitReachedException x)
- {
- throw new RuntimeException("nextRandomBytes(): "
- + String.valueOf(x));
- }
- }
+ try
+ {
+ irnd.nextBytes(buffer, 0, buffer.length);
+ }
+ catch (IllegalStateException x)
+ {
+ throw new RuntimeException("nextRandomBytes(): " + x);
+ }
+ catch (LimitReachedException x)
+ {
+ throw new RuntimeException("nextRandomBytes(): " + x);
+ }
else
getDefaultPRNG().nextBytes(buffer);
}
@@ -238,17 +201,12 @@ public abstract class BaseSignature implements ISignature
private void setup(Map attributes)
{
init();
-
// do we have a Random or SecureRandom, or should we use our own?
Object obj = attributes.get(SOURCE_OF_RANDOMNESS);
if (obj instanceof Random)
- {
- rnd = (Random) obj;
- }
+ rnd = (Random) obj;
else if (obj instanceof IRandom)
- {
- irnd = (IRandom) obj;
- }
+ irnd = (IRandom) obj;
}
private PRNG getDefaultPRNG()