Просмотр исходного кода

enable Hashes::AddFD() to skip creation of certain hashes

David Kalnischkies лет назад: 15
Родитель
Сommit
1dab797ca6

+ 12 - 7
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;
 }

+ 4 - 1
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);};
 };

+ 2 - 3
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;

+ 1 - 1
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