MuldeR's Utilities for Qt MUtilities

Public Member Functions | Protected Member Functions | List of all members
MUtils::Hash::Hash Class Referenceabstract

This abstract class specifies the generic interface for all support hash algorithms. More...

`#include <Hash.h>`

## Public Member Functions
bool | update (const quint8 *const data, const quint32 len)
| Process the next chunk of input data. More...
bool | update (const QByteArray &data)
| Process the next chunk of input data. More...
bool | update (QFile &file)
| Process the next chunk of input data. More...
QByteArray | digest (const bool bAsHex=true)
| Retrieve the hash value. More...

## Protected Member Functions
| Hash (const char *key=NULL)
virtual bool | process (const quint8 *const data, const quint32 len)=0
virtual QByteArray | finalize (void)=0

## Detailed Description

This abstract class specifies the generic interface for all support hash algorithms.

In order to compute a hash value (digest) call the the Hash::update() function repeatedly until all input data (i.e. the complete "message") has been processed. Then call the Hash::digest() function to retrieve the final hash value.

All overloads of the Hash::update() function may be called in an interleaved fashion as needed.

This class is not thread-safe, i.e. do not call the same Hash instance from difference threads, unless serialization is ensured (e.g. by means of a Mutex). It is safe, however, to call different different Hash instances from difference threads concurrently.

## Member Function Documentation

## § digest()

QByteArray MUtils::Hash::Hash::digest | ( | const bool | bAsHex = `true` | ) |
| inline

Retrieve the hash value.

This function is used to retrieve the final hash value (digest), after all input data has been processed successfully.

Parameters

  bAsHex | If set to `true`, the function returns the hash value as a Hexadecimal-encoded ASCII string; if set to `false`, the function returns the hash value as "raw" bytes.

Returns
  The function returns a QByteArray object holding the final hash value (digest). The format depends on the `bAsHex` parameter.

## § update() [1/3]

bool MUtils::Hash::Hash::update | ( | const quint8 *const | data,
|  | const quint32 | len
| ) |  |
| inline

Process the next chunk of input data.

Updates the internal state of the hash function by processing the next chunk of input that. Can be called repeatedly, until until all input data has been processed.

Parameters

  data | A read-only pointer to the memory buffer holding the input data to be processed.
  len | The length of the input data, in bytes. The `data` parameter must be pointing to a memory buffer that is at least `len` bytes in size.

Returns
  The function returns `true`, if the input data was processed successfully; otherwise it returns `false`.

## § update() [2/3]

bool MUtils::Hash::Hash::update | ( | const QByteArray & | data | ) |
| inline

Process the next chunk of input data.

Updates the internal state of the hash function by processing the next chunk of input that. Can be called repeatedly, until until all input data has been processed.

Parameters

  data | A read-only reference to a QByteArray object holding the input data to be processed. All bytes in the QByteArray object will be processed.

Returns
  The function returns `true`, if the input data was processed successfully; otherwise it returns `false`.

## § update() [3/3]

bool MUtils::Hash::Hash::update | ( | QFile & | file | ) |

Process the next chunk of input data.

Updates the internal state of the hash function by processing the next chunk of input that. Can be called repeatedly, until until all input data has been processed.

Parameters

  data | A reference to a QFile object. The QFile object must be open and readable. All data from the current file position to the end of the file will be processed.

Returns
  The function returns `true`, if all data in the file was processed successfully; otherwise (e.g. in case of file read errors) it returns `false`.

The documentation for this class was generated from the following file:

- include/MUtils/Hash.h