diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-06-29 19:21:34 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-06-29 19:21:34 +0200 |
commit | 8f8ed8f4e50fd98aa43ee69971cac8bda55760f1 (patch) | |
tree | 79dbb2f29aca55db49f8e7213094a8423caa343e /ftparchive | |
parent | d953d210bb54accb416f2144104b79dcd29198ba (diff) | |
parent | 6f747894998e10649d0237fe5f7b9b85a5266f1f (diff) |
merge with debian-experimental 0.8.16~exp2 release
Diffstat (limited to 'ftparchive')
-rw-r--r-- | ftparchive/cachedb.cc | 40 | ||||
-rw-r--r-- | ftparchive/cachedb.h | 20 | ||||
-rw-r--r-- | ftparchive/writer.cc | 37 | ||||
-rw-r--r-- | ftparchive/writer.h | 2 |
4 files changed, 90 insertions, 9 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..c43e8f4b4 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -20,7 +20,7 @@ #include <apt-pkg/aptconfiguration.h> #include <apt-pkg/md5.h> #include <apt-pkg/sha1.h> -#include <apt-pkg/sha256.h> +#include <apt-pkg/sha2.h> #include <apt-pkg/deblistparser.h> #include <sys/types.h> @@ -64,6 +64,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 +317,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 +372,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 +448,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 +627,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 +635,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 +747,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 +808,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()); @@ -1046,6 +1061,12 @@ bool ReleaseWriter::DoPackage(string FileName) CheckSums[NewFileName].SHA256 = SHA256.Result(); } + if (DoSHA512 == true) + { + SHA512Summation SHA512; + SHA512.AddFD(fd.Fd(), fd.Size()); + CheckSums[NewFileName].SHA512 = SHA512.Result(); + } fd.Close(); return true; @@ -1092,4 +1113,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() {}; |