summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-11-29 13:39:45 +0100
committerMichael Vogt <mvo@debian.org>2013-11-29 13:39:45 +0100
commite4a93f90b2e50f6833f7146496e574a5a9cedaca (patch)
tree836dd5e70b394f9996d4af0bdfcd52d2a388a007 /apt-pkg
parentfdef7c5e3a19c5f35ee952598124d0fe8d03c7ec (diff)
parentfaeb435cab7b41a50c621ef9f96853d15c57d0d8 (diff)
Merge remote-tracking branch 'mvo/debian/sid' into debian/sid
Conflicts: apt-private/private-cmndline.cc
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/hashes.cc25
-rw-r--r--apt-pkg/contrib/hashes.h9
-rw-r--r--apt-pkg/contrib/strutl.cc8
-rw-r--r--apt-pkg/contrib/strutl.h1
4 files changed, 38 insertions, 5 deletions
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index e1a431823..b4c768db9 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -55,6 +55,26 @@ HashString::HashString(std::string StringedHash) /*{{{*/
/*}}}*/
bool HashString::VerifyFile(std::string filename) const /*{{{*/
{
+ std::string fileHash = GetHashForFile(filename);
+
+ if(_config->FindB("Debug::Hashes",false) == true)
+ std::clog << "HashString::VerifyFile: got: " << fileHash << " expected: " << toStr() << std::endl;
+
+ return (fileHash == Hash);
+}
+ /*}}}*/
+bool HashString::FromFile(std::string filename) /*{{{*/
+{
+ // pick the strongest hash
+ if (Type == "")
+ Type = _SupportedHashes[0];
+
+ Hash = GetHashForFile(filename);
+ return true;
+}
+ /*}}}*/
+std::string HashString::GetHashForFile(std::string filename) const /*{{{*/
+{
std::string fileHash;
FileFd Fd(filename, FileFd::ReadOnly);
@@ -84,10 +104,7 @@ bool HashString::VerifyFile(std::string filename) const /*{{{*/
}
Fd.Close();
- if(_config->FindB("Debug::Hashes",false) == true)
- std::clog << "HashString::VerifyFile: got: " << fileHash << " expected: " << toStr() << std::endl;
-
- return (fileHash == Hash);
+ return fileHash;
}
/*}}}*/
const char** HashString::SupportedHashes()
diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h
index 0c0b6c6a7..0a8bcd259 100644
--- a/apt-pkg/contrib/hashes.h
+++ b/apt-pkg/contrib/hashes.h
@@ -36,7 +36,10 @@ class HashString
protected:
std::string Type;
std::string Hash;
- static const char * _SupportedHashes[10];
+ static const char* _SupportedHashes[10];
+
+ // internal helper
+ std::string GetHashForFile(std::string filename) const;
public:
HashString(std::string Type, std::string Hash);
@@ -49,6 +52,10 @@ class HashString
// verify the given filename against the currently loaded hash
bool VerifyFile(std::string filename) const;
+ // generate a hash string from the given filename
+ bool FromFile(std::string filename);
+
+
// helper
std::string toStr() const; // convert to str as "type:hash"
bool empty() const;
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 9f794927d..962112854 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -49,6 +49,14 @@ std::string Strip(const std::string &s)
size_t end = s.find_last_not_of(" \t\n");
return s.substr(start, end-start+1);
}
+
+bool Endswith(const std::string &s, const std::string &end)
+{
+ if (end.size() > s.size())
+ return false;
+ return (s.substr(s.size() - end.size(), s.size()) == end);
+}
+
}
}
/*}}}*/
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index c8fc317c0..8d746f10e 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -36,6 +36,7 @@ using std::ostream;
namespace APT {
namespace String {
std::string Strip(const std::string &s);
+ bool Endswith(const std::string &s, const std::string &ending);
};
};