E-MailRelay
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
G::Md5 Class Reference

MD5 message digest class. More...

#include <gmd5.h>

Classes

struct  digest_state
 Holds the four parts of the md5 state. More...
 
struct  digest_stream_state
 Holds the md5 state plus unprocessed residual data. More...
 

Public Types

using big_t = std::size_t
 
using small_t = std::size_t
 

Public Member Functions

 Md5 ()
 Default constructor. More...
 
 Md5 (const std::string &state)
 Constructor using an intermediate state() string. More...
 
std::string state () const
 Returns the current intermediate state as a 20 character string, although this requires the size of the added data is a multiple of the blocksize(). More...
 
void add (const std::string &data)
 Adds more data. More...
 
std::string value ()
 Returns the hash value as a 16-character string. More...
 
 Md5 (const Md5 &)=delete
 
 Md5 (Md5 &&)=delete
 
void operator= (const Md5 &)=delete
 
void operator= (Md5 &&)=delete
 

Static Public Member Functions

static std::size_t blocksize ()
 Returns the block size in bytes (64). More...
 
static std::size_t valuesize ()
 Returns the value() size in bytes (16). More...
 
static std::size_t statesize ()
 Returns the size of the state() string (20). More...
 
static std::string digest (const std::string &input)
 A convenience function that returns a digest from one input. More...
 
static std::string digest (const std::string &input_1, const std::string &input_2)
 A convenience function that returns a digest from two inputs. More...
 
static std::string digest2 (const std::string &input_1, const std::string &input_2)
 A non-overloaded name for the digest() overload taking two parameters. More...
 
static std::string predigest (const std::string &padded_key)
 A convenience function that add()s the given string of length blocksize() (typically a padded key) and returns the resulting state() truncated to valuesize() characters. More...
 
static std::string postdigest (const std::string &state_pair, const std::string &message)
 A convenience function that returns the value() from an outer digest that is initialised with the second half of the state pair, and with the value() of an inner digest add()ed; the inner digest being initialised with the first half of the state pair, and with the given message add()ed. More...
 

Detailed Description

MD5 message digest class.

Eg:

Md5 h1 ;
std::string x = ... ;
std::string y = ... ;
assert( (x.size() % 64U) == 0 ) ;
h1.add( x ) ;
Md5 h2( h1.state() ) ;
h2.add( y ) ;
assert( h2.value() == Md5::digest(x+y) ) ;
static std::string digest(const std::string &input)
A convenience function that returns a digest from one input.
Definition: gmd5.cpp:535
Md5()
Default constructor.
Definition: gmd5.cpp:493

Definition at line 48 of file gmd5.h.

Member Typedef Documentation

◆ big_t

using G::Md5::big_t = std::size_t

Definition at line 53 of file gmd5.h.

◆ small_t

using G::Md5::small_t = std::size_t

Definition at line 54 of file gmd5.h.

Constructor & Destructor Documentation

◆ Md5() [1/2]

G::Md5::Md5 ( )

Default constructor.

Definition at line 493 of file gmd5.cpp.

◆ Md5() [2/2]

G::Md5::Md5 ( const std::string &  state)
explicit

Constructor using an intermediate state() string.

Precondition: state.size() == 20

Definition at line 498 of file gmd5.cpp.

Member Function Documentation

◆ add()

void G::Md5::add ( const std::string &  data)

Adds more data.

Definition at line 510 of file gmd5.cpp.

◆ blocksize()

std::size_t G::Md5::blocksize ( )
static

Returns the block size in bytes (64).

Definition at line 580 of file gmd5.cpp.

◆ digest() [1/2]

std::string G::Md5::digest ( const std::string &  input)
static

A convenience function that returns a digest from one input.

Definition at line 535 of file gmd5.cpp.

◆ digest() [2/2]

std::string G::Md5::digest ( const std::string &  input_1,
const std::string &  input_2 
)
static

A convenience function that returns a digest from two inputs.

Definition at line 541 of file gmd5.cpp.

◆ digest2()

std::string G::Md5::digest2 ( const std::string &  input_1,
const std::string &  input_2 
)
static

A non-overloaded name for the digest() overload taking two parameters.

Definition at line 549 of file gmd5.cpp.

◆ postdigest()

std::string G::Md5::postdigest ( const std::string &  state_pair,
const std::string &  message 
)
static

A convenience function that returns the value() from an outer digest that is initialised with the second half of the state pair, and with the value() of an inner digest add()ed; the inner digest being initialised with the first half of the state pair, and with the given message add()ed.

The result is a string of 32 non-printing characters. Throws InvalidState if the state-pair string is not valid.

Definition at line 562 of file gmd5.cpp.

◆ predigest()

std::string G::Md5::predigest ( const std::string &  padded_key)
static

A convenience function that add()s the given string of length blocksize() (typically a padded key) and returns the resulting state() truncated to valuesize() characters.

Definition at line 554 of file gmd5.cpp.

◆ state()

std::string G::Md5::state ( ) const

Returns the current intermediate state as a 20 character string, although this requires the size of the added data is a multiple of the blocksize().

Note that the trailing 4 characters represent the total size of the added data.

See also
G::HashState

Definition at line 504 of file gmd5.cpp.

◆ statesize()

std::size_t G::Md5::statesize ( )
static

Returns the size of the state() string (20).

Definition at line 590 of file gmd5.cpp.

◆ value()

std::string G::Md5::value ( )

Returns the hash value as a 16-character string.

No more add()s are allowed. The resulting string is not generally printable and it may have embedded nulls.

See also
G::HashState, G::Hash::printable().

Definition at line 525 of file gmd5.cpp.

◆ valuesize()

std::size_t G::Md5::valuesize ( )
static

Returns the value() size in bytes (16).

Definition at line 585 of file gmd5.cpp.


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