org.logi.crypto.sign
Class HashState

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.sign.HashState
Direct Known Subclasses:
MD5State, SHA1State

public abstract class HashState
extends Crypto

An subclasses of this object handle the status of a fingerprint still being calculated.

Instances can be continually updated with data and at any point a Fingerprint for the data added so far can be requested.

Version:
1.0.6
Author:
Logi Ragnarsson (logir@logi.org)
See Also:
Fingerprint

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Constructor Summary
HashState()
           
 
Method Summary
abstract  int blockSize()
          Return the size of input-blocks for this hash function in bytes.
abstract  Fingerprint calculate()
          Return a fingerprint for the curret state, without destroying the state.
static HashState create()
          Create a HashState object for the default hash function.
static HashState create(java.lang.String algorithm)
          Create a HashState object for the named hash function.
static java.lang.String getDefaultHashFunction()
          Returns the default hash-function.
abstract  java.lang.String getName()
          Return the name of the algorithm used by this HashState object.
abstract  int hashSize()
          Returns the size of a fingerprint in bytes.
abstract  void reset()
          Reset the state.
static void setDefaultHashFunction(java.lang.String algorithm)
          Sets the default hash-function.
 void update(byte[] buf)
          Update the hash state with the bytes from buf.
abstract  void update(byte[] buf, int offset, int length)
          Update the hash state with the bytes from buf[offset, offset+length-1].
 void update(java.lang.String s)
          Update the hash state with the characters from s.
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, ensureArrayLength, ensureArrayLength, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, prettyPrint, prettyPrint, readBlock, readInt, trimArrayLength, trimArrayLength, trimLeadingZeroes, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashState

public HashState()
Method Detail

create

public static HashState create(java.lang.String algorithm)
                        throws InvalidCDSException
Create a HashState object for the named hash function.
Throws:
InvalidCDSException - if a HashState object for the named algorithm could not be created.

create

public static HashState create()
Create a HashState object for the default hash function.

setDefaultHashFunction

public static void setDefaultHashFunction(java.lang.String algorithm)
                                   throws InvalidCDSException
Sets the default hash-function. It must be the name of a supported hash function, such as SHA1 or MD5.

Note that changing this will invalidate all values previously returned by the hash() method of objects which generate the hash from a cryptographic fingerprint of themselves. This call should preferably be made before any such hash vlaues are returned, f.ex. in KeyRing objects.

Throws:
InvalidCDSException - if a HashState object for the named algorithm could not be created.

getDefaultHashFunction

public static java.lang.String getDefaultHashFunction()
Returns the default hash-function.

getName

public abstract java.lang.String getName()
Return the name of the algorithm used by this HashState object.

reset

public abstract void reset()
Reset the state.

update

public abstract void update(byte[] buf,
                            int offset,
                            int length)
Update the hash state with the bytes from buf[offset, offset+length-1].

update

public void update(byte[] buf)
Update the hash state with the bytes from buf.

update

public void update(java.lang.String s)
Update the hash state with the characters from s.

calculate

public abstract Fingerprint calculate()
Return a fingerprint for the curret state, without destroying the state.

blockSize

public abstract int blockSize()
Return the size of input-blocks for this hash function in bytes.

hashSize

public abstract int hashSize()
Returns the size of a fingerprint in bytes.


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL