ostore.util
Interface SecureHash

All Superinterfaces:
Cloneable, Comparable, Digestible, QuickSerializable
All Known Implementing Classes:
SHA1Hash

public interface SecureHash
extends Cloneable, Comparable, Digestible

SecureHash is the interface used to represent classes which are secure hashes An example is the SHA1 hash

Version:
$Id: SecureHash.java,v 1.10 2002/04/06 22:52:44 eaton Exp $
Author:
Chris WElls

Method Summary
 byte[] bytes()
          Returns the bytes contained in this hash
 void calculate(byte[] bytes, SecureVerify verify)
          This routine calculates the root hash for a given object and its slice of its verification tree (basically, this routine does what verify does, but instead of comparing the last hash to this hash and returning the result, it sets this hash's value to the last hash's value)
 void calculate(QuickSerializable qs, SecureVerify verify)
          This routine calculates the root hash for a given object and its slice of its verification tree (basically, this routine does what verify does, but instead of comparing the last hash to this hash and returning the result, it sets this hash's value to the last hash's value)
 Object clone()
          This is the clone routine for Fragment.
 boolean equals(Object o)
          Compares this SecureHash with another hash, and returns true iff they are the same type of hash and have the same byte representation
 String fullString()
          Converts all bytes of this SecureHash to a human-readable String
 void hash(byte[] bytes)
          Hashes over the input bytes
 SecureVerify[] hash(byte[][] array)
          Creates a hierarchical hash over an array of byte arrays, and returns an array of SecureVerifiers, the i^th element of which contains the hashes along the tree of hashes to the root hash for the i^th byte array in the input array; This hash is set to the value of that root.
 void hash(byte[] bytes, int offset, int len)
          Hashes over the input bytes, starting at offset, going for len
 void hash(Digestible o)
          Hashes over a Digestible object
 SecureVerify[] hash(QuickSerializable[] array)
          Creates a hierarchical hash over an array of objects, and returns an array of SecureVerifiers, the i^th element of which contains the hashes along the tree of hashes to the root hash for the i^th byte array in the input array; This hash is set to the value of that root.
 void hash(String str)
          Hashes over the bytes of the input String
 int hashCode()
          Calculates a Java hash code for this SecureHash object (typically by taking its lower order bytes)
 boolean isNull()
          Determines if this SecureHash is a NULL hash or not.
 SecureHash nullHash()
          Returns the implementation's NULL hash (typically all zeroes).
 int size()
          Return the number of bytes used in the representation of this hash (for example, SHA1 uses 20 bytes)
 String toString()
          Converts a few bytes of this SecureHash to a human-readable String
 boolean verify(byte[] bytes)
          Verifies that the input bytes hash to this hash value
 boolean verify(byte[] bytes, int offset, int len)
          Verifies that the input bytes hash to this hash value
 boolean verify(byte[] bytes, SecureVerify verify)
          Verifies that the input byte array, coupled with the input verification information, hashes to this hash's value
 boolean verify(Digestible o)
          Verifies a Digestible object
 boolean verify(QuickSerializable o, SecureVerify verify)
          Verifies that the input object, coupled with the input verification information, hashes to this hash's value
 boolean verify(String str)
          Verifies the input String
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface ostore.util.Digestible
add_to_digest
 
Methods inherited from interface ostore.util.QuickSerializable
to_bytes, type_code
 

Method Detail

size

public int size()
Return the number of bytes used in the representation of this hash (for example, SHA1 uses 20 bytes)
Returns:
number of bytes used in the implementation

isNull

public boolean isNull()
Determines if this SecureHash is a NULL hash or not.
Returns:
true iff this Hash has a NULL value

nullHash

public SecureHash nullHash()
Returns the implementation's NULL hash (typically all zeroes).
Returns:
the implementation's null hash

bytes

public byte[] bytes()
Returns the bytes contained in this hash
Returns:
the bytes of this hash

equals

public boolean equals(Object o)
Compares this SecureHash with another hash, and returns true iff they are the same type of hash and have the same byte representation
Overrides:
equals in class Object
Parameters:
o - the object with which to compare this SecureHash
Returns:
true iff this and o contain the same byte values

hashCode

