From: Michael Vogt Date: Fri, 25 Feb 2011 12:47:09 +0000 (+0100) Subject: add sha512 support in the client now as well X-Git-Tag: 0.9.0~86^2~5 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/d9b9e9e2495fa4cfd9f555cd51a394bad2f98894 add sha512 support in the client now as well --- d9b9e9e2495fa4cfd9f555cd51a394bad2f98894 diff --cc apt-pkg/acquire-item.cc index d4df31e85,d4df31e85..05e2f28a4 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@@ -1665,6 -1665,6 +1665,8 @@@ bool pkgAcqArchive::QueueNext( string PkgFile = Parse.FileName(); if (ForceHash.empty() == false) { ++ if(stringcasecmp(ForceHash, "sha512") == 0) ++ ExpectedHash = HashString("SHA512", Parse.SHA512Hash()); if(stringcasecmp(ForceHash, "sha256") == 0) ExpectedHash = HashString("SHA256", Parse.SHA256Hash()); else if (stringcasecmp(ForceHash, "sha1") == 0) @@@ -1675,7 -1675,7 +1677,9 @@@ else { string Hash; -- if ((Hash = Parse.SHA256Hash()).empty() == false) ++ if ((Hash = Parse.SHA512Hash()).empty() == false) ++ ExpectedHash = HashString("SHA512", Hash); ++ else if ((Hash = Parse.SHA256Hash()).empty() == false) ExpectedHash = HashString("SHA256", Hash); else if ((Hash = Parse.SHA1Hash()).empty() == false) ExpectedHash = HashString("SHA1", Hash); diff --cc apt-pkg/acquire-method.cc index 17d52cf51,17d52cf51..bf3beafa2 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@@ -187,6 -187,6 +187,8 @@@ void pkgAcqMethod::URIDone(FetchResult End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str()); if (Res.SHA256Sum.empty() == false) End += snprintf(End,sizeof(S)-50 - (End - S),"SHA256-Hash: %s\n",Res.SHA256Sum.c_str()); ++ if (Res.SHA512Sum.empty() == false) ++ End += snprintf(End,sizeof(S)-50 - (End - S),"SHA512-Hash: %s\n",Res.SHA512Sum.c_str()); if (UsedMirror.empty() == false) End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str()); if (Res.GPGVOutput.size() > 0) @@@ -224,7 -224,7 +226,10 @@@ if (Alt->SHA256Sum.empty() == false) End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-SHA256-Hash: %s\n", Alt->SHA256Sum.c_str()); -- ++ if (Alt->SHA512Sum.empty() == false) ++ End += snprintf(End,sizeof(S)-50 - (End - S),"Alt-SHA512-Hash: %s\n", ++ Alt->SHA512Sum.c_str()); ++ if (Alt->IMSHit == true) strcat(End,"Alt-IMS-Hit: true\n"); } @@@ -500,5 -500,5 +505,6 @@@ void pkgAcqMethod::FetchResult::TakeHas MD5Sum = Hash.MD5.Result(); SHA1Sum = Hash.SHA1.Result(); SHA256Sum = Hash.SHA256.Result(); ++ SHA512Sum = Hash.SHA512.Result(); } /*}}}*/ diff --cc apt-pkg/acquire-method.h index 03851e823,03851e823..f6bf83842 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@@ -45,6 -45,6 +45,7 @@@ class pkgAcqMetho string MD5Sum; string SHA1Sum; string SHA256Sum; ++ string SHA512Sum; vector GPGVOutput; time_t LastModified; bool IMSHit; diff --cc apt-pkg/contrib/hashes.cc index 985d89d90,985d89d90..66ae33146 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@@ -23,7 -23,7 +23,7 @@@ const char* HashString::_SupportedHashes[] = { -- "SHA256", "SHA1", "MD5Sum", NULL ++ "SHA512", "SHA256", "SHA1", "MD5Sum", NULL }; HashString::HashString() @@@ -57,6 -57,6 +57,7 @@@ bool HashString::VerifyFile(string file MD5Summation MD5; SHA1Summation SHA1; SHA256Summation SHA256; ++ SHA256Summation SHA512; string fileHash; FileFd Fd(filename, FileFd::ReadOnly); @@@ -75,6 -75,6 +76,11 @@@ SHA256.AddFD(Fd.Fd(), Fd.Size()); fileHash = (string)SHA256.Result(); } ++ else if (Type == "SHA512") ++ { ++ SHA512.AddFD(Fd.Fd(), Fd.Size()); ++ fileHash = (string)SHA512.Result(); ++ } Fd.Close(); if(_config->FindB("Debug::Hashes",false) == true) @@@ -119,6 -119,6 +125,7 @@@ bool Hashes::AddFD(int Fd,unsigned lon MD5.Add(Buf,Res); SHA1.Add(Buf,Res); SHA256.Add(Buf,Res); ++ SHA512.Add(Buf,Res); } return true; } diff --cc apt-pkg/contrib/hashes.h index 264f7fe90,264f7fe90..b3587e02a --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@@ -17,6 -17,6 +17,7 @@@ #include #include #include ++#include #include #include @@@ -60,10 -60,10 +61,11 @@@ class Hashe MD5Summation MD5; SHA1Summation SHA1; SHA256Summation SHA256; ++ SHA512Summation SHA512; inline bool Add(const unsigned char *Data,unsigned long Size) { -- return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size); ++ return MD5.Add(Data,Size) && SHA1.Add(Data,Size) && SHA256.Add(Data,Size) && SHA512.Add(Data,Size); }; inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));}; bool AddFD(int Fd,unsigned long Size); diff --cc apt-pkg/deb/debrecords.cc index ec9e395ef,ec9e395ef..1ca9ae1d2 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@@ -77,7 -77,7 +77,7 @@@ string debRecordParser::SHA1Hash( return Section.FindS("SHA1"); } /*}}}*/ --// RecordParser::SHA1Hash - Return the archive hash /*{{{*/ ++// RecordParser::SHA256Hash - Return the archive hash /*{{{*/ // --------------------------------------------------------------------- /* */ string debRecordParser::SHA256Hash() @@@ -85,6 -85,6 +85,14 @@@ return Section.FindS("SHA256"); } /*}}}*/ ++// RecordParser::SHA512Hash - Return the archive hash /*{{{*/ ++// --------------------------------------------------------------------- ++/* */ ++string debRecordParser::SHA512Hash() ++{ ++ return Section.FindS("SHA512"); ++} ++ /*}}}*/ // RecordParser::Maintainer - Return the maintainer email /*{{{*/ // --------------------------------------------------------------------- /* */ diff --cc apt-pkg/deb/debrecords.h index 6f358abfa,6f358abfa..05159ea1e --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@@ -36,6 -36,6 +36,7 @@@ class debRecordParser : public pkgRecor virtual string MD5Hash(); virtual string SHA1Hash(); virtual string SHA256Hash(); ++ virtual string SHA512Hash(); virtual string SourcePkg(); virtual string SourceVer(); diff --cc apt-pkg/pkgrecords.h index c2c98188a,c2c98188a..2d994211d --- a/apt-pkg/pkgrecords.h +++ b/apt-pkg/pkgrecords.h @@@ -58,6 -58,6 +58,7 @@@ class pkgRecords::Parser /*{{{* virtual string MD5Hash() {return string();}; virtual string SHA1Hash() {return string();}; virtual string SHA256Hash() {return string();}; ++ virtual string SHA512Hash() {return string();}; virtual string SourcePkg() {return string();}; virtual string SourceVer() {return string();}; diff --cc apt-pkg/tagfile.cc index 4a2f3f7e6,4a2f3f7e6..b7245073d --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@@ -457,6 -457,6 +457,7 @@@ static const char *iTFRewritePackageOrd "MD5Sum", "SHA1", "SHA256", ++ "SHA512", "MSDOS-Filename", // Obsolete "Description", 0}; diff --cc cmdline/apt-get.cc index e93d12c2b,e93d12c2b..61efa5601 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@@ -2239,6 -2239,6 +2239,8 @@@ bool DoDownload(CommandLine &CmdL strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr()); // get the most appropriate hash HashString hash; ++ if (rec.SHA512Hash() != "") ++ hash = HashString("sha512", rec.SHA512Hash()); if (rec.SHA256Hash() != "") hash = HashString("sha256", rec.SHA256Hash()); else if (rec.SHA1Hash() != "")