NAbstractHash Class Reference

NAbstractHash class is the base class definition for hash calculation classes. More...

Inheritance diagram for NAbstractHash:

NObject NMd2Hash NMd4Hash NMd5Hash NSha1Hash NShaHash

List of all members.

Public Member Functions

 NAbstractHash (void)
 Constructs a NAbstractHash object.
virtual ~NAbstractHash (void)
 Destroys a NAbstractHash object.
virtual NHash calculate (const NString &str)=0
 Calculates the hash of a given string.
virtual NHash calculate (const NDataStream &data, nint32 size)=0
 Calculates the hash of arbitrary data.
virtual NHash calculateFile (const NString &filename)=0
 Calculates the hash of a file.
virtual NHash calculateFile (NFile *file)=0
 Calculates the hash of a file.
bool match (const NString &str, const NString &hash)
 Tests whether a string matches a given hash.
bool match (const NString &str, const NHash &hash)
 Tests whether a string matches a given hash.
bool match (NFile *file, const NString &hash)
 Tests whether a file matches a given hash.
bool match (NFile *file, const NHash &hash)
 Tests whether a file matches a given hash.

Protected Member Functions

void init (const NString &hash_name)
 Initialiazes the hash structures.
int update (const void *data, int bytes)
 Updates the hash structures by computing the hash of more data.
NString cleanup (void)
 Clear the hash structures and return the result.
void setHashBufferSize (int size)
 Sets the size of the internal buffer used to calculate the hash.
int getHashBufferSize (void) const
 Gets the size of the internal buffer used to calculate the hash.


Detailed Description

NAbstractHash class is the base class definition for hash calculation classes.
Examples:

hashapp.cpp.

Definition at line 48 of file nabstracthash.h.


Member Function Documentation

virtual NHash calculate ( const NString str  )  [pure virtual]

Calculates the hash of a given string.

Parameters:
str The string to calculate the hash
Returns:
A NHash object with the value of the string

Implemented in NMd2Hash, NMd4Hash, NMd5Hash, NSha1Hash, and NShaHash.

Referenced by match().

virtual NHash calculate ( const NDataStream data,
nint32  size 
) [pure virtual]

Calculates the hash of arbitrary data.

Parameters:
data The data to be calculated
size Number of bytes to calculate the hash
Returns:
A NHash object with the value of the string

Implemented in NMd2Hash, NMd4Hash, NMd5Hash, NSha1Hash, and NShaHash.

virtual NHash calculateFile ( const NString filename  )  [pure virtual]

Calculates the hash of a file.

Parameters:
filename The full path to the file to calculate
Returns:
A NHash object with the value of the string

Implemented in NMd2Hash, NMd4Hash, NMd5Hash, NSha1Hash, and NShaHash.

Referenced by match().

virtual NHash calculateFile ( NFile file  )  [pure virtual]

Calculates the hash of a file.

Parameters:
file A pointer to an open NFile object
Returns:
A NHash object with the value of the string

Implemented in NMd2Hash, NMd4Hash, NMd5Hash, NSha1Hash, and NShaHash.

bool match ( const NString str,
const NString hash 
)

Tests whether a string matches a given hash.

Parameters:
str The string to be tested
hash The hash to be tested in string format
Returns:
true if the string matches the hash or false otherwise

Definition at line 106 of file nabstracthash.cpp.

References calculate().

bool match ( const NString str,
const NHash hash 
)

Tests whether a string matches a given hash.

Parameters:
str The string to be tested
hash The hash to be tested
Returns:
true if the string matches the hash or false otherwise

Definition at line 115 of file nabstracthash.cpp.

References calculate().

bool match ( NFile file,
const NString hash 
)

Tests whether a file matches a given hash.

Parameters:
file A pointer to an open NFile object
hash The hash to be tested in string format
Returns:
true if the string matches the hash or false otherwise

Definition at line 123 of file nabstracthash.cpp.

References calculateFile().

bool match ( NFile file,
const NHash hash 
)

Tests whether a file matches a given hash.

Parameters:
file A pointer to an open NFile object
hash The hash to be tested
Returns:
true if the string matches the hash or false otherwise

Definition at line 134 of file nabstracthash.cpp.

References calculateFile().

void init ( const NString hash_name  )  [protected]

Initialiazes the hash structures.

Parameters:
hash_name The name of the hash
Note:
Acceptable values for hash_name: md2, md4, md5, sha, sha1, rmd160 (class not implemented)

Definition at line 39 of file nabstracthash.cpp.

References NSTR(), NException::SECURITY, and NString::toChar().

Referenced by NMd2Hash::NMd2Hash(), NMd4Hash::NMd4Hash(), NMd5Hash::NMd5Hash(), NSha1Hash::NSha1Hash(), and NShaHash::NShaHash().

int update ( const void *  data,
int  bytes 
) [protected]

Updates the hash structures by computing the hash of more data.

Parameters:
data The data to be computed
bytes Number of bytes to compute
Returns:
The number of bytes computed

Definition at line 55 of file nabstracthash.cpp.

Referenced by NShaHash::calculate(), NSha1Hash::calculate(), NMd5Hash::calculate(), NMd4Hash::calculate(), NMd2Hash::calculate(), NShaHash::calculateFile(), NSha1Hash::calculateFile(), NMd5Hash::calculateFile(), NMd4Hash::calculateFile(), and NMd2Hash::calculateFile().

NString cleanup ( void   )  [protected]

Clear the hash structures and return the result.

Returns:
The resulting hash as a pointer to a NULL terminated structure

Definition at line 63 of file nabstracthash.cpp.

Referenced by NShaHash::calculate(), NSha1Hash::calculate(), NMd5Hash::calculate(), NMd4Hash::calculate(), NMd2Hash::calculate(), NShaHash::calculateFile(), NSha1Hash::calculateFile(), NMd5Hash::calculateFile(), NMd4Hash::calculateFile(), and NMd2Hash::calculateFile().

void setHashBufferSize ( int  size  )  [protected]

Sets the size of the internal buffer used to calculate the hash.

Parameters:
size The size of the internal buffer

Definition at line 145 of file nabstracthash.cpp.

Referenced by NMd2Hash::NMd2Hash(), NMd4Hash::NMd4Hash(), NMd5Hash::NMd5Hash(), NSha1Hash::NSha1Hash(), and NShaHash::NShaHash().

int getHashBufferSize ( void   )  const [protected]

Gets the size of the internal buffer used to calculate the hash.

Returns:
The size of the internal buffer

Definition at line 150 of file nabstracthash.cpp.


The documentation for this class was generated from the following files:
Generated on Wed Mar 5 23:10:36 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4