From 9a961efc5cedeb2b7439114df18e8d0201c83fcf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Feb 2011 22:06:31 +0100 Subject: add sha512 support to apt-ftparchive --- ftparchive/writer.cc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'ftparchive/writer.cc') diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 9cdca8d3e..e7eff2045 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -311,6 +312,7 @@ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string c DoMD5 = _config->FindB("APT::FTPArchive::MD5",true); DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true); DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true); + DoSHA256 = _config->FindB("APT::FTPArchive::SHA512",true); DoAlwaysStat = _config->FindB("APT::FTPArchive::AlwaysStat", false); DoContents = _config->FindB("APT::FTPArchive::Contents",true); NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false); @@ -365,7 +367,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; @@ -438,6 +440,7 @@ bool PackagesWriter::DoPackage(string FileName) SetTFRewriteData(Changes[End++], "MD5sum", Db.MD5Res.c_str()); SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str()); SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str()); + 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); @@ -613,8 +616,10 @@ bool SourcesWriter::DoPackage(string FileName) SHA1Summation SHA1; SHA256Summation SHA256; + SHA512Summation SHA512; SHA1.Add((unsigned char *)Start,BlkEnd - Start); SHA256.Add((unsigned char *)Start,BlkEnd - Start); + SHA512.Add((unsigned char *)Start,BlkEnd - Start); // Add an extra \n to the end, just in case *BlkEnd++ = '\n'; @@ -725,6 +730,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 && @@ -777,6 +788,7 @@ bool SourcesWriter::DoPackage(string FileName) SetTFRewriteData(Changes[End++],"Files",Files.c_str()); SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str()); SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str()); + SetTFRewriteData(Changes[End++],"Checksums-Sha512",ChecksumsSha512.c_str()); if (Directory != "./") SetTFRewriteData(Changes[End++],"Directory",Directory.c_str()); SetTFRewriteData(Changes[End++],"Priority",BestPrio.c_str()); @@ -1010,6 +1022,10 @@ bool ReleaseWriter::DoPackage(string FileName) SHA256.AddFD(fd.Fd(), fd.Size()); CheckSums[NewFileName].SHA256 = SHA256.Result(); + SHA256Summation SHA512; + SHA256.AddFD(fd.Fd(), fd.Size()); + CheckSums[NewFileName].SHA512 = SHA512.Result(); + fd.Close(); return true; @@ -1052,5 +1068,17 @@ void ReleaseWriter::Finish() (*I).second.size, (*I).first.c_str()); } + + fprintf(Output, "SHA512:\n"); + for(map::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()); + } + } -- cgit v1.2.3 From 84a0890e6ef49b5d41a0b9ff0b5a5fe95cca6f3e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 25 Feb 2011 14:16:35 +0100 Subject: move sha512,256 into apt-pkg/sha2.{cc,h}, move gifford implementation to sha2_internal.{cc,h} --- ftparchive/writer.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ftparchive/writer.cc') diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index e7eff2045..98ab852ea 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -19,8 +19,7 @@ #include #include #include -#include -#include +#include #include #include -- cgit v1.2.3 From 8c4e1f97686c412f88bb57827a84b776626d9980 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Jul 2011 23:23:04 +0200 Subject: * ftparchive/writer.cc: - generate all checksums in one run over the file for Release --- ftparchive/writer.cc | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'ftparchive/writer.cc') diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index c43e8f4b4..60db8b990 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -19,8 +19,7 @@ #include #include #include -#include -#include +#include #include #include @@ -1040,35 +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) - { - SHA512Summation SHA512; - SHA512.AddFD(fd.Fd(), fd.Size()); - CheckSums[NewFileName].SHA512 = SHA512.Result(); - } + CheckSums[NewFileName].SHA512 = hs.SHA512.Result(); fd.Close(); - + return true; } -- cgit v1.2.3