Aria  2.8.0
ArMD5Calculator Class Reference

Calculates the MD5 checksum when reading or writing a text file using ArFunctors. More...

#include <ArMD5Calculator.h>

Public Types

enum  { DIGEST_LENGTH = 16, DISPLAY_LENGTH = (DIGEST_LENGTH * 2) + 1 }
 

Public Member Functions

void append (const char *str)
 Calculates the checksum for the given text line, and accumulates the results.
 
 ArMD5Calculator (ArFunctor1< const char *> *secondFunctor=NULL)
 Creates a new calculator, with an optional functor. More...
 
unsigned char * getDigest ()
 Returns a pointer to the internal buffer that accumulates the checksum results.
 
ArFunctor1< const char * > * getFunctor ()
 Returns the internal functor used to calculate the checksum. More...
 
ArFunctor1< const char * > * getSecondFunctor ()
 Returns the optional secondary functor to be called on each text line.
 
void reset ()
 Resets the calculator so that a new checksum can be calculated.
 
void setSecondFunctor (ArFunctor1< const char *> *secondFunctor)
 Sets the optional secondary functor to be called on each text line.
 
 ~ArMD5Calculator ()
 Destructor.
 

Static Public Member Functions

static bool calculateChecksum (const char *fileName, unsigned char *md5DigestBuffer, size_t md5DigestBufferLen)
 Calculates the checksum for the specified file. More...
 
static void toDisplay (const unsigned char *digestBuf, size_t digestLength, char *displayBuf, size_t displayLength)
 Converts the given checksum buffer to a displayable text string. More...
 

Detailed Description

Calculates the MD5 checksum when reading or writing a text file using ArFunctors.

ArMD5Calculator is a small helper class used to calculate MD5 checksums on text files. It contains a static method that will calculate the checksum of a given file, independently performing all I/O.

The calculator also contains a functor that can be used to calculate a checksum interactively. For example, it can accumulate the checksum while a file is being written using a writeToFunctor method. If the optional second functor is specified, then it will be invoked after the checksum functor.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
DIGEST_LENGTH 

Number of bytes in the checksum buffer.

DISPLAY_LENGTH 

Number of characters needed to display the checksum.

Constructor & Destructor Documentation

◆ ArMD5Calculator()

ArMD5Calculator::ArMD5Calculator ( ArFunctor1< const char *> *  secondFunctor = NULL)

Creates a new calculator, with an optional functor.

Parameters
secondFunctorthe optional functor to be invoked on the current text string after its checksum has been calculated

Member Function Documentation

◆ calculateChecksum()

bool ArMD5Calculator::calculateChecksum ( const char *  fileName,
unsigned char *  md5DigestBuffer,
size_t  md5DigestBufferLen 
)
static

Calculates the checksum for the specified file.

Parameters
fileNamethe name of the file of which to calculate the checksum
md5DigestBuffera pointer to the output buffer in which to store the calculated checksum
md5DigestBufferLenthe length of the md5DigestBuffer; should be DIGEST_LENGTH
Returns
bool true if the file was successfully opened and the checksum calculated; false, otherwise

◆ getFunctor()

ArFunctor1< const char * > * ArMD5Calculator::getFunctor ( )

Returns the internal functor used to calculate the checksum.

If the calculator is being used interactively with writeToFunctor, then this is the functor to use. It calls append on each text line which accumulates the checksum and calls the second functor if necessary.

◆ toDisplay()

void ArMD5Calculator::toDisplay ( const unsigned char *  digestBuf,
size_t  digestLength,
char *  displayBuf,
size_t  displayLength 
)
static

Converts the given checksum buffer to a displayable text string.

Parameters
digestBufa pointer to the byte array that contains the checksum
digestLengththe length of the disgestBuf; should be DIGEST_LENGTH
displayBufa pointer to the output text buffer that will contain the displayable text string
displayLengththe length of the displayBuf; should be at least DISPLAY_LENGTH

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