"Fossies" - the Fresh Open Source Software Archive

Member "postal-0.76/cmd5.cpp" (13 Dec 2016, 908 Bytes) of package /linux/privat/postal-0.76.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cmd5.cpp" see the Fossies "Dox" file reference documentation.

    1 #include "postal.h"
    2 #include "cmd5.h"
    3 #include <stdio.h>
    4 
    5 Cmd5::Cmd5()
    6 {
    7   init();
    8 }
    9 
   10 void Cmd5::init()
   11 {
   12 #ifdef USE_OPENSSL
   13   MD5_Init(&m_context);
   14 #else
   15   MD5Init(&m_context);
   16 #endif
   17 }
   18 
   19 void Cmd5::getSum(char *buf)
   20 {
   21 #ifdef USE_OPENSSL
   22   MD5_Final((unsigned char *)buf, &m_context);
   23 #else
   24   MD5Final((unsigned char *)buf, &m_context);
   25 #endif
   26 }
   27   // get the sum into a string reference
   28 string Cmd5::getSum()
   29 {
   30   unsigned char output[16];
   31   getSum((char *)output);
   32   char str_output[33];
   33   for(int i = 0; i < 16; i++)
   34   {
   35     sprintf(&str_output[2 * i], "%02x", (int)output[i]);
   36   }
   37   return str_output;
   38 }
   39 
   40 void Cmd5::addData(const char *buf, size_t bytes)
   41 {
   42 #ifdef USE_OPENSSL
   43   MD5_Update(&m_context, (const unsigned char *)buf, bytes);
   44 #else
   45   MD5Update(&m_context, (const unsigned char *)buf, bytes);
   46 #endif
   47 }
   48 
   49 void Cmd5::addData(const string &buf)
   50 {
   51   addData((const char *)buf.c_str(), buf.size());
   52 }
   53