summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/gnu/javax/crypto/assembly
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/javax/crypto/assembly')
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/Assembly.java109
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/Cascade.java203
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/CascadeStage.java22
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/CascadeTransformer.java24
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/DeflateTransformer.java124
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/Direction.java30
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/LoopbackTransformer.java20
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/ModeStage.java33
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/Operation.java32
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/PaddingTransformer.java52
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/Stage.java103
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/Transformer.java194
-rw-r--r--libjava/classpath/gnu/javax/crypto/assembly/TransformerException.java58
13 files changed, 350 insertions, 654 deletions
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/Assembly.java b/libjava/classpath/gnu/javax/crypto/assembly/Assembly.java
index 2d5bba3646e..49770675bbd 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/Assembly.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/Assembly.java
@@ -41,23 +41,19 @@ package gnu.javax.crypto.assembly;
import java.util.Map;
/**
- * <p>An <code>Assembly</code> is a construction consisting of a chain of
+ * An <code>Assembly</code> is a construction consisting of a chain of
* {@link Transformer} elements; each wired in pre- or post- transformation
* mode. This chain is terminated by one <code>LoopbackTransformer</code>
- * element.</p>
- *
- * <p>Once constructed, and correctly initialised, the bulk of the methods
- * available on the <code>Assembly</code> are delegated to the <i>head</i>
- * of the {@link Transformer} chain of the <code>Assembly</code>.</p>
- *
+ * element.
+ * <p>
+ * Once constructed, and correctly initialised, the bulk of the methods
+ * available on the <code>Assembly</code> are delegated to the <i>head</i> of
+ * the {@link Transformer} chain of the <code>Assembly</code>.
+ *
* @see Transformer
*/
public class Assembly
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.assembly.direction";
/** Flag that tells if the instance is initialised or not; and if yes how. */
@@ -66,9 +62,6 @@ public class Assembly
/** The first Transformer in the chain. */
private Transformer head;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Trivial constructor that sets the <i>chain</i> to a
* <code>LoopbackTransformer</code>.
@@ -81,21 +74,15 @@ public class Assembly
head = new LoopbackTransformer();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Adds the designated {@link Transformer} and signals that it should operate
* in pre-processing mode; i.e. it should apply its internal transformation
* algorithm on the input data stream, <b>before</b> it passes that stream to
* the next element in the <i>chain</i>.
- *
+ *
* @param t the {@link Transformer} to add at the head of the current chain.
- * @throws IllegalArgumentException if the designated {@link Transformer}
- * has a non-null tail; i.e. it is already an element of a chain.
+ * @throws IllegalArgumentException if the designated {@link Transformer} has
+ * a non-null tail; i.e. it is already an element of a chain.
*/
public void addPreTransformer(Transformer t)
{
@@ -107,10 +94,10 @@ public class Assembly
* in post-processing mode; i.e. it should apply its internal transformation
* algorithm on the input data stream, <b>after</b> it passes that stream to
* the next element in the <i>chain</i>.
- *
+ *
* @param t the {@link Transformer} to add at the head of the current chain.
- * @throws IllegalArgumentException if the designated {@link Transformer}
- * has a non-null tail; i.e. it is already an element of a chain.
+ * @throws IllegalArgumentException if the designated {@link Transformer} has
+ * a non-null tail; i.e. it is already an element of a chain.
*/
public void addPostTransformer(Transformer t)
{
@@ -120,22 +107,18 @@ public class Assembly
/**
* Initialises the <code>Assembly</code> for operation with specific
* characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the instance is already initialised.
*/
public void init(Map attributes) throws TransformerException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
- {
- flow = Direction.FORWARD;
- }
+ flow = Direction.FORWARD;
attributes.put(Transformer.DIRECTION, flow);
head.init(attributes);
wired = flow;
@@ -155,12 +138,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte b) throws TransformerException
@@ -172,12 +155,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments. All bytes in <code>in</code>, starting from index position
* <code>0</code> are considered.
- *
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte[] in) throws TransformerException
@@ -187,34 +170,32 @@ public class Assembly
/**
* Processes a designated number of bytes from a given byte array.
- *
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
*/
public byte[] update(byte[] in, int offset, int length)
throws TransformerException
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return head.update(in, offset, length);
}
/**
- * Convenience method that calls the method with same name and three
- * arguments using a 0-long byte array.
- *
+ * Convenience method that calls the method with same name and three arguments
+ * using a 0-long byte array.
+ *
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate() throws TransformerException
@@ -226,12 +207,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte b) throws TransformerException
@@ -243,12 +224,12 @@ public class Assembly
* Convenience method that calls the method with same name and three
* arguments. All bytes in <code>in</code>, starting from index position
* <code>0</code> are considered.
- *
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte[] in) throws TransformerException
@@ -257,39 +238,33 @@ public class Assembly
}
/**
- * Processes a designated number of bytes from a given byte array and
- * signals, at the same time, that this is the last <i>push</i> operation for
- * this <code>Assembly</code>.
- *
+ * Processes a designated number of bytes from a given byte array and signals,
+ * at the same time, that this is the last <i>push</i> operation for this
+ * <code>Assembly</code>.
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
- * @throws TransformerException if a transformation-related exception
- * occurs during the operation.
+ * @throws TransformerException if a transformation-related exception occurs
+ * during the operation.
*/
public byte[] lastUpdate(byte[] in, int offset, int length)
throws TransformerException
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
byte[] result = head.lastUpdate(in, offset, length);
reset();
return result;
}
- // helper methods ----------------------------------------------------------
-
private void wireTransformer(Transformer t, Operation mode)
{
if (t.tail != null)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
t.setMode(mode);
t.tail = head;
head = t;
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/Cascade.java b/libjava/classpath/gnu/javax/crypto/assembly/Cascade.java
index 678a7e7308d..f790956a472 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/Cascade.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/Cascade.java
@@ -49,36 +49,31 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>A <i>Cascade</i> Cipher is the concatenation of two or more block ciphers
+ * A <i>Cascade</i> Cipher is the concatenation of two or more block ciphers
* each with independent keys. Plaintext is input to the first stage; the output
- * of stage <code>i</code> is input to stage <code>i + 1</code>; and the output
- * of the last stage is the <i>Cascade</i>'s ciphertext output.</p>
- *
- * <p>In the simplest case, all stages in a <code>Cascade</code> have <i>k</i>-bit
+ * of stage <code>i</code> is input to stage <code>i + 1</code>; and the
+ * output of the last stage is the <i>Cascade</i>'s ciphertext output.
+ * <p>
+ * In the simplest case, all stages in a <code>Cascade</code> have <i>k</i>-bit
* keys, and the stage inputs and outputs are all n-bit quantities. The stage
* ciphers may differ (general cascade of ciphers), or all be identical (cascade
- * of identical ciphers).</p>
- *
- * <p>The term "block ciphers" used above refers to implementations of
- * {@link gnu.crypto.mode.IMode}, including the {@link gnu.crypto.mode.ECB}
- * mode which basically exposes a symmetric-key block cipher algorithm as a
- * <i>Mode</i> of Operations.</p>
- *
- * <p>References:</p>
- *
+ * of identical ciphers).
+ * <p>
+ * The term "block ciphers" used above refers to implementations of
+ * {@link gnu.javax.crypto.mode.IMode}, including the
+ * {@link gnu.javax.crypto.mode.ECB} mode which basically exposes a
+ * symmetric-key block cipher algorithm as a <i>Mode</i> of Operations.
+ * <p>
+ * References:
* <ol>
- * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
- * Applied Cryptography.<br>
- * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
- * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
+ * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
+ * Applied Cryptography.<br>
+ * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
+ * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
* </ol>
*/
public class Cascade
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.cascade.direction";
/** The map of Stages chained in this cascade. */
@@ -93,9 +88,6 @@ public class Cascade
/** The curently set block-size for this instance. */
protected int blockSize;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public Cascade()
{
super();
@@ -106,12 +98,9 @@ public class Cascade
blockSize = 0;
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
* Returns the Least Common Multiple of two integers.
- *
+ *
* @param a the first integer.
* @param b the second integer.
* @return the LCM of <code>abs(a)</code> and <code>abs(b)</code>.
@@ -123,18 +112,15 @@ public class Cascade
return A.multiply(B).divide(A.gcd(B)).abs().intValue();
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Adds to the end of the current chain, a designated {@link Stage}.
- *
+ *
* @param stage the {@link Stage} to append to the chain.
* @return a unique identifier for this stage, within this cascade.
* @throws IllegalStateException if the instance is already initialised.
- * @throws IllegalArgumentException if the designated stage is already in
- * the chain, or it has incompatible characteristics with the current
- * elements already in the chain.
+ * @throws IllegalArgumentException if the designated stage is already in the
+ * chain, or it has incompatible characteristics with the current
+ * elements already in the chain.
*/
public Object append(Stage stage) throws IllegalArgumentException
{
@@ -143,13 +129,13 @@ public class Cascade
/**
* Adds to the begining of the current chain, a designated {@link Stage}.
- *
+ *
* @param stage the {@link Stage} to prepend to the chain.
* @return a unique identifier for this stage, within this cascade.
* @throws IllegalStateException if the instance is already initialised.
- * @throws IllegalArgumentException if the designated stage is already in
- * the chain, or it has incompatible characteristics with the current
- * elements already in the chain.
+ * @throws IllegalArgumentException if the designated stage is already in the
+ * chain, or it has incompatible characteristics with the current
+ * elements already in the chain.
*/
public Object prepend(Stage stage) throws IllegalArgumentException
{
@@ -159,62 +145,49 @@ public class Cascade
/**
* Inserts a {@link Stage} into the current chain, at the specified index
* (zero-based) position.
- *
+ *
* @param stage the {@link Stage} to insert into the chain.
* @return a unique identifier for this stage, within this cascade.
- * @throws IllegalArgumentException if the designated stage is already in
- * the chain, or it has incompatible characteristics with the current
- * elements already in the chain.
+ * @throws IllegalArgumentException if the designated stage is already in the
+ * chain, or it has incompatible characteristics with the current
+ * elements already in the chain.
* @throws IllegalStateException if the instance is already initialised.
* @throws IndexOutOfBoundsException if <code>index</code> is less than
- * <code>0</code> or greater than the current size of this cascade.
+ * <code>0</code> or greater than the current size of this
+ * cascade.
*/
public Object insert(int index, Stage stage) throws IllegalArgumentException,
IndexOutOfBoundsException
{
if (stages.containsValue(stage))
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException();
if (wired != null || stage == null)
- {
- throw new IllegalStateException();
- }
-
+ throw new IllegalStateException();
if (index < 0 || index > size())
- {
- throw new IndexOutOfBoundsException();
- }
-
+ throw new IndexOutOfBoundsException();
// check that there is a non-empty set of common block-sizes
Set set = stage.blockSizes();
if (stages.isEmpty())
{
if (set.isEmpty())
- {
- throw new IllegalArgumentException("1st stage with no block sizes");
- }
+ throw new IllegalArgumentException("1st stage with no block sizes");
}
else
{
Set common = this.blockSizes();
common.retainAll(set);
if (common.isEmpty())
- {
- throw new IllegalArgumentException("no common block sizes found");
- }
+ throw new IllegalArgumentException("no common block sizes found");
}
-
Object result = new Object();
stageKeys.add(index, result);
stages.put(result, stage);
-
return result;
}
/**
* Returns the current number of stages in this chain.
- *
+ *
* @return the current count of stages in this chain.
*/
public int size()
@@ -226,18 +199,16 @@ public class Cascade
* Returns an {@link Iterator} over the stages contained in this instance.
* Each element of this iterator is a concrete implementation of a {@link
* Stage}.
- *
+ *
* @return an {@link Iterator} over the stages contained in this instance.
- * Each element of the returned iterator is a concrete instance of a {@link
- * Stage}.
+ * Each element of the returned iterator is a concrete instance of a
+ * {@link Stage}.
*/
public Iterator stages()
{
LinkedList result = new LinkedList();
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
- {
- result.addLast(stages.get(it.next()));
- }
+ result.addLast(stages.get(it.next()));
return result.listIterator();
}
@@ -245,9 +216,9 @@ public class Cascade
* Returns the {@link Set} of supported block sizes for this
* <code>Cascade</code> that are common to all of its chained stages. Each
* element in the returned {@link Set} is an instance of {@link Integer}.
- *
- * @return a {@link Set} of supported block sizes common to all the stages
- * of the chain.
+ *
+ * @return a {@link Set} of supported block sizes common to all the stages of
+ * the chain.
*/
public Set blockSizes()
{
@@ -255,42 +226,33 @@ public class Cascade
for (Iterator it = stages.values().iterator(); it.hasNext();)
{
Stage aStage = (Stage) it.next();
- if (result == null)
- { // first time
- result = new HashSet(aStage.blockSizes());
- }
+ if (result == null) // first time
+ result = new HashSet(aStage.blockSizes());
else
- {
- result.retainAll(aStage.blockSizes());
- }
+ result.retainAll(aStage.blockSizes());
}
return result == null ? Collections.EMPTY_SET : result;
}
/**
* Initialises the chain for operation with specific characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the chain, or any of its stages, is
- * already initialised.
+ * already initialised.
* @throws InvalidKeyException if the intialisation data provided with the
- * stage is incorrect or causes an invalid key to be generated.
+ * stage is incorrect or causes an invalid key to be generated.
* @see Direction#FORWARD
* @see Direction#REVERSED
*/
public void init(Map attributes) throws InvalidKeyException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
- {
- flow = Direction.FORWARD;
- }
-
+ flow = Direction.FORWARD;
int optimalSize = 0;
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
{
@@ -300,30 +262,25 @@ public class Cascade
Stage stage = (Stage) stages.get(id);
stage.init(attr);
optimalSize = optimalSize == 0 ? stage.currentBlockSize()
- : lcm(optimalSize,
- stage.currentBlockSize());
- }
-
- if (flow == Direction.REVERSED)
- { // reverse order
- Collections.reverse(stageKeys);
+ : lcm(optimalSize,
+ stage.currentBlockSize());
}
+ if (flow == Direction.REVERSED) // reverse order
+ Collections.reverse(stageKeys);
wired = flow;
blockSize = optimalSize;
}
/**
* Returns the currently set block size for the chain.
- *
+ *
* @return the current block size for the chain.
* @throws IllegalStateException if the instance is not initialised.
*/
public int currentBlockSize()
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return blockSize;
}
@@ -334,25 +291,21 @@ public class Cascade
public void reset()
{
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
- {
- ((Stage) stages.get(it.next())).reset();
- }
- if (wired == Direction.REVERSED)
- { // reverse it back
- Collections.reverse(stageKeys);
- }
+ ((Stage) stages.get(it.next())).reset();
+ if (wired == Direction.REVERSED) // reverse it back
+ Collections.reverse(stageKeys);
wired = null;
blockSize = 0;
}
/**
* Processes exactly one block of <i>plaintext</i> (if initialised in the
- * {@link Direction#FORWARD} state) or <i>ciphertext</i> (if initialised in the
- * {@link Direction#REVERSED} state).
- *
+ * {@link Direction#FORWARD} state) or <i>ciphertext</i> (if initialised in
+ * the {@link Direction#REVERSED} state).
+ *
* @param in the plaintext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
* @param outOffset index of <code>out</code> from which to store result.
* @throws IllegalStateException if the instance is not initialised.
@@ -360,23 +313,17 @@ public class Cascade
public void update(byte[] in, int inOffset, byte[] out, int outOffset)
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
int stageBlockSize, j, i = stages.size();
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
{
Stage stage = (Stage) stages.get(it.next());
stageBlockSize = stage.currentBlockSize();
for (j = 0; j < blockSize; j += stageBlockSize)
- {
- stage.update(in, inOffset + j, out, outOffset + j);
- }
+ stage.update(in, inOffset + j, out, outOffset + j);
i--;
if (i > 0)
- {
- System.arraycopy(out, outOffset, in, inOffset, blockSize);
- }
+ System.arraycopy(out, outOffset, in, inOffset, blockSize);
}
}
@@ -385,18 +332,16 @@ public class Cascade
* encryption / decryption test(s) for all supported block and key sizes of
* underlying block cipher(s) wrapped by Mode leafs. The test also includes
* one (1) variable key Known Answer Test (KAT) for each block cipher.
- *
+ *
* @return <code>true</code> if the implementation passes simple
- * <i>correctness</i> tests. Returns <code>false</code> otherwise.
+ * <i>correctness</i> tests. Returns <code>false</code> otherwise.
*/
public boolean selfTest()
{
for (Iterator it = stageKeys.listIterator(); it.hasNext();)
{
- if (!((Stage) stages.get(it.next())).selfTest())
- {
- return false;
- }
+ if (! ((Stage) stages.get(it.next())).selfTest())
+ return false;
}
return true;
}
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/CascadeStage.java b/libjava/classpath/gnu/javax/crypto/assembly/CascadeStage.java
index 81629f5a8e7..b86f42e2aec 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/CascadeStage.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/CascadeStage.java
@@ -44,19 +44,13 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>A Cascade <i>Stage</i> in a Cascade Cipher.</p>
+ * A Cascade <i>Stage</i> in a Cascade Cipher.
*/
-class CascadeStage extends Stage
+class CascadeStage
+ extends Stage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Cascade delegate;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
CascadeStage(Cascade cascade, Direction forwardDirection)
{
super(forwardDirection);
@@ -64,12 +58,6 @@ class CascadeStage extends Stage
this.delegate = cascade;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public Set blockSizes()
{
return Collections.unmodifiableSet(delegate.blockSizes());
@@ -79,9 +67,7 @@ class CascadeStage extends Stage
{
Direction flow = (Direction) attributes.get(DIRECTION);
attributes.put(DIRECTION, flow.equals(forward) ? forward
- : Direction.reverse(forward));
- // delegate.init(flow.equals(forward) ? forward : backward);
- // delegate.init(flow.equals(forward) ? forward : Direction.reverse(forward));
+ : Direction.reverse(forward));
delegate.init(attributes);
}
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/CascadeTransformer.java b/libjava/classpath/gnu/javax/crypto/assembly/CascadeTransformer.java
index dbbc7cd286e..5fce51a15eb 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/CascadeTransformer.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/CascadeTransformer.java
@@ -45,19 +45,13 @@ import java.util.Map;
* An Adapter to use any {@link Cascade} as a {@link Transformer} in an
* {@link Assembly}.
*/
-class CascadeTransformer extends Transformer
+class CascadeTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Cascade delegate;
private int blockSize;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
CascadeTransformer(Cascade delegate)
{
super();
@@ -65,12 +59,6 @@ class CascadeTransformer extends Transformer
this.delegate = delegate;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instant methods
- // -------------------------------------------------------------------------
-
void initDelegate(Map attributes) throws TransformerException
{
attributes.put(Cascade.DIRECTION, wired);
@@ -107,11 +95,9 @@ class CascadeTransformer extends Transformer
{
if (inBuffer.size() != 0)
{
- throw new TransformerException(
- "lastUpdateDelegate()",
- new IllegalStateException(
- "Cascade transformer, after last "
- + "update, must be empty but isn't"));
+ IllegalStateException cause = new IllegalStateException(
+ "Cascade transformer, after last update, must be empty but isn't");
+ throw new TransformerException("lastUpdateDelegate()", cause);
}
return new byte[0];
}
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/DeflateTransformer.java b/libjava/classpath/gnu/javax/crypto/assembly/DeflateTransformer.java
index 35328a6c1dc..e5c0b7a5724 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/DeflateTransformer.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/DeflateTransformer.java
@@ -44,27 +44,22 @@ import java.util.zip.Deflater;
import java.util.zip.Inflater;
/**
- * <p>A {@link Transformer} Adapter allowing inclusion of a DEFLATE compression
+ * A {@link Transformer} Adapter allowing inclusion of a DEFLATE compression
* algorithm in an {@link Assembly} chain. The {@link Direction#FORWARD}
* transformation is a compression (deflate) of input data, while the
- * {@link Direction#REVERSED} one is a decompression (inflate) that restores
- * the original data.</p>
- *
- * <p>This {@link Transformer} uses a {@link Deflater} instance to carry on the
- * compression, and an {@link Inflater} to do the decompression.</p>
- *
- * <p>When using such a {@link Transformer}, in an {@link Assembly}, there must
+ * {@link Direction#REVERSED} one is a decompression (inflate) that restores the
+ * original data.
+ * <p>
+ * This {@link Transformer} uses a {@link Deflater} instance to carry on the
+ * compression, and an {@link Inflater} to do the decompression.
+ * <p>
+ * When using such a {@link Transformer}, in an {@link Assembly}, there must
* be at least one element behind this instance in the constructed chain;
- * otherwise, a {@link TransformerException} is thrown at initialisation time.</p>
- *
- * @version Revision: $
+ * otherwise, a {@link TransformerException} is thrown at initialisation time.
*/
-class DeflateTransformer extends Transformer
+class DeflateTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Deflater compressor;
private Inflater decompressor;
@@ -73,46 +68,31 @@ class DeflateTransformer extends Transformer
private byte[] zlibBuffer;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
DeflateTransformer()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
void initDelegate(Map attributes) throws TransformerException
{
if (tail == null)
{
- throw new TransformerException(
- "initDelegate()",
- new IllegalStateException(
- "Compression transformer missing its tail!"));
+ IllegalStateException cause = new IllegalStateException(
+ "Compression transformer missing its tail!");
+ throw new TransformerException("initDelegate()", cause);
}
outputBlockSize = tail.currentBlockSize();
zlibBuffer = new byte[outputBlockSize];
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == Direction.FORWARD)
- {
- compressor = new Deflater();
- }
+ compressor = new Deflater();
else
- {
- decompressor = new Inflater();
- }
+ decompressor = new Inflater();
}
int delegateBlockSize()
{
- // return outputBlockSize;
return 1;
}
@@ -131,68 +111,36 @@ class DeflateTransformer extends Transformer
if (wired == Direction.FORWARD)
{
compressor.setInput(in, offset, length);
- while (!compressor.needsInput())
- {
- compress();
- }
+ while (! compressor.needsInput())
+ compress();
}
- else
- { // decompression: inflate first and then update tail
- decompress(in, offset, length);
- }
-
+ else // decompression: inflate first and then update tail
+ decompress(in, offset, length);
result = inBuffer.toByteArray();
inBuffer.reset();
return result;
}
- // byte[] lastUpdateDelegate(byte[] in, int offset, int length)
- // throws TransformerException {
- // // process multiples of blocksize as much as possible
- // byte[] result = this.updateDelegate(in, offset, length);
- // inBuffer.write(result, 0, result.length);
- // if (wired == Direction.FORWARD) { // compressing
- // if (!compressor.finished()) {
- // compressor.finish();
- // while (!compressor.finished()) {
- // compress();
- // }
- // }
- // } else { // decompressing
- // if (!decompressor.finished()) {
- // throw new TransformerException("lastUpdateDelegate()",
- // new IllegalStateException("Compression transformer, after last "
- // +"update, must be finished but isn't"));
- // }
- // }
- //
- // result = inBuffer.toByteArray();
- // inBuffer.reset();
- // return result;
- // }
byte[] lastUpdateDelegate() throws TransformerException
{
// process multiples of blocksize as much as possible
- if (wired == Direction.FORWARD)
- { // compressing
- if (!compressor.finished())
+ if (wired == Direction.FORWARD) // compressing
+ {
+ if (! compressor.finished())
{
compressor.finish();
- while (!compressor.finished())
- {
- compress();
- }
+ while (! compressor.finished())
+ compress();
}
}
- else
- { // decompressing
- if (!decompressor.finished())
+ else // decompressing
+ {
+ if (! decompressor.finished())
{
- throw new TransformerException(
- "lastUpdateDelegate()",
- new IllegalStateException(
- "Compression transformer, after last "
- + "update, must be finished but isn't"));
+ IllegalStateException cause = new IllegalStateException(
+ "Compression transformer, after last update, must be finished "
+ + "but isn't");
+ throw new TransformerException("lastUpdateDelegate()", cause);
}
}
byte[] result = inBuffer.toByteArray();
@@ -204,9 +152,7 @@ class DeflateTransformer extends Transformer
{
int len = compressor.deflate(zlibBuffer);
if (len > 0)
- {
- inBuffer.write(zlibBuffer, 0, len);
- }
+ inBuffer.write(zlibBuffer, 0, len);
}
private void decompress(byte[] in, int offset, int length)
@@ -225,9 +171,7 @@ class DeflateTransformer extends Transformer
throw new TransformerException("decompress()", x);
}
if (len > 0)
- {
- inBuffer.write(zlibBuffer, 0, len);
- }
+ inBuffer.write(zlibBuffer, 0, len);
}
}
}
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/Direction.java b/libjava/classpath/gnu/javax/crypto/assembly/Direction.java
index 58b59a6307f..48c74ed1ba0 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/Direction.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/Direction.java
@@ -39,32 +39,26 @@ exception statement from your version. */
package gnu.javax.crypto.assembly;
/**
- * <p>An enumeration type for wiring {@link Stage} instances into {@link
- * Cascade} Cipher chains, as well as for operating a {@link Cascade} in a
- * given direction.</p>
- *
- * <p>The possible values for this type are two:</p>
+ * An enumeration type for wiring {@link Stage} instances into {@link Cascade}
+ * Cipher chains, as well as for operating a {@link Cascade} in a given
+ * direction.
+ * <p>
+ * The possible values for this type are two:
* <ol>
- * <li>FORWARD: equivalent to {@link gnu.crypto.mode.IMode#ENCRYPTION}, and
- * its inverse value</li>
- * <li>REVERSED: equivalent to {@link gnu.crypto.mode.IMode#DECRYPTION}.</li>
+ * <li>FORWARD: equivalent to {@link gnu.javax.crypto.mode.IMode#ENCRYPTION},
+ * and its inverse value</li>
+ * <li>REVERSED: equivalent to {@link gnu.javax.crypto.mode.IMode#DECRYPTION}.
+ * </li>
* </ol>
*/
public final class Direction
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final Direction FORWARD = new Direction(1);
public static final Direction REVERSED = new Direction(2);
private int value;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
private Direction(int value)
{
super();
@@ -72,17 +66,11 @@ public final class Direction
this.value = value;
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static final Direction reverse(Direction d)
{
return (d.equals(FORWARD) ? REVERSED : FORWARD);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
public String toString()
{
return (this == FORWARD ? "forward" : "reversed");
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/LoopbackTransformer.java b/libjava/classpath/gnu/javax/crypto/assembly/LoopbackTransformer.java
index 3c0bdfab30c..bba1da77843 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/LoopbackTransformer.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/LoopbackTransformer.java
@@ -44,27 +44,15 @@ import java.util.Map;
* A trivial {@link Transformer} to allow closing a chain in an {@link Assembly}.
* This class is not visible outside this package.
*/
-final class LoopbackTransformer extends Transformer
+final class LoopbackTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
- /** Trivial protected constructor. */
+ /** Trivial package-private constructor. */
LoopbackTransformer()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public void init(Map attributes) throws TransformerException
{
}
@@ -84,8 +72,6 @@ final class LoopbackTransformer extends Transformer
return lastUpdateDelegate();
}
- // abstract methods to be implemented by concrete subclasses ---------------
-
void initDelegate(Map attributes) throws TransformerException
{
}
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/ModeStage.java b/libjava/classpath/gnu/javax/crypto/assembly/ModeStage.java
index 1143348f675..253ab4ae60a 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/ModeStage.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/ModeStage.java
@@ -48,25 +48,19 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>An {@link IMode} {@link Stage} in a {@link Cascade} Cipher chain.</p>
- *
- * <p>Such a stage wraps an implementation of a Block Cipher Mode of Operation
+ * An {@link IMode} {@link Stage} in a {@link Cascade} Cipher chain.
+ * <p>
+ * Such a stage wraps an implementation of a Block Cipher Mode of Operation
* ({@link IMode}) to allow inclusion of such an instance in a cascade of block
- * ciphers.</p>
+ * ciphers.
*/
-class ModeStage extends Stage
+class ModeStage
+ extends Stage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private IMode delegate;
private transient Set cachedBlockSizes;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
ModeStage(IMode mode, Direction forwardDirection)
{
super(forwardDirection);
@@ -75,21 +69,13 @@ class ModeStage extends Stage
cachedBlockSizes = null;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public Set blockSizes()
{
if (cachedBlockSizes == null)
{
HashSet result = new HashSet();
for (Iterator it = delegate.blockSizes(); it.hasNext();)
- {
- result.add(it.next());
- }
+ result.add(it.next());
cachedBlockSizes = Collections.unmodifiableSet(result);
}
return cachedBlockSizes;
@@ -99,9 +85,8 @@ class ModeStage extends Stage
{
Direction flow = (Direction) attributes.get(DIRECTION);
attributes.put(IMode.STATE,
- new Integer(flow.equals(forward) ? IMode.ENCRYPTION
- : IMode.DECRYPTION));
-
+ Integer.valueOf(flow.equals(forward) ? IMode.ENCRYPTION
+ : IMode.DECRYPTION));
delegate.init(attributes);
}
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/Operation.java b/libjava/classpath/gnu/javax/crypto/assembly/Operation.java
index 34cae52ea80..28fdf941298 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/Operation.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/Operation.java
@@ -39,34 +39,26 @@ exception statement from your version. */
package gnu.javax.crypto.assembly;
/**
- * <p>An enumeration type for specifying the operation type of a
- * {@link Transformer}.</p>
- *
- * <p>The possible values for this type are two:</p>
+ * An enumeration type for specifying the operation type of a
+ * {@link Transformer}.
+ * <p>
+ * The possible values for this type are two:
* <ol>
- * <li>PRE_PROCESSING: where the input data is first processed by the
- * current {@link Transformer} before being passed to the rest of the chain;
- * and</li>
- * <li>POST_PROCESSING: where the input data is first passed to the rest of
- * the chain, and the resulting bytes are then processed by the current
- * {@link Transformer}.</li>
+ * <li>PRE_PROCESSING: where the input data is first processed by the current
+ * {@link Transformer} before being passed to the rest of the chain; and</li>
+ * <li>POST_PROCESSING: where the input data is first passed to the rest of the
+ * chain, and the resulting bytes are then processed by the current
+ * {@link Transformer}.</li>
* </ol>
*/
public final class Operation
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final Operation PRE_PROCESSING = new Operation(1);
public static final Operation POST_PROCESSING = new Operation(2);
private int value;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
private Operation(int value)
{
super();
@@ -74,12 +66,6 @@ public final class Operation
this.value = value;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public String toString()
{
return (this == PRE_PROCESSING ? "pre-processing" : "post-processing");
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/PaddingTransformer.java b/libjava/classpath/gnu/javax/crypto/assembly/PaddingTransformer.java
index c63f92e87bc..c11f4fe88da 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/PaddingTransformer.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/PaddingTransformer.java
@@ -44,26 +44,20 @@ import gnu.javax.crypto.pad.WrongPaddingException;
import java.util.Map;
/**
- * <p>An Adapter to use any {@link IPad} as a {@link Transformer} in an
- * {@link Assembly}.</p>
- *
- * <p>When using such a {@link Transformer}, in an {@link Assembly}, there must
+ * An Adapter to use any {@link IPad} as a {@link Transformer} in an
+ * {@link Assembly}.
+ * <p>
+ * When using such a {@link Transformer}, in an {@link Assembly}, there must
* be at least one element behind this instance in the constructed chain;
- * otherwise, a {@link TransformerException} is thrown at initialisation time.</p>
+ * otherwise, a {@link TransformerException} is thrown at initialisation time.
*/
-class PaddingTransformer extends Transformer
+class PaddingTransformer
+ extends Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private IPad delegate;
private int outputBlockSize = 1;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
PaddingTransformer(IPad padding)
{
super();
@@ -71,20 +65,13 @@ class PaddingTransformer extends Transformer
this.delegate = padding;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
void initDelegate(Map attributes) throws TransformerException
{
if (tail == null)
{
- throw new TransformerException(
- "initDelegate()",
- new IllegalStateException(
- "Padding transformer missing its tail!"));
+ IllegalStateException cause = new IllegalStateException(
+ "Padding transformer missing its tail!");
+ throw new TransformerException("initDelegate()", cause);
}
outputBlockSize = tail.currentBlockSize();
delegate.init(outputBlockSize);
@@ -108,9 +95,10 @@ class PaddingTransformer extends Transformer
byte[] tmp = inBuffer.toByteArray();
inBuffer.reset();
byte[] result;
- if (wired == Direction.FORWARD)
- { // padding
- // buffers remaining bytes from (inBuffer + in) that are less than 1 block
+ if (wired == Direction.FORWARD) // padding
+ {
+ // buffers remaining bytes from (inBuffer + in) that are less than 1
+ // block
if (tmp.length < outputBlockSize)
{
inBuffer.write(tmp, 0, tmp.length);
@@ -124,8 +112,8 @@ class PaddingTransformer extends Transformer
System.arraycopy(tmp, 0, result, 0, newlen);
}
}
- else
- { // unpadding
+ else // unpadding
+ {
// always keep in own buffer a max of 1 block to cater for lastUpdate
if (tmp.length < outputBlockSize)
{
@@ -147,14 +135,14 @@ class PaddingTransformer extends Transformer
byte[] result;
// process multiples of blocksize as much as possible
// catenate result from processing inBuffer with last-update( tail )
- if (wired == Direction.FORWARD)
- { // padding
+ if (wired == Direction.FORWARD) // padding
+ {
result = inBuffer.toByteArray();
byte[] padding = delegate.pad(result, 0, result.length);
inBuffer.write(padding, 0, padding.length);
}
- else
- { // unpadding
+ else // unpadding
+ {
byte[] tmp = inBuffer.toByteArray();
inBuffer.reset();
int realLength;
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/Stage.java b/libjava/classpath/gnu/javax/crypto/assembly/Stage.java
index 23d50bb8237..d023f62830a 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/Stage.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/Stage.java
@@ -45,59 +45,56 @@ import java.util.Map;
import java.util.Set;
/**
- * <p>A <i>Stage</i> in a Cascade Cipher.</p>
- *
- * <p>Each stage may be either an implementation of a Block Cipher Mode of
- * Operation ({@link IMode}) or another Cascade Cipher ({@link Cascade}). Each
- * stage has also a <i>natural</i> operational direction when constructed for
- * inclusion within a {@link Cascade}. This <i>natural</i> direction dictates
- * how data flows from one stage into another when stages are chained together
- * in a cascade. One can think of a stage and its natural direction as the
- * specification of how to wire the stage into the chain. The following diagrams
- * may help understand the paradigme. The first shows two stages chained each
- * with a {@link Direction#FORWARD} direction.</p>
+ * A <i>Stage</i> in a Cascade Cipher.
+ * <p>
+ * Each stage may be either an implementation of a Block Cipher Mode of
+ * Operation ({@link IMode}) or another Cascade Cipher ({@link Cascade}).
+ * Each stage has also a <i>natural</i> operational direction when constructed
+ * for inclusion within a {@link Cascade}. This <i>natural</i> direction
+ * dictates how data flows from one stage into another when stages are chained
+ * together in a cascade. One can think of a stage and its natural direction as
+ * the specification of how to wire the stage into the chain. The following
+ * diagrams may help understand the paradigme. The first shows two stages
+ * chained each with a {@link Direction#FORWARD} direction.
+ *
* <pre>
- * FORWARD FORWARD
- * +------+ +-------+
- * | | | |
- * | +--in --+ | +--in --+
- * ---+ | Stage | | | Stage | +---
- * +--out--+ | +--out--+ |
- * | | | |
- * +-------+ +------+
+ * FORWARD FORWARD
+ * +------+ +-------+
+ * | | | |
+ * | +--in --+ | +--in --+
+ * ---+ | Stage | | | Stage | +---
+ * +--out--+ | +--out--+ |
+ * | | | |
+ * +-------+ +------+
* </pre>
- * <p>The second diagram shows two stages, one in a {@link Direction#FORWARD}
+ *
+ * <p>
+ * The second diagram shows two stages, one in a {@link Direction#FORWARD}
* direction, while the other is wired in a {@link Direction#REVERSED}
- * direction.</p>
+ * direction.
+ *
* <pre>
- * FORWARD REVERSED
- * +------+ +------+
- * | | | |
- * | +--in --+ +--in --+ |
- * ---+ | Stage | | Stage | +---
- * +--out--+ +--out--+
- * | |
- * +---------------+
+ * FORWARD REVERSED
+ * +------+ +------+
+ * | | | |
+ * | +--in --+ +--in --+ |
+ * ---+ | Stage | | Stage | +---
+ * +--out--+ +--out--+
+ * | |
+ * +---------------+
* </pre>
- *
+ *
* @see ModeStage
* @see CascadeStage
*/
public abstract class Stage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.stage.direction";
protected Direction forward;
protected Direction wired;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected Stage(Direction forwardDirection)
{
super();
@@ -106,9 +103,6 @@ public abstract class Stage
this.wired = null;
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static final Stage getInstance(IMode mode, Direction forwardDirection)
{
return new ModeStage(mode, forwardDirection);
@@ -120,32 +114,27 @@ public abstract class Stage
return new CascadeStage(cascade, forwardDirection);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Returns the {@link Set} of supported block sizes for this
* <code>Stage</code>. Each element in the returned {@link Set} is an
* instance of {@link Integer}.
- *
+ *
* @return a {@link Set} of supported block sizes.
*/
public abstract Set blockSizes();
/**
* Initialises the stage for operation with specific characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the instance is already initialised.
* @throws InvalidKeyException if the key data is invalid.
*/
public void init(Map attributes) throws InvalidKeyException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
{
@@ -158,7 +147,7 @@ public abstract class Stage
/**
* Returns the currently set block size for the stage.
- *
+ *
* @return the current block size for this stage.
* @throws IllegalStateException if the instance is not initialised.
*/
@@ -178,10 +167,10 @@ public abstract class Stage
* Processes exactly one block of <i>plaintext</i> (if initialised in the
* {@link Direction#FORWARD} state) or <i>ciphertext</i> (if initialised in
* the {@link Direction#REVERSED} state).
- *
+ *
* @param in the plaintext.
* @param inOffset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param out the ciphertext.
* @param outOffset index of <code>out</code> from which to store result.
* @throws IllegalStateException if the instance is not initialised.
@@ -189,9 +178,7 @@ public abstract class Stage
public void update(byte[] in, int inOffset, byte[] out, int outOffset)
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
updateDelegate(in, inOffset, out, outOffset);
}
@@ -200,14 +187,12 @@ public abstract class Stage
* encryption / decryption test(s) for all supported block and key sizes of
* underlying block cipher(s) wrapped by Mode leafs. The test also includes
* one (1) variable key Known Answer Test (KAT) for each block cipher.
- *
+ *
* @return <code>true</code> if the implementation passes simple
- * <i>correctness</i> tests. Returns <code>false</code> otherwise.
+ * <i>correctness</i> tests. Returns <code>false</code> otherwise.
*/
public abstract boolean selfTest();
- // abstract methods to be implemented by concrete subclasses ---------------
-
abstract void initDelegate(Map attributes) throws InvalidKeyException;
abstract void resetDelegate();
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/Transformer.java b/libjava/classpath/gnu/javax/crypto/assembly/Transformer.java
index 80430dc196f..58a991b93b9 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/Transformer.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/Transformer.java
@@ -44,50 +44,44 @@ import java.io.ByteArrayOutputStream;
import java.util.Map;
/**
- * <p>A <code>Transformer</code> is an abstract representation of a two-way
+ * A <code>Transformer</code> is an abstract representation of a two-way
* <i>transformation</i> that can be chained together with other instances of
* this type. Examples of such transformations in this library are:
- * {@link Cascade} cipher, {@link gnu.crypto.pad.IPad} algorithm, and a
+ * {@link Cascade} cipher, {@link gnu.javax.crypto.pad.IPad} algorithm, and a
* ZLib-based deflater/inflater algorithm. A special implementation of a
- * <code>Transformer</code> to close a chain is also provided.</p>
- *
- * <p>A <code>Transformer</code> is characterised by the followings:<p>
+ * <code>Transformer</code> to close a chain is also provided.
+ * <p>
+ * A <code>Transformer</code> is characterised by the followings:
* <ul>
- * <li>It can be chained to other instances, to form an {@link Assembly}.</li>
- * <li>When configured in an {@link Assembly}, it can be set to apply its
- * internal transformation on the input data stream before (pre-processing)
- * or after (post-processing) passing the input data to the next element in
- * the chain. Note that the same type <code>Transformer</code> can be used as
- * either in pre-processing or a post-processing modes.</li>
- * <li>A special transformer --<code>LoopbackTransformer</code>-- is used to
- * close the chain.</li>
- * <li>A useful type of <code>Transformer</code> --one we're interested in--
- * has internal buffers. The distinction between a casual push (update)
- * operation and the last one allows to correctly flush any intermediate
- * bytes that may exist in those buffers.</li>
+ * <li>It can be chained to other instances, to form an {@link Assembly}.</li>
+ * <li>When configured in an {@link Assembly}, it can be set to apply its
+ * internal transformation on the input data stream before (pre-processing) or
+ * after (post-processing) passing the input data to the next element in the
+ * chain. Note that the same type <code>Transformer</code> can be used as
+ * either in pre-processing or a post-processing modes.</li>
+ * <li>A special transformer --<code>LoopbackTransformer</code>-- is used
+ * to close the chain.</li>
+ * <li>A useful type of <code>Transformer</code> --one we're interested in--
+ * has internal buffers. The distinction between a casual push (update)
+ * operation and the last one allows to correctly flush any intermediate bytes
+ * that may exist in those buffers.</li>
* </ul>
- *
- * <p>To allow wiring <code>Transformer</code> instances together, a
+ * <p>
+ * To allow wiring <code>Transformer</code> instances together, a
* <i>minimal-output-size</i> in bytes is necessary. The trivial case of a
* value of <code>1</code> for such attribute practically means that no output
* buffering, from the previous element, is needed --which is independant of
- * buffering the input if the <code>Transformer</code> implementation itself is
- * block-based.</p>
- *
+ * buffering the input if the <code>Transformer</code> implementation itself
+ * is block-based.
+ *
* @see CascadeTransformer
* @see PaddingTransformer
* @see DeflateTransformer
*/
public abstract class Transformer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String DIRECTION = "gnu.crypto.assembly.transformer.direction";
- // public static final String MODE = "gnu.crypto.assembly.transformer.mode";
-
protected Direction wired;
protected Operation mode;
@@ -98,9 +92,6 @@ public abstract class Transformer
protected ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(2048);
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial protected constructor. */
protected Transformer()
{
@@ -109,9 +100,6 @@ public abstract class Transformer
this.wired = null;
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static final Transformer getCascadeTransformer(Cascade cascade)
{
return new CascadeTransformer(cascade);
@@ -127,81 +115,69 @@ public abstract class Transformer
return new DeflateTransformer();
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Sets the operational mode of this <code>Transformer</code>.
- *
+ *
* @param mode the processing mode this <code>Transformer</code> is required
- * to operate in.
- * @throws IllegalStateException if this instance has already been assigned
- * an operational mode.
+ * to operate in.
+ * @throws IllegalStateException if this instance has already been assigned an
+ * operational mode.
*/
public void setMode(final Operation mode)
{
if (this.mode != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
this.mode = mode;
}
/**
* Returns <code>true</code> if this <code>Transformer</code> was wired in
* pre-processing mode; <code>false</code> otherwise.
- *
- * @return <code>true</code> if this <code>Transformer</code> has been wired
- * in pre-processing mode; <code>false</code> otherwise.
- * @throws IllegalStateException if this instance has not yet been assigned
- * an operational <i>type</i>.
+ *
+ * @return <code>true</code> if this <code>Transformer</code> has been
+ * wired in pre-processing mode; <code>false</code> otherwise.
+ * @throws IllegalStateException if this instance has not yet been assigned an
+ * operational <i>type</i>.
*/
public boolean isPreProcessing()
{
if (mode == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return (mode == Operation.PRE_PROCESSING);
}
/**
* Returns <code>true</code> if this <code>Transformer</code> was wired in
* post-processing mode; <code>false</code> otherwise.
- *
- * @return <code>true</code> if this <code>Transformer</code> has been wired
- * in post-processing mode; <code>false</code> otherwise.
- * @throws IllegalStateException if this instance has not yet been assigned
- * an operational <i>type</i>.
+ *
+ * @return <code>true</code> if this <code>Transformer</code> has been
+ * wired in post-processing mode; <code>false</code> otherwise.
+ * @throws IllegalStateException if this instance has not yet been assigned an
+ * operational <i>type</i>.
*/
public boolean isPostProcessing()
{
- return !isPreProcessing();
+ return ! isPreProcessing();
}
/**
* Initialises the <code>Transformer</code> for operation with specific
* characteristics.
- *
+ *
* @param attributes a set of name-value pairs that describes the desired
- * future behaviour of this instance.
+ * future behaviour of this instance.
* @throws IllegalStateException if the instance is already initialised.
*/
public void init(Map attributes) throws TransformerException
{
if (wired != null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
Direction flow = (Direction) attributes.get(DIRECTION);
if (flow == null)
- {
- flow = Direction.FORWARD;
- }
+ flow = Direction.FORWARD;
wired = flow;
inBuffer.reset();
outBuffer.reset();
-
tail.init(attributes); // initialise tail first
initDelegate(attributes); // initialise this instance
}
@@ -209,15 +185,13 @@ public abstract class Transformer
/**
* Returns the block-size of this <code>Transformer</code>. A value of
* <code>1</code> indicates that this instance is block-agnostic.
- *
+ *
* @return the current minimal required block size.
*/
public int currentBlockSize()
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
+ throw new IllegalStateException();
return delegateBlockSize();
}
@@ -238,12 +212,12 @@ public abstract class Transformer
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte b) throws TransformerException
@@ -253,14 +227,14 @@ public abstract class Transformer
/**
* Convenience method that calls the same method with three arguments. All
- * bytes in <code>in</code>, starting from index position <code>0</code> are
- * considered.
- *
+ * bytes in <code>in</code>, starting from index position <code>0</code>
+ * are considered.
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #update(byte[], int, int)
*/
public byte[] update(byte[] in) throws TransformerException
@@ -270,48 +244,42 @@ public abstract class Transformer
/**
* Processes a designated number of bytes from a given byte array.
- *
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
*/
public byte[] update(byte[] in, int offset, int length)
throws TransformerException
{
if (wired == null)
- {
- throw new IllegalStateException();
- }
- byte[] result = (wired == Direction.FORWARD ? forwardUpdate(in, offset,
- length)
- : inverseUpdate(in, offset,
- length));
+ throw new IllegalStateException();
+ byte[] result = (wired == Direction.FORWARD ? forwardUpdate(in, offset, length)
+ : inverseUpdate(in, offset, length));
return result;
}
/**
* Convenience method that calls the same method with three arguments. A
* zero-long byte array is used.
- *
+ *
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate() throws TransformerException
{
byte[] result = (wired == Direction.FORWARD ? lastForwardUpdate()
- : lastInverseUpdate());
- if (inBuffer.size() != 0)
- { // we still have some buffered bytes
- throw new TransformerException("lastUpdate(): input buffer not empty");
- }
+ : lastInverseUpdate());
+ if (inBuffer.size() != 0) // we still have some buffered bytes
+ throw new TransformerException("lastUpdate(): input buffer not empty");
return result;
}
@@ -319,12 +287,12 @@ public abstract class Transformer
* Convenience method that calls the method with same name and three
* arguments, using a byte array of length <code>1</code> whose contents are
* the designated byte.
- *
+ *
* @param b the byte to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte b) throws TransformerException
@@ -334,14 +302,14 @@ public abstract class Transformer
/**
* Convenience method that calls the same method with three arguments. All
- * bytes in <code>in</code>, starting from index position <code>0</code> are
- * considered.
- *
+ * bytes in <code>in</code>, starting from index position <code>0</code>
+ * are considered.
+ *
* @param in the input data bytes.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
* @see #lastUpdate(byte[], int, int)
*/
public byte[] lastUpdate(byte[] in) throws TransformerException
@@ -350,18 +318,18 @@ public abstract class Transformer
}
/**
- * Processes a designated number of bytes from a given byte array and
- * signals, at the same time, that this is the last <i>push</i> operation on
- * this <code>Transformer</code>.
- *
+ * Processes a designated number of bytes from a given byte array and signals,
+ * at the same time, that this is the last <i>push</i> operation on this
+ * <code>Transformer</code>.
+ *
* @param in the input data bytes.
* @param offset index of <code>in</code> from which to start considering
- * data.
+ * data.
* @param length the count of bytes to process.
* @return the result of transformation.
* @throws IllegalStateException if the instance is not initialised.
* @throws TransformerException if a transformation-related exception occurs
- * during the operation.
+ * during the operation.
*/
public byte[] lastUpdate(byte[] in, int offset, int length)
throws TransformerException
@@ -378,22 +346,18 @@ public abstract class Transformer
return result;
}
- // helper methods ----------------------------------------------------------
-
private byte[] forwardUpdate(byte[] in, int off, int len)
throws TransformerException
{
- return (isPreProcessing() ? preTransform(in, off, len) : postTransform(in,
- off,
- len));
+ return (isPreProcessing() ? preTransform(in, off, len)
+ : postTransform(in, off, len));
}
private byte[] inverseUpdate(byte[] in, int off, int len)
throws TransformerException
{
- return (isPreProcessing() ? postTransform(in, off, len) : preTransform(in,
- off,
- len));
+ return (isPreProcessing() ? postTransform(in, off, len)
+ : preTransform(in, off, len));
}
private byte[] preTransform(byte[] in, int off, int len)
@@ -444,8 +408,6 @@ public abstract class Transformer
return result;
}
- // abstract methods to be implemented by concrete subclasses ---------------
-
abstract void initDelegate(Map attributes) throws TransformerException;
abstract int delegateBlockSize();
diff --git a/libjava/classpath/gnu/javax/crypto/assembly/TransformerException.java b/libjava/classpath/gnu/javax/crypto/assembly/TransformerException.java
index 412f0f0f183..2c972f858d3 100644
--- a/libjava/classpath/gnu/javax/crypto/assembly/TransformerException.java
+++ b/libjava/classpath/gnu/javax/crypto/assembly/TransformerException.java
@@ -43,17 +43,11 @@ import java.io.PrintWriter;
/**
*/
-public class TransformerException extends Exception
+public class TransformerException
+ extends Exception
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private Throwable _exception = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public TransformerException()
{
super();
@@ -78,12 +72,6 @@ public class TransformerException extends Exception
this._exception = cause;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instant methods
- // -------------------------------------------------------------------------
-
public Throwable getCause()
{
return _exception;
@@ -98,61 +86,53 @@ public class TransformerException extends Exception
{
super.printStackTrace();
if (_exception != null)
- {
- _exception.printStackTrace();
- }
+ _exception.printStackTrace();
}
/**
* Prints this exception's stack trace to a print stream. If this exception
- * has a root exception; the stack trace of the root exception is also
- * printed to the print stream.
- *
+ * has a root exception; the stack trace of the root exception is also printed
+ * to the print stream.
+ *
* @param ps the non-null print stream to which to print.
*/
public void printStackTrace(PrintStream ps)
{
super.printStackTrace(ps);
if (_exception != null)
- {
- _exception.printStackTrace(ps);
- }
+ _exception.printStackTrace(ps);
}
/**
* Prints this exception's stack trace to a print writer. If this exception
- * has a root exception; the stack trace of the root exception is also
- * printed to the print writer.
- *
+ * has a root exception; the stack trace of the root exception is also printed
+ * to the print writer.
+ *
* @param pw the non-null print writer to use for output.
*/
public void printStackTrace(PrintWriter pw)
{
super.printStackTrace(pw);
if (_exception != null)
- {
- _exception.printStackTrace(pw);
- }
+ _exception.printStackTrace(pw);
}
/**
* Returns the string representation of this exception. The string
- * representation contains this exception's class name, its detailed
- * messsage, and if it has a root exception, the string representation of the
- * root exception. This string representation is meant for debugging and not
- * meant to be interpreted programmatically.
- *
+ * representation contains this exception's class name, its detailed messsage,
+ * and if it has a root exception, the string representation of the root
+ * exception. This string representation is meant for debugging and not meant
+ * to be interpreted programmatically.
+ *
* @return the non-null string representation of this exception.
* @see Throwable#getMessage()
*/
public String toString()
{
- StringBuffer sb = new StringBuffer(this.getClass().getName()).append(": ").append(
- super.toString());
+ StringBuffer sb = new StringBuffer(this.getClass().getName())
+ .append(": ").append(super.toString());
if (_exception != null)
- {
- sb.append("; caused by: ").append(_exception.toString());
- }
+ sb.append("; caused by: ").append(_exception.toString());
return sb.toString();
}
}
OpenPOWER on IntegriCloud