From 1dab797ca6dc0357474675a0f132c962dee4a2c2 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Jul 2011 23:10:38 +0200 Subject: enable Hashes::AddFD() to skip creation of certain hashes --- apt-pkg/contrib/hashes.cc | 19 ++++++++++++------- apt-pkg/contrib/hashes.h | 5 ++++- apt-pkg/contrib/hashsum.cc | 5 ++--- apt-pkg/contrib/hashsum_template.h | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 66ae33146..d217747df 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -107,7 +107,8 @@ string HashString::toStr() const // Hashes::AddFD - Add the contents of the FD /*{{{*/ // --------------------------------------------------------------------- /* */ -bool Hashes::AddFD(int Fd,unsigned long Size) +bool Hashes::AddFD(int const Fd,unsigned long Size, bool const addMD5, + bool const addSHA1, bool const addSHA256, bool const addSHA512) { unsigned char Buf[64*64]; int Res = 0; @@ -118,14 +119,18 @@ bool Hashes::AddFD(int Fd,unsigned long Size) if (!ToEOF) n = min(Size,(unsigned long)n); Res = read(Fd,Buf,n); if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read - return false; + return false; if (ToEOF && Res == 0) // EOF - break; + break; Size -= Res; - MD5.Add(Buf,Res); - SHA1.Add(Buf,Res); - SHA256.Add(Buf,Res); - SHA512.Add(Buf,Res); + if (addMD5 == true) + MD5.Add(Buf,Res); + if (addSHA1 == true) + SHA1.Add(Buf,Res); + if (addSHA256 == true) + SHA256.Add(Buf,Res); + if (addSHA512 == true) + SHA512.Add(Buf,Res); } return true; } diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index 4b6a08b1f..e702fcca2 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -67,7 +67,10 @@ class Hashes return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size) && SHA512.Add(Data,Size); }; inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; - bool AddFD(int Fd,unsigned long Size); + inline bool AddFD(int const Fd,unsigned long Size = 0) + { return AddFD(Fd, Size, true, true, true, true); }; + bool AddFD(int const Fd, unsigned long Size, bool const addMD5, + bool const addSHA1, bool const addSHA256, bool const addSHA512); inline bool Add(const unsigned char *Beg,const unsigned char *End) {return Add(Beg,End-Beg);}; }; diff --git a/apt-pkg/contrib/hashsum.cc b/apt-pkg/contrib/hashsum.cc index b97eaf831..728747d7a 100644 --- a/apt-pkg/contrib/hashsum.cc +++ b/apt-pkg/contrib/hashsum.cc @@ -10,11 +10,10 @@ bool SummationImplementation::AddFD(int const Fd, unsigned long Size) { unsigned char Buf[64 * 64]; int Res = 0; int ToEOF = (Size == 0); - unsigned long n = sizeof(Buf); - if (!ToEOF) - n = std::min(Size, n); while (Size != 0 || ToEOF) { + unsigned n = sizeof(Buf); + if (!ToEOF) n = min(Size,(unsigned long)n); Res = read(Fd, Buf, n); if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read return false; diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h index 2847f3308..85d94c2af 100644 --- a/apt-pkg/contrib/hashsum_template.h +++ b/apt-pkg/contrib/hashsum_template.h @@ -101,7 +101,7 @@ class SummationImplementation inline bool Add(const char *Beg, const char *End) { return Add((const unsigned char *)Beg, End - Beg); }; - bool AddFD(int Fd, unsigned long Size); + bool AddFD(int Fd, unsigned long Size = 0); }; #endif -- cgit v1.2.3