X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/6c55f07a5fa3612a5d59c61a17da5fe640eadc8b..82153438235144c485a8539b5c035e67bbef96e4:/apt-pkg/contrib/hashes.cc diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 4481321c4..755ad2035 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -129,6 +129,24 @@ APT_PURE bool HashString::empty() const /*{{{*/ return (Type.empty() || Hash.empty()); } /*}}}*/ + +APT_PURE static bool IsConfigured(const char *name, const char *what) +{ + std::string option; + strprintf(option, "APT::Hashes::%s::%s", name, what); + return _config->FindB(option, false); +} + +APT_PURE bool HashString::usable() const /*{{{*/ +{ + return ( + (Type != "Checksum-FileSize") && + (Type != "MD5Sum") && + (Type != "SHA1") && + !IsConfigured(Type.c_str(), "Untrusted") + ); +} + /*}}}*/ std::string HashString::toStr() const /*{{{*/ { return Type + ":" + Hash; @@ -151,10 +169,10 @@ bool HashStringList::usable() const /*{{{*/ std::string const forcedType = _config->Find("Acquire::ForceHash", ""); if (forcedType.empty() == true) { - // FileSize alone isn't usable - for (std::vector::const_iterator hs = list.begin(); hs != list.end(); ++hs) - if (hs->HashType() != "Checksum-FileSize") - return true; + // See if there is at least one usable hash + for (auto const &hs: list) + if (hs.usable()) + return true; return false; } return find(forcedType) != NULL;