aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src/qgpgmewkdrefreshjob.cpp
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2023-08-23 10:00:26 +0000
committerIngo Klöcker <[email protected]>2023-08-23 10:00:26 +0000
commit3f297387bf401475385c458e4d1d95b3eefaf3d8 (patch)
tree84c417987274d7a78a3579e6bf8e46b6bdbb0c46 /lang/qt/src/qgpgmewkdrefreshjob.cpp
parentqt,tests: Fix build in source directory, part 2 (diff)
downloadgpgme-3f297387bf401475385c458e4d1d95b3eefaf3d8.tar.gz
gpgme-3f297387bf401475385c458e4d1d95b3eefaf3d8.zip
qt: Allow specifying user IDs to use when refreshing keys via WKD
* lang/qt/src/wkdrefreshjob.h, lang/qt/src/wkdrefreshjob.cpp (WKDRefreshJob::start): New overload. * lang/qt/src/wkdrefreshjob_p.h (WKDRefreshJobPrivate): Add field m_userIds. * lang/qt/src/qgpgmewkdrefreshjob.cpp (toEmailAddresses): New. (locate_external_keys): Change return type and arguments. (refresh_keys): Remove. (QGpgMEWKDRefreshJobPrivate::startIt): Get emails from keys or user IDs. Remove duplicates. Call locate_external_keys instead of refresh_keys. * lang/qt/tests/run-wkdrefreshjob.cpp (CommandLineOptions, parseCommandLine): New. (main): Support new option --all-userids. -- The new start() overload allows to specify the user IDs to use for the WKD lookup explicitly. This allows updating user IDs via WKD which were originally not retrieved via WKD. GnuPG-bug-id: 6672
Diffstat (limited to 'lang/qt/src/qgpgmewkdrefreshjob.cpp')
-rw-r--r--lang/qt/src/qgpgmewkdrefreshjob.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/lang/qt/src/qgpgmewkdrefreshjob.cpp b/lang/qt/src/qgpgmewkdrefreshjob.cpp
index 8bad1ef1..f590ed4b 100644
--- a/lang/qt/src/qgpgmewkdrefreshjob.cpp
+++ b/lang/qt/src/qgpgmewkdrefreshjob.cpp
@@ -88,6 +88,21 @@ static QStringList toEmailAddressesOriginatingFromWKD(const std::vector<GpgME::K
return emails;
}
+static QStringList toEmailAddresses(const std::vector<GpgME::UserID> &userIds)
+{
+ const QStringList emails = std::accumulate(
+ std::begin(userIds),
+ std::end(userIds),
+ QStringList{},
+ [](QStringList &emails, const UserID &userId) {
+ if (!userId.isRevoked() && !userId.addrSpec().empty()) {
+ emails.push_back(QString::fromStdString(userId.addrSpec()));
+ }
+ return emails;
+ });
+ return emails;
+}
+
}
QGpgMEWKDRefreshJob::QGpgMEWKDRefreshJob(Context *context)
@@ -99,12 +114,11 @@ QGpgMEWKDRefreshJob::QGpgMEWKDRefreshJob(Context *context)
QGpgMEWKDRefreshJob::~QGpgMEWKDRefreshJob() = default;
-static ImportResult locate_external_keys(Context *ctx, const std::vector<Key> &keys)
+static QGpgMEWKDRefreshJob::result_type locate_external_keys(Context *ctx, const QStringList &emails)
{
- const auto emails = toEmailAddressesOriginatingFromWKD(keys);
qCDebug(QGPGME_LOG) << __func__ << "locating external keys for" << emails;
if (emails.empty()) {
- return ImportResult{};
+ return std::make_tuple(ImportResult{}, QString{}, Error{});
}
Context::KeyListModeSaver saver{ctx};
@@ -121,24 +135,22 @@ static ImportResult locate_external_keys(Context *ctx, const std::vector<Key> &k
qCDebug(QGPGME_LOG) << __func__ << "result:" << toLogString(result).c_str();
job.release();
- return result;
-}
-
-static QGpgMEWKDRefreshJob::result_type refresh_keys(Context *ctx, const std::vector<Key> &keys)
-{
- const auto result = locate_external_keys(ctx, keys);
-
return std::make_tuple(result, QString{}, Error{});
}
GpgME::Error QGpgMEWKDRefreshJobPrivate::startIt()
{
- if (m_keys.empty()) {
- return Error::fromCode(GPG_ERR_INV_VALUE);
+ QStringList emails;
+ if (!m_keys.empty()) {
+ emails = toEmailAddressesOriginatingFromWKD(m_keys);
+ } else {
+ emails = toEmailAddresses(m_userIds);
}
+ std::sort(emails.begin(), emails.end());
+ emails.erase(std::unique(emails.begin(), emails.end()), emails.end());
- q->run([=](Context *ctx) {
- return refresh_keys(ctx, m_keys);
+ q->run([emails](Context *ctx) {
+ return locate_external_keys(ctx, emails);
});
return {};