md5.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: md5.h,v 1.2 1998/11/25 23:54:45 jgg Exp $
  4. /* ######################################################################
  5. MD5SumValue - Storage for a MD5Sum
  6. MD5Summation - MD5 Message Digest Algorithm.
  7. This is a C++ interface to a set of MD5Sum functions. The class can
  8. store a MD5Sum in 16 bytes of memory.
  9. A MD5Sum is used to generate a (hopefully) unique 16 byte number for a
  10. block of data. This can be used to gaurd against corruption of a file.
  11. There are two classes because computing a MD5 is not a continual
  12. operation unless 64 byte blocks are used. Also the summation requires an
  13. extra 18*4 bytes to operate.
  14. ##################################################################### */
  15. /*}}}*/
  16. #ifndef APTPKG_MD5_H
  17. #define APTPKG_MD5_H
  18. #ifdef __GNUG__
  19. #pragma interface "apt-pkg/md5.h"
  20. #endif
  21. #include <string>
  22. class MD5Summation;
  23. class MD5SumValue
  24. {
  25. friend MD5Summation;
  26. unsigned char Sum[4*4];
  27. public:
  28. // Accessors
  29. bool operator ==(const MD5SumValue &rhs) const;
  30. string Value() const;
  31. inline operator string() const {return Value();};
  32. bool Set(string Str);
  33. MD5SumValue(string Str);
  34. MD5SumValue();
  35. };
  36. class MD5Summation
  37. {
  38. unsigned char Buf[4*4];
  39. unsigned char Bytes[2*4];
  40. unsigned char In[16*4];
  41. bool Done;
  42. public:
  43. bool Add(const unsigned char *Data,unsigned long Size);
  44. inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
  45. bool AddFD(int Fd,unsigned long Size);
  46. inline bool Add(const unsigned char *Beg,const unsigned char *End)
  47. {return Add(Beg,End-Beg);};
  48. MD5SumValue Result();
  49. MD5Summation();
  50. };
  51. #endif