gnu.crypto.assembly

Class Transformer

public abstract class Transformer extends Object

A Transformer is an abstract representation of a two-way transformation that can be chained together with other instances of this type. Examples of such transformations in this library are: Cascade cipher, IPad algorithm, and a ZLib-based deflater/inflater algorithm. A special implementation of a Transformer to close a chain is also provided.

A Transformer is characterised by the followings:

To allow wiring Transformer instances together, a minimal-output-size in bytes is necessary. The trivial case of a value of 1 for such attribute practically means that no output buffering, from the previous element, is needed --which is independant of buffering the input if the Transformer implementation itself is block-based.

Version: $Revision: 1.3 $

See Also: CascadeTransformer PaddingTransformer DeflateTransformer

Field Summary
static StringDIRECTION
protected ByteArrayOutputStreaminBuffer
protected Operationmode
protected ByteArrayOutputStreamoutBuffer
protected Transformertail
protected Directionwired
Constructor Summary
protected Transformer()
Trivial protected constructor.
Method Summary
intcurrentBlockSize()
Returns the block-size of this Transformer.
abstract intdelegateBlockSize()
static TransformergetCascadeTransformer(Cascade cascade)
static TransformergetDeflateTransformer()
static TransformergetPaddingTransformer(IPad padding)
voidinit(Map attributes)
Initialises the Transformer for operation with specific characteristics.
abstract voidinitDelegate(Map attributes)
booleanisPostProcessing()
Returns true if this Transformer was wired in post-processing mode; false otherwise.
booleanisPreProcessing()
Returns true if this Transformer was wired in pre-processing mode; false otherwise.
byte[]lastUpdate()
Convenience method that calls the same method with three arguments.
byte[]lastUpdate(byte b)
Convenience method that calls the method with same name and three arguments, using a byte array of length 1 whose contents are the designated byte.
byte[]lastUpdate(byte[] in)
Convenience method that calls the same method with three arguments.
byte[]lastUpdate(byte[] in, int offset, int length)
Processes a designated number of bytes from a given byte array and signals, at the same time, that this is the last push operation on this Transformer.
abstract byte[]lastUpdateDelegate()
voidreset()
Resets the Transformer for re-initialisation and use with other characteristics.
abstract voidresetDelegate()
voidsetMode(Operation mode)
Sets the operational mode of this Transformer.
byte[]update(byte b)
Convenience method that calls the method with same name and three arguments, using a byte array of length 1 whose contents are the designated byte.
byte[]update(byte[] in)
Convenience method that calls the same method with three arguments.
byte[]update(byte[] in, int offset, int length)
Processes a designated number of bytes from a given byte array.
abstract byte[]updateDelegate(byte[] in, int off, int len)

Field Detail

DIRECTION

public static final String DIRECTION

inBuffer

protected ByteArrayOutputStream inBuffer

mode

protected Operation mode

outBuffer

protected ByteArrayOutputStream outBuffer

tail

protected Transformer tail

wired

protected Direction wired

Constructor Detail

Transformer

protected Transformer()
Trivial protected constructor.

Method Detail

currentBlockSize

public int currentBlockSize()
Returns the block-size of this Transformer. A value of 1 indicates that this instance is block-agnostic.

Returns: the current minimal required block size.

delegateBlockSize

abstract int delegateBlockSize()

getCascadeTransformer

public static final Transformer getCascadeTransformer(Cascade cascade)

getDeflateTransformer

public static final Transformer getDeflateTransformer()

getPaddingTransformer

public static final Transformer getPaddingTransformer(IPad padding)

init

public void init(Map attributes)
Initialises the Transformer for operation with specific characteristics.

Parameters: attributes a set of name-value pairs that describes the desired future behaviour of this instance.

Throws: IllegalStateException if the instance is already initialised.

initDelegate

abstract void initDelegate(Map attributes)

isPostProcessing

public boolean isPostProcessing()
Returns true if this Transformer was wired in post-processing mode; false otherwise.

Returns: true if this Transformer has been wired in post-processing mode; false otherwise.

Throws: IllegalStateException if this instance has not yet been assigned an operational type.

isPreProcessing

public boolean isPreProcessing()
Returns true if this Transformer was wired in pre-processing mode; false otherwise.

Returns: true if this Transformer has been wired in pre-processing mode; false otherwise.

Throws: IllegalStateException if this instance has not yet been assigned an operational type.

lastUpdate

public byte[] lastUpdate()
Convenience method that calls the same method with three arguments. A zero-long byte array is used.

Returns: the result of transformation.

Throws: IllegalStateException if the instance is not initialised. TransformerException if a transformation-related exception occurs during the operation.

See Also: (byte[], int, int)

lastUpdate

public byte[] lastUpdate(byte b)
Convenience method that calls the method with same name and three arguments, using a byte array of length 1 whose contents are the designated byte.

Parameters: b the byte to process.

Returns: the result of transformation.

Throws: IllegalStateException if the instance is not initialised. TransformerException if a transformation-related exception occurs during the operation.

See Also: (byte[], int, int)

lastUpdate

public byte[] lastUpdate(byte[] in)
Convenience method that calls the same method with three arguments. All bytes in in, starting from index position 0 are considered.

Parameters: in the input data bytes.

Returns: the result of transformation.

Throws: IllegalStateException if the instance is not initialised. TransformerException if a transformation-related exception occurs during the operation.

See Also: (byte[], int, int)

lastUpdate

public byte[] lastUpdate(byte[] in, int offset, int length)
Processes a designated number of bytes from a given byte array and signals, at the same time, that this is the last push operation on this Transformer.

Parameters: in the input data bytes. offset index of in from which to start considering data. length the count of bytes to process.

Returns: the result of transformation.

Throws: IllegalStateException if the instance is not initialised. TransformerException if a transformation-related exception occurs during the operation.

lastUpdateDelegate

abstract byte[] lastUpdateDelegate()

reset

public void reset()
Resets the Transformer for re-initialisation and use with other characteristics. This method always succeeds.

resetDelegate

abstract void resetDelegate()

setMode

public void setMode(Operation mode)
Sets the operational mode of this Transformer.

Parameters: mode the processing mode this Transformer is required to operate in.

Throws: IllegalStateException if this instance has already been assigned an operational mode.

update

public byte[] update(byte b)
Convenience method that calls the method with same name and three arguments, using a byte array of length 1 whose contents are the designated byte.

Parameters: b the byte to process.

Returns: the result of transformation.

Throws: IllegalStateException if the instance is not initialised. TransformerException if a transformation-related exception occurs during the operation.

See Also: (byte[], int, int)

update

public byte[] update(byte[] in)
Convenience method that calls the same method with three arguments. All bytes in in, starting from index position 0 are considered.

Parameters: in the input data bytes.

Returns: the result of transformation.

Throws: IllegalStateException if the instance is not initialised. TransformerException if a transformation-related exception occurs during the operation.

See Also: (byte[], int, int)

update

public byte[] update(byte[] in, int offset, int length)
Processes a designated number of bytes from a given byte array.

Parameters: in the input data bytes. offset index of in from which to start considering data. length the count of bytes to process.

Returns: the result of transformation.

Throws: IllegalStateException if the instance is not initialised. TransformerException if a transformation-related exception occurs during the operation.

updateDelegate

abstract byte[] updateDelegate(byte[] in, int off, int len)
Copyright © 2001, 2002, 2003 Free Software Foundation, Inc. All Rights Reserved.