LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Namespaces | Enumerations | Functions
LogCabin::Core::Checksum Namespace Reference

Namespaces

namespace  anonymous_namespace{Checksum.cc}

Enumerations

enum  { MAX_LENGTH }
 The number of bytes any checksum algorithm name and digest may occupy. More...

Functions

std::vector< std::string > listAlgorithms ()
 Returns the names of all available hash functions.
uint32_t calculate (const char *algorithm, const void *data, uint64_t dataLength, char output[MAX_LENGTH])
 Calculate the checksum for a chunk of data.
uint32_t calculate (const char *algorithm, std::initializer_list< std::pair< const void *, uint64_t >> data, char output[MAX_LENGTH])
 Calculate the checksum for a chunk of data.
uint32_t length (const char *checksum, uint32_t maxChecksumLength)
 Check to see if the checksum format looks plausible.
std::string verify (const char *checksum, const void *data, uint64_t dataLength)
 Verify data against an existing checksum.
std::string verify (const char *checksum, std::initializer_list< std::pair< const void *, uint64_t >> data)
 Verify data against an existing checksum.

Enumeration Type Documentation

anonymous enum

The number of bytes any checksum algorithm name and digest may occupy.

Enumerator:
MAX_LENGTH 

Definition at line 35 of file Checksum.h.


Function Documentation

std::vector< std::string > LogCabin::Core::Checksum::listAlgorithms ( )

Returns the names of all available hash functions.

You can use any of these names in the calculate function.

Returns:
The names in sorted order.

Definition at line 189 of file Checksum.cc.

uint32_t LogCabin::Core::Checksum::calculate ( const char *  algorithm,
const void *  data,
uint64_t  dataLength,
char  output[MAX_LENGTH] 
)

Calculate the checksum for a chunk of data.

Parameters:
algorithmThe checksum algorithm to use. Most crypto++ hash algorithms may be used, for example, "SHA-256". This function will PANIC if the algorithm is not available (see listAlgorithms()).
dataThe first byte of the data.
dataLengthThe number of bytes in the data.
[out]outputThe result of the hash function will be placed here. This will be a null-terminated, printable C-string.
Returns:
The number of valid characters in 'output', including the null terminator. This is guaranteed to be greater than 1.

Definition at line 195 of file Checksum.cc.

uint32_t LogCabin::Core::Checksum::calculate ( const char *  algorithm,
std::initializer_list< std::pair< const void *, uint64_t >>  data,
char  output[MAX_LENGTH] 
)

Calculate the checksum for a chunk of data.

Parameters:
algorithmThe checksum algorithm to use. Most crypto++ hash algorithms may be used, for example, "SHA-256". This function will PANIC if the algorithm is not available (see listAlgorithms()).
dataAn list of (pointer, length) pairs describing what to checksum.
[out]outputThe result of the hash function will be placed here. This will be a null-terminated, printable C-string.
Returns:
The number of valid characters in 'output', including the null terminator. This is guaranteed to be greater than 1.

Definition at line 203 of file Checksum.cc.

uint32_t LogCabin::Core::Checksum::length ( const char *  checksum,
uint32_t  maxChecksumLength 
)

Check to see if the checksum format looks plausible.

Parameters:
checksumWhat might be a checksum as generated by calculate().
maxChecksumLengthThe total number of bytes in the buffer containing checksum, including the null terminator (if any).
Returns:
If 'checksum' looks plausible and is safe to pass to verify(), returns the number of bytes in 'checksum' up to and including its null terminator. If 'checksum' looks malformed, this returns 0, which the caller should treat as a corrupt checksum.

Definition at line 217 of file Checksum.cc.

std::string LogCabin::Core::Checksum::verify ( const char *  checksum,
const void *  data,
uint64_t  dataLength 
)

Verify data against an existing checksum.

Parameters:
checksumA null-terminated checksum returned from calculate() or whose format has been verified by length(). The algorithm name in this checksum will determine which checksumming algorithm to use.
dataThe first byte of the data.
dataLengthThe number of bytes in the data.
Returns:
An empty string if the checksum matches, or an error string if the checksum does not match or the checksum algorithm is not available.

Definition at line 232 of file Checksum.cc.

std::string LogCabin::Core::Checksum::verify ( const char *  checksum,
std::initializer_list< std::pair< const void *, uint64_t >>  data 
)

Verify data against an existing checksum.

Parameters:
checksumA null-terminated checksum returned from calculate() or whose format has been verified by length(). The algorithm name in this checksum will determine which checksumming algorithm to use.
dataAn list of (pointer, length) pairs describing what to checksum.
Returns:
An empty string if the checksum matches, or an error string if the checksum does not match or the checksum algorithm is not available.

Definition at line 239 of file Checksum.cc.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines