summaryrefslogtreecommitdiff
path: root/ftparchive
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-08-09 14:38:01 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-08-09 14:38:01 +0200
commit216d0bd8869c4f52ead5256064512ac97e9fc824 (patch)
treeea6911a231e29b73a883d4449fe7f88941ddd92d /ftparchive
parent629b60f6feea2d2d356645aa2615b212481bd3d8 (diff)
parent97efc27f0723f09405d7a1836ab21c2e2948eb10 (diff)
merged from the debian-experimental2 branch
Diffstat (limited to 'ftparchive')
-rw-r--r--ftparchive/cachedb.cc40
-rw-r--r--ftparchive/cachedb.h20
-rw-r--r--ftparchive/writer.cc59
-rw-r--r--ftparchive/writer.h2
4 files changed, 92 insertions, 29 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 /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/ftparchive/cachedb.h b/ftparchive/cachedb.h
index 0ba80909a..15e796325 100644
--- a/ftparchive/cachedb.h
+++ b/ftparchive/cachedb.h
@@ -70,10 +70,13 @@ class CacheDB
bool GetMD5(bool const &GenOnly);
bool GetSHA1(bool const &GenOnly);
bool GetSHA256(bool const &GenOnly);
+ bool GetSHA512(bool const &GenOnly);
// Stat info stored in the DB, Fixed types since it is written to disk.
enum FlagList {FlControl = (1<<0),FlMD5=(1<<1),FlContents=(1<<2),
- FlSize=(1<<3), FlSHA1=(1<<4), FlSHA256=(1<<5)};
+ FlSize=(1<<3), FlSHA1=(1<<4), FlSHA256=(1<<5),
+ FlSHA512=(1<<6)};
+
struct StatStore
{
uint32_t Flags;
@@ -82,6 +85,7 @@ class CacheDB
uint8_t MD5[16];
uint8_t SHA1[20];
uint8_t SHA256[32];
+ uint8_t SHA512[64];
} CurStat;
struct StatStore OldStat;
@@ -98,6 +102,7 @@ class CacheDB
string MD5Res;
string SHA1Res;
string SHA256Res;
+ string SHA512Res;
// Runtime statistics
struct Stats
@@ -106,14 +111,21 @@ class CacheDB
double MD5Bytes;
double SHA1Bytes;
double SHA256Bytes;
+ double SHA512Bytes;
unsigned long Packages;
unsigned long Misses;
unsigned long DeLinkBytes;
inline void Add(const Stats &S) {
- Bytes += S.Bytes; MD5Bytes += S.MD5Bytes; SHA1Bytes += S.SHA1Bytes;
+ Bytes += S.Bytes;
+ MD5Bytes += S.MD5Bytes;
+ SHA1Bytes += S.SHA1Bytes;
SHA256Bytes += S.SHA256Bytes;
- Packages += S.Packages; Misses += S.Misses; DeLinkBytes += S.DeLinkBytes;};
+ SHA512Bytes += S.SHA512Bytes;
+ Packages += S.Packages;
+ Misses += S.Misses;
+ DeLinkBytes += S.DeLinkBytes;
+ };
Stats() : Bytes(0), MD5Bytes(0), SHA1Bytes(0), SHA256Bytes(0), Packages(0), Misses(0), DeLinkBytes(0) {};
} Stats;
@@ -125,7 +137,7 @@ class CacheDB
bool SetFile(string const &FileName,struct stat St,FileFd *Fd);
bool 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 = false);
+ bool const &DoMD5, bool const &DoSHA1, bool const &DoSHA256, bool const &DoSHA512, bool const &checkMtime = false);
bool Finish();
bool Clean();
diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc
index 9f12cbf3d..60db8b990 100644
--- a/ftparchive/writer.cc
+++ b/ftparchive/writer.cc
@@ -19,8 +19,7 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/md5.h>
-#include <apt-pkg/sha1.h>
-#include <apt-pkg/sha256.h>
+#include <apt-pkg/hashes.h>
#include <apt-pkg/deblistparser.h>
#include <sys/types.h>
@@ -64,6 +63,7 @@ FTWScanner::FTWScanner(string const &Arch): Arch(Arch)
DoMD5 = _config->FindB("APT::FTPArchive::MD5",true);
DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true);
DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true);
+ DoSHA512 = _config->FindB("APT::FTPArchive::SHA512",true);
}
/*}}}*/
// FTWScanner::Scanner - FTW Scanner /*{{{*/
@@ -316,6 +316,7 @@ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string c
DoMD5 = _config->FindB("APT::FTPArchive::Packages::MD5",DoMD5);
DoSHA1 = _config->FindB("APT::FTPArchive::Packages::SHA1",DoSHA1);
DoSHA256 = _config->FindB("APT::FTPArchive::Packages::SHA256",DoSHA256);
+ DoSHA256 = _config->FindB("APT::FTPArchive::Packages::SHA512",true);
DoAlwaysStat = _config->FindB("APT::FTPArchive::AlwaysStat", false);
DoContents = _config->FindB("APT::FTPArchive::Contents",true);
NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false);
@@ -370,7 +371,7 @@ bool FTWScanner::SetExts(string const &Vals)
bool PackagesWriter::DoPackage(string FileName)
{
// Pull all the data we need form the DB
- if (Db.GetFileInfo(FileName, true, DoContents, true, DoMD5, DoSHA1, DoSHA256, DoAlwaysStat)
+ if (Db.GetFileInfo(FileName, true, DoContents, true, DoMD5, DoSHA1, DoSHA256, DoSHA512, DoAlwaysStat)
== false)
{
return false;
@@ -446,6 +447,8 @@ bool PackagesWriter::DoPackage(string FileName)
SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str());
if (DoSHA256 == true)
SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str());
+ if (DoSHA512 == true)
+ SetTFRewriteData(Changes[End++], "SHA512", Db.SHA512Res.c_str());
SetTFRewriteData(Changes[End++], "Filename", NewFileName.c_str());
SetTFRewriteData(Changes[End++], "Priority", OverItem->Priority.c_str());
SetTFRewriteData(Changes[End++], "Status", 0);
@@ -623,6 +626,7 @@ bool SourcesWriter::DoPackage(string FileName)
MD5Summation MD5;
SHA1Summation SHA1;
SHA256Summation SHA256;
+ SHA256Summation SHA512;
if (DoMD5 == true)
MD5.Add((unsigned char *)Start,BlkEnd - Start);
@@ -630,6 +634,8 @@ bool SourcesWriter::DoPackage(string FileName)
SHA1.Add((unsigned char *)Start,BlkEnd - Start);
if (DoSHA256 == true)
SHA256.Add((unsigned char *)Start,BlkEnd - Start);
+ if (DoSHA512 == true)
+ SHA512.Add((unsigned char *)Start,BlkEnd - Start);
// Add an extra \n to the end, just in case
*BlkEnd++ = '\n';
@@ -740,6 +746,12 @@ bool SourcesWriter::DoPackage(string FileName)
<< strippedName << "\n " << Tags.FindS("Checksums-Sha256");
string const ChecksumsSha256 = ostreamSha256.str();
+ std::ostringstream ostreamSha512;
+ if (Tags.Exists("Checksums-Sha512"))
+ ostreamSha512 << "\n " << string(SHA512.Result()) << " " << St.st_size << " "
+ << strippedName << "\n " << Tags.FindS("Checksums-Sha512");
+ string const ChecksumsSha512 = ostreamSha512.str();
+
// Strip the DirStrip prefix from the FileName and add the PathPrefix
string NewFileName;
if (DirStrip.empty() == false &&
@@ -795,6 +807,8 @@ bool SourcesWriter::DoPackage(string FileName)
SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str());
if (ChecksumsSha256.empty() == false)
SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str());
+ if (ChecksumsSha512.empty() == false)
+ SetTFRewriteData(Changes[End++],"Checksums-Sha512",ChecksumsSha512.c_str());
if (Directory != "./")
SetTFRewriteData(Changes[End++],"Directory",Directory.c_str());
SetTFRewriteData(Changes[End++],"Priority",BestPrio.c_str());
@@ -1025,29 +1039,18 @@ bool ReleaseWriter::DoPackage(string FileName)
CheckSums[NewFileName].size = fd.Size();
+ Hashes hs;
+ hs.AddFD(fd.Fd(), 0, DoMD5, DoSHA1, DoSHA256, DoSHA512);
if (DoMD5 == true)
- {
- MD5Summation MD5;
- MD5.AddFD(fd.Fd(), fd.Size());
- CheckSums[NewFileName].MD5 = MD5.Result();
- fd.Seek(0);
- }
+ CheckSums[NewFileName].MD5 = hs.MD5.Result();
if (DoSHA1 == true)
- {
- SHA1Summation SHA1;
- SHA1.AddFD(fd.Fd(), fd.Size());
- CheckSums[NewFileName].SHA1 = SHA1.Result();
- fd.Seek(0);
- }
+ CheckSums[NewFileName].SHA1 = hs.SHA1.Result();
if (DoSHA256 == true)
- {
- SHA256Summation SHA256;
- SHA256.AddFD(fd.Fd(), fd.Size());
- CheckSums[NewFileName].SHA256 = SHA256.Result();
- }
-
+ CheckSums[NewFileName].SHA256 = hs.SHA256.Result();
+ if (DoSHA512 == true)
+ CheckSums[NewFileName].SHA512 = hs.SHA512.Result();
fd.Close();
-
+
return true;
}
@@ -1092,4 +1095,16 @@ void ReleaseWriter::Finish()
(*I).first.c_str());
}
}
+
+ fprintf(Output, "SHA512:\n");
+ for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
+ I != CheckSums.end();
+ ++I)
+ {
+ fprintf(Output, " %s %32ld %s\n",
+ (*I).second.SHA512.c_str(),
+ (*I).second.size,
+ (*I).first.c_str());
+ }
+
}
diff --git a/ftparchive/writer.h b/ftparchive/writer.h
index ce0eab7af..c6026e954 100644
--- a/ftparchive/writer.h
+++ b/ftparchive/writer.h
@@ -63,6 +63,7 @@ class FTWScanner
bool DoMD5;
bool DoSHA1;
bool DoSHA256;
+ bool DoSHA512;
unsigned long DeLinkLimit;
string InternalPrefix;
@@ -195,6 +196,7 @@ protected:
string MD5;
string SHA1;
string SHA256;
+ string SHA512;
// Limited by FileFd::Size()
unsigned long size;
~CheckSum() {};