From 05fae6fae95d8ef6690f3d56863e3bb6a44d424c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 1 Apr 2022 11:37:26 +0200 Subject: Parse Checksum fields via pkgTagSection::Key, too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We abstract hashes a fair bit to be able to add new ones eventually, which lead us to building the field names on the fly. We can do better through by keeping a central place for these names, too, which even helps in reducing code as we don't need the MD5 → Files dance anymore. --- apt-pkg/contrib/hashes.cc | 11 +++++++++++ apt-pkg/contrib/hashes.h | 14 ++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 267e2679a..313b1d37d 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include @@ -45,6 +47,15 @@ const char * HashString::_SupportedHashes[] = { "SHA512", "SHA256", "SHA1", "MD5Sum", "Checksum-FileSize", NULL }; +std::vector HashString::SupportedHashesInfo() +{ + return {{ + { "SHA512", pkgTagSection::Key::SHA512,"Checksums-Sha512", pkgTagSection::Key::Checksums_Sha512}, + { "SHA256", pkgTagSection::Key::SHA256, "Checksums-Sha256", pkgTagSection::Key::Checksums_Sha256}, + { "SHA1", pkgTagSection::Key::SHA1, "Checksums-Sha1", pkgTagSection::Key::Checksums_Sha1 }, + { "MD5Sum", pkgTagSection::Key::MD5sum, "Files", pkgTagSection::Key::Files }, + }}; +} HashString::HashString() { diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index 422c1e023..e259b4e28 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -14,6 +14,11 @@ #include +#ifdef APT_COMPILING_APT +#include +#include +#endif + #include #include #include @@ -59,6 +64,15 @@ class APT_PUBLIC HashString // return the list of hashes we support static APT_PURE const char** SupportedHashes(); +#ifdef APT_COMPILING_APT + struct APT_HIDDEN HashSupportInfo { + APT::StringView name; + pkgTagSection::Key namekey; + APT::StringView chksumsname; + pkgTagSection::Key chksumskey; + }; + APT_HIDDEN static std::vector SupportedHashesInfo(); +#endif }; class APT_PUBLIC HashStringList -- cgit v1.2.3-70-g09d2