Leviathan  0.8.0.0
Leviathan game engine
Leviathan::MD5 Class Reference

#include <MD5Generator.h>

Public Types

typedef unsigned int size_type
 

Public Member Functions

DLLEXPORT MD5 ()
 
DLLEXPORT MD5 (const std::string &text)
 
DLLEXPORT void update (const unsigned char *buf, size_type length)
 
DLLEXPORT void update (const char *buf, size_type length)
 
DLLEXPORT MD5finalize ()
 
DLLEXPORT std::string hexdigest () const
 

Friends

std::ostream & operator<< (std::ostream &, MD5 md5)
 

Detailed Description

Definition at line 55 of file MD5Generator.h.

Member Typedef Documentation

◆ size_type

typedef unsigned int Leviathan::MD5::size_type

Definition at line 57 of file MD5Generator.h.

Constructor & Destructor Documentation

◆ MD5() [1/2]

MD5::MD5 ( )

Definition at line 106 of file MD5Generator.cpp.

107 {
108  init();
109 }

◆ MD5() [2/2]

MD5::MD5 ( const std::string &  text)

Definition at line 114 of file MD5Generator.cpp.

115 {
116  if(text.size() > std::numeric_limits<unsigned int>::max())
117  throw InvalidArgument("input string too long");
118 
119  init();
120  update(text.c_str(), static_cast<unsigned int>(text.length()));
121  finalize();
122 }
DLLEXPORT void update(const unsigned char *buf, size_type length)
DLLEXPORT MD5 & finalize()

Member Function Documentation

◆ finalize()

MD5 & MD5::finalize ( )

Definition at line 304 of file MD5Generator.cpp.

305 {
306  if (!finalized) {
307  // Save number of bits
308  unsigned char bits[8];
309  encode(bits, count, 8);
310 
311  static unsigned char padding[64] = {
312  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
313  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
314  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
315  };
316 
317  // pad out to 56 mod 64.
318  size_type index = count[0] / 8 % 64;
319  size_type padLen = (index < 56) ? (56 - index) : (120 - index);
320  update(padding, padLen);
321 
322  // Append length (before padding)
323  update(bits, 8);
324 
325  // Store state in digest
326  encode(digest, state, 16);
327 
328  // Zeroize sensitive information.
329  memset(buffer, 0, sizeof buffer);
330  memset(count, 0, sizeof count);
331 
332  finalized=true;
333  }
334 
335  return *this;
336 }
unsigned int size_type
Definition: MD5Generator.h:57
DLLEXPORT void update(const unsigned char *buf, size_type length)

◆ hexdigest()

std::string MD5::hexdigest ( ) const

Definition at line 341 of file MD5Generator.cpp.

342 {
343  if (!finalized)
344  return "";
345 
346  stringstream digeststring("");
347  // set proper settings //
348  digeststring << std::hex << std::setfill('0');
349 
350 
351  //char buf[33];
352  for (int i=0; i<16; i++)
353  //sprintf(buf+i*2, "%02x", digest[i]);
354  //sprintf_s(buf+i*2, sizeof(buf[0]),"%02x", digest[i]);
355  digeststring << std::setw(2) << static_cast<unsigned>(digest[i]);
356  //buf[32]=0;
357 
358  return digeststring.str();
359 }

◆ update() [1/2]

DLLEXPORT void Leviathan::MD5::update ( const unsigned char *  buf,
size_type  length 
)

◆ update() [2/2]

DLLEXPORT void Leviathan::MD5::update ( const char *  buf,
size_type  length 
)

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
MD5  md5 
)
friend

Definition at line 363 of file MD5Generator.cpp.

364 {
365  return out << md5.hexdigest();
366 }
std::string md5(const std::string &str)

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