00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef APTPKG_MD5_H
00024 #define APTPKG_MD5_H
00025
00026
00027 #include <string>
00028 #include <cstring>
00029 #include <algorithm>
00030 #include <stdint.h>
00031
00032 using std::string;
00033 using std::min;
00034
00035 class MD5Summation;
00036
00037 class MD5SumValue
00038 {
00039 friend class MD5Summation;
00040 unsigned char Sum[4*4];
00041
00042 public:
00043
00044
00045 bool operator ==(const MD5SumValue &rhs) const;
00046 string Value() const;
00047 inline void Value(unsigned char S[16])
00048 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
00049 inline operator string() const {return Value();};
00050 bool Set(string Str);
00051 inline void Set(unsigned char S[16])
00052 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
00053
00054 MD5SumValue(string Str);
00055 MD5SumValue();
00056 };
00057
00058 class MD5Summation
00059 {
00060 uint32_t Buf[4];
00061 unsigned char Bytes[2*4];
00062 unsigned char In[16*4];
00063 bool Done;
00064
00065 public:
00066
00067 bool Add(const unsigned char *Data,unsigned long Size);
00068 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
00069 bool AddFD(int Fd,unsigned long Size);
00070 inline bool Add(const unsigned char *Beg,const unsigned char *End)
00071 {return Add(Beg,End-Beg);};
00072 MD5SumValue Result();
00073
00074 MD5Summation();
00075 };
00076
00077 #endif