hashes.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: hashes.cc,v 1.1 2001/03/06 07:15:29 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. // Include Files /*{{{*/
  11. #ifdef __GNUG__
  12. #pragma implementation "apt-pkg/hashes.h"
  13. #endif
  14. #include <apt-pkg/hashes.h>
  15. #include <unistd.h>
  16. #include <system.h>
  17. /*}}}*/
  18. // Hashes::AddFD - Add the contents of the FD /*{{{*/
  19. // ---------------------------------------------------------------------
  20. /* */
  21. bool Hashes::AddFD(int Fd,unsigned long Size)
  22. {
  23. unsigned char Buf[64*64];
  24. int Res = 0;
  25. while (Size != 0)
  26. {
  27. Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
  28. if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
  29. return false;
  30. Size -= Res;
  31. MD5.Add(Buf,Res);
  32. SHA1.Add(Buf,Res);
  33. SHA256.Add(Buf,Res);
  34. }
  35. return true;
  36. }
  37. /*}}}*/