hashes.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include <apt-pkg/hashes.h>
  12. #include <unistd.h>
  13. #include <system.h>
  14. /*}}}*/
  15. // Hashes::AddFD - Add the contents of the FD /*{{{*/
  16. // ---------------------------------------------------------------------
  17. /* */
  18. bool Hashes::AddFD(int Fd,unsigned long Size)
  19. {
  20. unsigned char Buf[64*64];
  21. int Res = 0;
  22. while (Size != 0)
  23. {
  24. Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
  25. if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
  26. return false;
  27. Size -= Res;
  28. MD5.Add(Buf,Res);
  29. SHA1.Add(Buf,Res);
  30. SHA256.Add(Buf,Res);
  31. }
  32. return true;
  33. }
  34. /*}}}*/