hashes.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: hashes.h,v 1.2 2001/03/11 05:30:20 jgg Exp $
  4. /* ######################################################################
  5. Hashes - Simple wrapper around the hash functions
  6. This is just used to make building the methods simpler, this is the
  7. only interface required..
  8. ##################################################################### */
  9. /*}}}*/
  10. #ifndef APTPKG_HASHES_H
  11. #define APTPKG_HASHES_H
  12. #ifdef __GNUG__
  13. #pragma interface "apt-pkg/hashes.h"
  14. #endif
  15. #include <apt-pkg/md5.h>
  16. #include <apt-pkg/sha1.h>
  17. #include <apt-pkg/sha256.h>
  18. #include <algorithm>
  19. using std::min;
  20. class Hashes
  21. {
  22. public:
  23. MD5Summation MD5;
  24. SHA1Summation SHA1;
  25. SHA256Summation SHA256;
  26. inline bool Add(const unsigned char *Data,unsigned long Size)
  27. {
  28. return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size);
  29. };
  30. inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
  31. bool AddFD(int Fd,unsigned long Size);
  32. inline bool Add(const unsigned char *Beg,const unsigned char *End)
  33. {return Add(Beg,End-Beg);};
  34. };
  35. #endif