summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/hashes.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-12-19 14:22:05 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2011-12-19 14:22:05 +0100
commit2f67d29b0c3de8618983055e811e70ee36662f4a (patch)
tree7ab0646d51474b4f3c16c8a984f2f1edd43528d8 /apt-pkg/contrib/hashes.cc
parent27da8141d21cfbfc29675510737ee05bdfd4a2b1 (diff)
parent29966fd1cc2bab68777e85b9070dba7821a58d36 (diff)
merged from lp:~donkult/apt/experimental
Diffstat (limited to 'apt-pkg/contrib/hashes.cc')
-rw-r--r--apt-pkg/contrib/hashes.cc40
1 files changed, 35 insertions, 5 deletions
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 05001f042..e1a431823 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -61,25 +61,25 @@ bool HashString::VerifyFile(std::string filename) const /*{{{*/
if(Type == "MD5Sum")
{
MD5Summation MD5;
- MD5.AddFD(Fd.Fd(), Fd.Size());
+ MD5.AddFD(Fd);
fileHash = (std::string)MD5.Result();
}
else if (Type == "SHA1")
{
SHA1Summation SHA1;
- SHA1.AddFD(Fd.Fd(), Fd.Size());
+ SHA1.AddFD(Fd);
fileHash = (std::string)SHA1.Result();
}
else if (Type == "SHA256")
{
SHA256Summation SHA256;
- SHA256.AddFD(Fd.Fd(), Fd.Size());
+ SHA256.AddFD(Fd);
fileHash = (std::string)SHA256.Result();
}
else if (Type == "SHA512")
{
SHA512Summation SHA512;
- SHA512.AddFD(Fd.Fd(), Fd.Size());
+ SHA512.AddFD(Fd);
fileHash = (std::string)SHA512.Result();
}
Fd.Close();
@@ -135,5 +135,35 @@ bool Hashes::AddFD(int const Fd,unsigned long long Size, bool const addMD5,
}
return true;
}
+bool Hashes::AddFD(FileFd &Fd,unsigned long long Size, bool const addMD5,
+ bool const addSHA1, bool const addSHA256, bool const addSHA512)
+{
+ unsigned char Buf[64*64];
+ bool const ToEOF = (Size == 0);
+ while (Size != 0 || ToEOF)
+ {
+ unsigned long long n = sizeof(Buf);
+ if (!ToEOF) n = std::min(Size, n);
+ unsigned long long a = 0;
+ if (Fd.Read(Buf, n, &a) == false) // error
+ return false;
+ if (ToEOF == false)
+ {
+ if (a != n) // short read
+ return false;
+ }
+ else if (a == 0) // EOF
+ break;
+ Size -= a;
+ if (addMD5 == true)
+ MD5.Add(Buf, a);
+ if (addSHA1 == true)
+ SHA1.Add(Buf, a);
+ if (addSHA256 == true)
+ SHA256.Add(Buf, a);
+ if (addSHA512 == true)
+ SHA512.Add(Buf, a);
+ }
+ return true;
+}
/*}}}*/
-