X-Git-Url: http://git.hcoop.net/ntk/apt.git/blobdiff_plain/90a88b83020eb9526951eec83e3075b54653fa33..3e2efdda0a8f577d571fcae15e9f4c3cebddfe30:/apt-pkg/contrib/md5.cc diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc index 44242371..4351aeb2 100644 --- a/apt-pkg/contrib/md5.cc +++ b/apt-pkg/contrib/md5.cc @@ -35,15 +35,16 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include + #include #include +#include #include #include #include // For htonl #include -#include -#include /*}}}*/ // byteSwap - Swap bytes in a buffer /*{{{*/ @@ -165,61 +166,6 @@ static void MD5Transform(uint32_t buf[4], uint32_t const in[16]) buf[3] += d; } /*}}}*/ -// MD5SumValue::MD5SumValue - Constructs the summation from a string /*{{{*/ -// --------------------------------------------------------------------- -/* The string form of a MD5 is a 32 character hex number */ -MD5SumValue::MD5SumValue(string Str) -{ - memset(Sum,0,sizeof(Sum)); - Set(Str); -} - /*}}}*/ -// MD5SumValue::MD5SumValue - Default constructor /*{{{*/ -// --------------------------------------------------------------------- -/* Sets the value to 0 */ -MD5SumValue::MD5SumValue() -{ - memset(Sum,0,sizeof(Sum)); -} - /*}}}*/ -// MD5SumValue::Set - Set the sum from a string /*{{{*/ -// --------------------------------------------------------------------- -/* Converts the hex string into a set of chars */ -bool MD5SumValue::Set(string Str) -{ - return Hex2Num(Str,Sum,sizeof(Sum)); -} - /*}}}*/ -// MD5SumValue::Value - Convert the number into a string /*{{{*/ -// --------------------------------------------------------------------- -/* Converts the set of chars into a hex string in lower case */ -string MD5SumValue::Value() const -{ - char Conv[16] = {'0','1','2','3','4','5','6','7','8','9','a','b', - 'c','d','e','f'}; - char Result[33]; - Result[32] = 0; - - // Convert each char into two letters - int J = 0; - int I = 0; - for (; I != 32; J++, I += 2) - { - Result[I] = Conv[Sum[J] >> 4]; - Result[I + 1] = Conv[Sum[J] & 0xF]; - } - - return string(Result); -} - /*}}}*/ -// MD5SumValue::operator == - Comparitor /*{{{*/ -// --------------------------------------------------------------------- -/* Call memcmp on the buffer */ -bool MD5SumValue::operator ==(const MD5SumValue &rhs) const -{ - return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0; -} - /*}}}*/ // MD5Summation::MD5Summation - Initialize the summer /*{{{*/ // --------------------------------------------------------------------- /* This assigns the deep magic initial values */ @@ -241,7 +187,7 @@ MD5Summation::MD5Summation() // MD5Summation::Add - 'Add' a data set to the hash /*{{{*/ // --------------------------------------------------------------------- /* */ -bool MD5Summation::Add(const unsigned char *data,unsigned long len) +bool MD5Summation::Add(const unsigned char *data,unsigned long long len) { if (Done == true) return false; @@ -286,24 +232,6 @@ bool MD5Summation::Add(const unsigned char *data,unsigned long len) return true; } /*}}}*/ -// MD5Summation::AddFD - Add the contents of a FD to the hash /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool MD5Summation::AddFD(int Fd,unsigned long Size) -{ - unsigned char Buf[64*64]; - int Res = 0; - while (Size != 0) - { - Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf))); - if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf))) - return false; - Size -= Res; - Add(Buf,Res); - } - return true; -} - /*}}}*/ // MD5Summation::Result - Returns the value of the sum /*{{{*/ // --------------------------------------------------------------------- /* Because this must add in the last bytes of the series it prevents anyone @@ -348,7 +276,7 @@ MD5SumValue MD5Summation::Result() } MD5SumValue V; - memcpy(V.Sum,buf,16); + V.Set((unsigned char *)buf); return V; } /*}}}*/