summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/hashes.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-11-10 16:56:21 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2011-11-10 16:56:21 +0100
commit7cb543fb742a837c4931513674febaec5e4c1401 (patch)
treeddefe5b9329907818aa6eb3b593f555b29ccb869 /apt-pkg/contrib/hashes.cc
parentf6cb0880a4b5d31e398cceb2e2577b6b82f4fffb (diff)
parent71ecaad29d8066a494f516efc5efd80860653fe2 (diff)
merged from lp:~mvo/apt/mvo (that has all the changes from debian-experimental2) and resolved a bunch of conflicts
Diffstat (limited to 'apt-pkg/contrib/hashes.cc')
-rw-r--r--apt-pkg/contrib/hashes.cc38
1 files changed, 20 insertions, 18 deletions
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 4407574fa..05001f042 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -11,12 +11,14 @@
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
+#include <config.h>
+
#include <apt-pkg/hashes.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/macros.h>
-#include <unistd.h>
+#include <unistd.h>
#include <string>
#include <iostream>
/*}}}*/
@@ -30,20 +32,20 @@ HashString::HashString()
{
}
-HashString::HashString(string Type, string Hash) : Type(Type), Hash(Hash)
+HashString::HashString(std::string Type, std::string Hash) : Type(Type), Hash(Hash)
{
}
-HashString::HashString(string StringedHash) /*{{{*/
+HashString::HashString(std::string StringedHash) /*{{{*/
{
// legacy: md5sum without "MD5Sum:" prefix
- if (StringedHash.find(":") == string::npos && StringedHash.size() == 32)
+ if (StringedHash.find(":") == std::string::npos && StringedHash.size() == 32)
{
Type = "MD5Sum";
Hash = StringedHash;
return;
}
- string::size_type pos = StringedHash.find(":");
+ std::string::size_type pos = StringedHash.find(":");
Type = StringedHash.substr(0,pos);
Hash = StringedHash.substr(pos+1, StringedHash.size() - pos);
@@ -51,34 +53,34 @@ HashString::HashString(string StringedHash) /*{{{*/
std::clog << "HashString(string): " << Type << " : " << Hash << std::endl;
}
/*}}}*/
-bool HashString::VerifyFile(string filename) const /*{{{*/
+bool HashString::VerifyFile(std::string filename) const /*{{{*/
{
- string fileHash;
+ std::string fileHash;
FileFd Fd(filename, FileFd::ReadOnly);
if(Type == "MD5Sum")
{
MD5Summation MD5;
MD5.AddFD(Fd.Fd(), Fd.Size());
- fileHash = (string)MD5.Result();
+ fileHash = (std::string)MD5.Result();
}
else if (Type == "SHA1")
{
SHA1Summation SHA1;
SHA1.AddFD(Fd.Fd(), Fd.Size());
- fileHash = (string)SHA1.Result();
+ fileHash = (std::string)SHA1.Result();
}
else if (Type == "SHA256")
{
SHA256Summation SHA256;
SHA256.AddFD(Fd.Fd(), Fd.Size());
- fileHash = (string)SHA256.Result();
+ fileHash = (std::string)SHA256.Result();
}
else if (Type == "SHA512")
{
SHA512Summation SHA512;
SHA512.AddFD(Fd.Fd(), Fd.Size());
- fileHash = (string)SHA512.Result();
+ fileHash = (std::string)SHA512.Result();
}
Fd.Close();
@@ -98,26 +100,26 @@ bool HashString::empty() const
return (Type.empty() || Hash.empty());
}
-string HashString::toStr() const
+std::string HashString::toStr() const
{
- return Type+string(":")+Hash;
+ return Type + std::string(":") + Hash;
}
// Hashes::AddFD - Add the contents of the FD /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool Hashes::AddFD(int const Fd,unsigned long Size, bool const addMD5,
+bool Hashes::AddFD(int const Fd,unsigned long long Size, bool const addMD5,
bool const addSHA1, bool const addSHA256, bool const addSHA512)
{
unsigned char Buf[64*64];
- int Res = 0;
+ ssize_t Res = 0;
int ToEOF = (Size == 0);
while (Size != 0 || ToEOF)
{
- unsigned n = sizeof(Buf);
- if (!ToEOF) n = min(Size,(unsigned long)n);
+ unsigned long long n = sizeof(Buf);
+ if (!ToEOF) n = std::min(Size, n);
Res = read(Fd,Buf,n);
- if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
+ if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
return false;
if (ToEOF && Res == 0) // EOF
break;