|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.helidb.lang.hasher.AbstractMessageDigestStringHasher<H>
public abstract class AbstractMessageDigestStringHasher<H extends Comparable<H>>
This is an abstract base class for String
Hasher
:s that use a
MessageDigest
to produce the hash.
Field Summary | |
---|---|
static String |
DEFAULT_ALGORITHM
The default hash algorithm. |
Constructor Summary | |
---|---|
protected |
AbstractMessageDigestStringHasher(String hashAlgorithm,
int hashLength,
int noOfBitsInMostSignificantByte)
Create an instance of the hasher. |
protected |
AbstractMessageDigestStringHasher(String hashAlgorithm,
int hashLength,
int noOfBitsInMostSignificantByte,
String provider,
Charset cs)
Create an instance of the hasher. |
Method Summary | |
---|---|
protected void |
assertNoMaskedBitsSet(byte b)
|
protected byte[] |
createDigest(String s)
Create a digest for the supplied string. |
int |
getHashLength()
Get the size of the hash in bytes. |
H |
hash(String s)
This implementation creates a digest and then uses the Hasher.fromBytes(byte[]) method to create a byte array to return. |
boolean |
isPreservingValues()
Does the hashing operation not modify the hashed value at all? This is true if v.equals(hasher.hash(v)) for all values v
accepted by the hasher. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.helidb.lang.hasher.Hasher |
---|
fromBytes, toBytes |
Field Detail |
---|
public static final String DEFAULT_ALGORITHM
Constructor Detail |
---|
protected AbstractMessageDigestStringHasher(String hashAlgorithm, int hashLength, int noOfBitsInMostSignificantByte) throws IllegalArgumentException
Charset
used for creating the hash is the platform's default
charset.
hashAlgorithm
- The name of the hash algorithm. This should be the
name of an hash algorithm implemented by one of the JVM's registered
security providers.hashLength
- The length of hashes created by this object.noOfBitsInMostSignificantByte
- The number of bits to keep in the
most significant byte. The bits kept are the least significant bits. If
this is set to 7, the most significant bit is discarded. If set to 6, the
two most significant bits are discarded, etc.
IllegalArgumentException
- If the hash length is less than 1 or if
the number of bits value is invalid.protected AbstractMessageDigestStringHasher(String hashAlgorithm, int hashLength, int noOfBitsInMostSignificantByte, String provider, Charset cs) throws IllegalArgumentException
Charset
is used for
creating the hash.
hashAlgorithm
- The name of the hash algorithm. This should be the
name of an hash algorithm implemented by the specified security provider.hashLength
- The length of hashes created by this object.noOfBitsInMostSignificantByte
- The number of bits to keep in the
most significant byte. The bits kept are the least significant bits. If
this is set to 7, the most significant bit is discarded. If set to 6, the
two most significant bits are discarded, etc.provider
- The security provider that implements the hash algorithm.
If this is null
, the default provider lookup mechanism is used.cs
- The Charset
used for creating the hash. If this is
null
, the platform's default Charset
is used.
IllegalArgumentException
- If the hash length is less than 1 or if
the number of bits value is invalid.Method Detail |
---|
public int getHashLength()
Hasher
byte
array created by Hasher.toBytes(Comparable)
and accepted by
Hasher.fromBytes(byte[])
.
getHashLength
in interface Hasher<String,H extends Comparable<H>>
public boolean isPreservingValues()
Hasher
true
if v.equals(hasher.hash(v))
for all values v
accepted by the hasher.
isPreservingValues
in interface Hasher<String,H extends Comparable<H>>
false
, always.protected void assertNoMaskedBitsSet(byte b) throws IllegalArgumentException
IllegalArgumentException
protected byte[] createDigest(String s)
s
- The string to create a digest for-
public H hash(String s)
Hasher.fromBytes(byte[])
method to create a byte array to return.
hash
in interface Hasher<String,H extends Comparable<H>>
s
- The value to hash.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |