Commit 30fe9e01 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Use the helpers that were moved to libkleo

The helpers were moved to libkleo to make them available for other
users of this library.

GnuPG-bug-id: 5805
parent 702f05d2
......@@ -32,7 +32,7 @@ option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF)
# Standalone build. Find / include everything necessary.
set(KF5_MIN_VERSION "5.90.0")
set(KMIME_VERSION "5.19.40")
set(LIBKLEO_VERSION "5.19.49")
set(LIBKLEO_VERSION "5.19.50")
set(QT_REQUIRED_VERSION "5.15.2")
set(GPGME_REQUIRED_VERSION "1.15.0")
set(BOOST_REQUIRED_VERSION "1.58")
......
......@@ -25,6 +25,7 @@
#include <Libkleo/KeyListSortFilterProxyModel>
#include <Libkleo/KeyCache>
#include <Libkleo/KeyGroupImportExport>
#include <Libkleo/KeyHelpers>
#include <Libkleo/Predicates>
#include <Libkleo/Formatting>
#include <Libkleo/Stl_Util>
......@@ -724,63 +725,6 @@ void ImportCertificatesCommand::Private::importGroups()
filesToImportGroupsFrom.clear();
}
namespace
{
bool havePublicKeyForSignature(const GpgME::UserID::Signature &signature)
{
// GnuPG returns status "NoPublicKey" for missing signing keys, but also
// for expired or revoked signing keys.
return (signature.status() != GpgME::UserID::Signature::NoPublicKey)
|| !KeyCache::instance()->findByKeyIDOrFingerprint (signature.signerKeyID()).isNull();
}
auto accumulateMissingSignerKeys(const std::vector<GpgME::UserID::Signature> &signatures)
{
return std::accumulate(
std::begin(signatures), std::end(signatures),
std::set<QString>{},
[] (auto &keyIds, const auto &signature) {
if (!havePublicKeyForSignature(signature)) {
keyIds.insert(QLatin1String{signature.signerKeyID()});
}
return keyIds;
}
);
}
auto accumulateMissingSignerKeys(const std::vector<GpgME::UserID> &userIds)
{
return std::accumulate(
std::begin(userIds), std::end(userIds),
std::set<QString>(),
[] (auto &keyIds, const auto &userID) {
if (!userID.isBad()) {
const auto newKeyIds = accumulateMissingSignerKeys(userID.signatures());
std::copy(std::begin(newKeyIds), std::end(newKeyIds),
std::inserter(keyIds, std::end(keyIds)));
}
return keyIds;
}
);
}
auto accumulateMissingSignerKeys(const std::vector<GpgME::Key> &keys)
{
return std::accumulate(
std::begin(keys), std::end(keys),
std::set<QString>(),
[] (auto &keyIds, const auto &key) {
if (!key.isBad()) {
const auto newKeyIds = accumulateMissingSignerKeys(key.userIDs());
std::copy(std::begin(newKeyIds), std::end(newKeyIds),
std::inserter(keyIds, std::end(keyIds)));
}
return keyIds;
}
);
}
}
static auto accumulateNewKeys(std::vector<std::string> &fingerprints, const std::vector<GpgME::Import> &imports)
{
return std::accumulate(std::begin(imports), std::end(imports),
......@@ -810,8 +754,8 @@ std::set<QString> ImportCertificatesCommand::Private::getMissingSignerKeyIds(con
auto newOpenPGPKeys = KeyCache::instance()->findByFingerprint(accumulateNewOpenPGPKeys(results));
// update all new OpenPGP keys to get information about certifications
std::for_each(std::begin(newOpenPGPKeys), std::end(newOpenPGPKeys), std::mem_fn(&Key::update));
auto missingSignerKeys = accumulateMissingSignerKeys(newOpenPGPKeys);
return missingSignerKeys;
auto missingSignerKeyIds = Kleo::getMissingSignerKeyIds(newOpenPGPKeys);
return missingSignerKeyIds;
}
void ImportCertificatesCommand::Private::importSignerKeys(const std::set<QString> &keyIds)
......
......@@ -17,7 +17,7 @@
#include "commands/importcertificatefromkeyservercommand.h"
#include <Libkleo/KeyCache>
#include <Libkleo/KeyHelpers>
#include <QDialogButtonBox>
#include <QPushButton>
......@@ -82,55 +82,14 @@ WebOfTrustDialog::~WebOfTrustDialog()
dialog.sync();
}
namespace
{
bool havePublicKeyForSignature(const GpgME::UserID::Signature &signature)
{
// GnuPG returns status "NoPublicKey" for missing signing keys, but also
// for expired or revoked signing keys.
return (signature.status() != GpgME::UserID::Signature::NoPublicKey)
|| !KeyCache::instance()->findByKeyIDOrFingerprint (signature.signerKeyID()).isNull();
}
auto accumulateMissingSignerKeys(const std::vector<GpgME::UserID::Signature> &signatures)
{
return std::accumulate(
std::begin(signatures), std::end(signatures),
std::set<QString>{},
[] (auto &keyIds, const auto &signature) {
if (!havePublicKeyForSignature(signature)) {
keyIds.insert(QLatin1String{signature.signerKeyID()});
}
return keyIds;
}
);
}
auto accumulateMissingSignerKeys(const std::vector<GpgME::UserID> &userIds)
{
return std::accumulate(
std::begin(userIds), std::end(userIds),
std::set<QString>(),
[] (auto &keyIds, const auto &userID) {
if (!userID.isBad()) {
const auto newKeyIds = accumulateMissingSignerKeys(userID.signatures());
std::copy(std::begin(newKeyIds), std::end(newKeyIds),
std::inserter(keyIds, std::end(keyIds)));
}
return keyIds;
}
);
}
}
void WebOfTrustDialog::fetchMissingKeys()
{
if (key().isNull()) {
return;
}
const auto missingSignerKeys = accumulateMissingSignerKeys(key().userIDs());
const auto missingSignerKeyIds = Kleo::getMissingSignerKeyIds(key().userIDs());
auto cmd = new Kleo::ImportCertificateFromKeyserverCommand{QStringList{std::begin(missingSignerKeys), std::end(missingSignerKeys)}};
auto cmd = new Kleo::ImportCertificateFromKeyserverCommand{QStringList{std::begin(missingSignerKeyIds), std::end(missingSignerKeyIds)}};
cmd->setParentWidget(this);
mFetchKeysBtn->setEnabled(false);
connect(cmd, &Kleo::ImportCertificateFromKeyserverCommand::finished,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment