Add MD5_HASH::Format for debug purposes.

This commit is contained in:
jean-pierre charras 2019-03-21 11:41:37 +01:00
parent a7c8df5666
commit ecb168f7a7
2 changed files with 32 additions and 0 deletions

View File

@ -92,6 +92,32 @@ bool MD5_HASH::operator!=( const MD5_HASH& aOther ) const
}
std::string MD5_HASH::Format()
{
std::string data;
// Build a hexadecimal string from the 16 bytes of MD5_HASH:
for( int ii = 0; ii < 16; ++ii )
{
char lsb = ( m_hash[ii] & 0x0F ) + '0';
if( lsb > '9' )
lsb += 'A'-'9';
char msb = ( ( m_hash[ii] >> 4 ) & 0x0F ) + '0';
if( msb > '9' )
msb += 'A'-'9';
data += msb;
data += lsb;
data += ' ';
}
return data;
}
void MD5_HASH::md5_transform(MD5_CTX *ctx, uint8_t data[])
{
uint32_t a,b,c,d,m[16],i,j;

View File

@ -6,6 +6,7 @@
#define __MD5_HASH_H
#include <cstdint>
#include <string>
class MD5_HASH
{
@ -29,6 +30,11 @@ public:
bool operator==( const MD5_HASH& aOther ) const;
bool operator!=( const MD5_HASH& aOther ) const;
/** @return Build a hexadecimal string from the 16 bytes of MD5_HASH
* Mainly for debug purposes.
*/
std::string Format();
private:
struct MD5_CTX {
uint8_t data[64];