public int hashCode()
Calculates a Java hash code for this SecureHash object (typically by taking its lower order bytes)
Overrides:
hashCode in class Object
Returns:
the Java hash code for this SecureHash

hash

public void hash(byte[] bytes,
                 int offset,
                 int len)
Hashes over the input bytes, starting at offset, going for len
Parameters:
bytes - byte array over which to hash
offset - offset in bytes[] at which to begin hashing
len - number of bytes over which to hash

hash

public void hash(byte[] bytes)
Hashes over the input bytes
Parameters:
bytes - byte array over which to hash

hash

public void hash(Digestible o)
Hashes over a Digestible object
Parameters:
o - the object over which to hash

hash

public void hash(String str)
Hashes over the bytes of the input String
Parameters:
str - the String over which to hash

hash

public SecureVerify[] hash(byte[][] array)
Creates a hierarchical hash over an array of byte arrays, and returns an array of SecureVerifiers, the i^th element of which contains the hashes along the tree of hashes to the root hash for the i^th byte array in the input array; This hash is set to the value of that root.
Parameters:
array - array of byte arrays
Returns:
array of arrays of verification information

hash

public SecureVerify[] hash(QuickSerializable[] array)
Creates a hierarchical hash over an array of objects, and returns an array of SecureVerifiers, the i^th element of which contains the hashes along the tree of hashes to the root hash for the i^th byte array in the input array; This hash is set to the value of that root.
Parameters:
array - array of byte arrays
Returns:
array of arrays of verification information

verify

public boolean verify(byte[] bytes,
                      int offset,
                      int len)
Verifies that the input bytes hash to this hash value
Parameters:
bytes - byte array containing the bytes to verify
offset - offset in bytes[] at which to begin hashing
len - number of bytes over which to hash
Returns:
true iff the input bytes hash to a hash value equal to this hash value

verify

public boolean verify(byte[] bytes)
Verifies that the input bytes hash to this hash value
Parameters:
bytes - byte array to verify
Returns:
true iff the input bytes hash to a hash value equal to this hash value

verify

public boolean verify(Digestible o)
Verifies a Digestible object
Parameters:
o - the object over which to hash
Returns:
true iff the input object hashes to a hash value equal to this hash value

verify

public boolean verify(String str)
Verifies the input String
Parameters:
str - the String to verify
Returns:
true iff the input String hashes to a hash value equal to this hash value

verify

public boolean verify(byte[] bytes,
                      SecureVerify verify)
Verifies that the input byte array, coupled with the input verification information, hashes to this hash's value
Parameters:
bytes - bytes to verify
verify - verification information to use to verify bytes
Returns:
true iff the bytes hash to the value contained in this hash

verify

public boolean verify(QuickSerializable o,
                      SecureVerify verify)
Verifies that the input object, coupled with the input verification information, hashes to this hash's value
Parameters:
o - object to verify
verify - verification information to use to verify bytes
Returns:
true iff object hashes to the value contained in this hash

calculate

public void calculate(byte[] bytes,
                      SecureVerify verify)
This routine calculates the root hash for a given object and its slice of its verification tree (basically, this routine does what verify does, but instead of comparing the last hash to this hash and returning the result, it sets this hash's value to the last hash's value)
Parameters:
bytes - bytes to calc a root hash for
verify - verification information to use in the calculation

calculate

public void calculate(QuickSerializable qs,
                      SecureVerify verify)
This routine calculates the root hash for a given object and its slice of its verification tree (basically, this routine does what verify does, but instead of comparing the last hash to this hash and returning the result, it sets this hash's value to the last hash's value)
Parameters:
qs - object to calc a root hash for
verify - verification information to use in the calculation

toString

public String toString()
Converts a few bytes of this SecureHash to a human-readable String
Overrides:
toString in class Object
Returns:
human-readable String representation of this Hash

fullString

public String fullString()
Converts all bytes of this SecureHash to a human-readable String
Returns:
human-readable String representation of this Hash containing every nibble of this Hash's value

clone

public Object clone()
             throws CloneNotSupportedException
This is the clone routine for Fragment. It deeply clones a fragment (meaning that it copies all of the data, not just references).
Overrides:
clone in class Object