summaryrefslogtreecommitdiff
path: root/gnu/java/security/sig/BaseSignature.java
diff options
context:
space:
mode:
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()