summaryrefslogtreecommitdiff
path: root/ftparchive/cachedb.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-06-08 12:03:34 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-06-08 12:03:34 +0200
commit12cd178d6eb61306cc99e5e07c463c800d406771 (patch)
tree90941ebf0adb1c4b3ef9ca780a2b42cb1f2dfb16 /ftparchive/cachedb.cc
parentd953d210bb54accb416f2144104b79dcd29198ba (diff)
parent31693a8ff0fe593879ed30a4dde8f9be5b0859bf (diff)
merge lp:~mvo/apt/sha512-template to add support for sha512
Diffstat (limited to 'ftparchive/cachedb.cc')
-rw-r--r--ftparchive/cachedb.cc40
1 files changed, 37 insertions, 3 deletions
diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc
index b04244347..7e4c2e9fe 100644
--- a/ftparchive/cachedb.cc
+++ b/ftparchive/cachedb.cc
@@ -16,7 +16,7 @@
#include <apt-pkg/error.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
-#include <apt-pkg/sha256.h>
+#include <apt-pkg/sha2.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/configuration.h>
@@ -162,7 +162,8 @@ bool CacheDB::GetCurStat()
// ---------------------------------------------------------------------
bool CacheDB::GetFileInfo(string const &FileName, bool const &DoControl, bool const &DoContents,
bool const &GenContentsOnly, bool const &DoMD5, bool const &DoSHA1,
- bool const &DoSHA256, bool const &checkMtime)
+ bool const &DoSHA256, bool const &DoSHA512,
+ bool const &checkMtime)
{
this->FileName = FileName;
@@ -190,7 +191,9 @@ bool CacheDB::GetFileInfo(string const &FileName, bool const &DoControl, bool co
|| (DoContents && LoadContents(GenContentsOnly) == false)
|| (DoMD5 && GetMD5(false) == false)
|| (DoSHA1 && GetSHA1(false) == false)
- || (DoSHA256 && GetSHA256(false) == false))
+ || (DoSHA256 && GetSHA256(false) == false)
+ || (DoSHA512 && GetSHA512(false) == false)
+ )
{
delete Fd;
Fd = NULL;
@@ -412,6 +415,37 @@ bool CacheDB::GetSHA256(bool const &GenOnly)
return true;
}
/*}}}*/
+// CacheDB::GetSHA256 - Get the SHA256 hash /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool CacheDB::GetSHA512(bool const &GenOnly)
+{
+ // Try to read the control information out of the DB.
+ if ((CurStat.Flags & FlSHA512) == FlSHA512)
+ {
+ if (GenOnly == true)
+ return true;
+
+ SHA512Res = bytes2hex(CurStat.SHA512, sizeof(CurStat.SHA512));
+ return true;
+ }
+
+ Stats.SHA512Bytes += CurStat.FileSize;
+
+ if (Fd == NULL && OpenFile() == false)
+ {
+ return false;
+ }
+ SHA512Summation SHA512;
+ if (Fd->Seek(0) == false || SHA512.AddFD(Fd->Fd(),CurStat.FileSize) == false)
+ return false;
+
+ SHA512Res = SHA512.Result();
+ hex2bytes(CurStat.SHA512, SHA512Res.data(), sizeof(CurStat.SHA512));
+ CurStat.Flags |= FlSHA512;
+ return true;
+}
+ /*}}}*/
// CacheDB::Finish - Write back the cache structure /*{{{*/
// ---------------------------------------------------------------------
/* */