diff --git a/lang/qt/src/qgpgmewkdlookupjob.cpp b/lang/qt/src/qgpgmewkdlookupjob.cpp index fcb757e1..b8622167 100644 --- a/lang/qt/src/qgpgmewkdlookupjob.cpp +++ b/lang/qt/src/qgpgmewkdlookupjob.cpp @@ -118,11 +118,11 @@ static GpgME::Error setUpDirmngrAssuanConnection(Context *ctx) return err; } -static GpgME::Error run_wkd_get(Context *ctx, const QString &email) +static GpgME::Error run_wkd_get(Context *ctx, const std::string &email) { Error err; - const auto cmd = std::string{"WKD_GET "} + email.toUtf8().toStdString(); + const auto cmd = std::string{"WKD_GET "} + email; err = ctx->assuanTransact(cmd.c_str()); if (err.code() == GPG_ERR_NO_NAME || err.code() == GPG_ERR_NO_DATA) { // ignore those benign errors; GPG_ERR_NO_NAME indicates that the domain @@ -146,8 +146,9 @@ static QGpgMEWKDLookupJob::result_type lookup_keys(Context *ctx, const QString & Error err = setUpDirmngrAssuanConnection(ctx); + const auto pattern = email.toUtf8().toStdString(); if (!err) { - err = run_wkd_get(ctx, email); + err = run_wkd_get(ctx, pattern); } if (!err) { @@ -156,14 +157,14 @@ static QGpgMEWKDLookupJob::result_type lookup_keys(Context *ctx, const QString & const auto rawData = transaction->data(); if (rawData.size() == 0) { qCDebug(QGPGME_LOG) << "No key found for" << email; - result = WKDLookupResult{GpgME::Data::null, {}, {}}; + result = WKDLookupResult{pattern, GpgME::Data::null, {}, {}}; } else { qCDebug(QGPGME_LOG) << "Found key for" << email << "at" << source.c_str(); - result = WKDLookupResult{GpgME::Data{rawData.c_str(), rawData.size()}, source, {}}; + result = WKDLookupResult{pattern, GpgME::Data{rawData.c_str(), rawData.size()}, source, {}}; } } - return std::make_tuple(err ? WKDLookupResult{err} : result, QString{}, Error{}); + return std::make_tuple(err ? WKDLookupResult{pattern, err} : result, QString{}, Error{}); } Error QGpgMEWKDLookupJob::start(const QString &email) diff --git a/lang/qt/src/wkdlookupresult.cpp b/lang/qt/src/wkdlookupresult.cpp index 71aa75cf..ac1a89e9 100644 --- a/lang/qt/src/wkdlookupresult.cpp +++ b/lang/qt/src/wkdlookupresult.cpp @@ -45,6 +45,7 @@ using namespace GpgME; class WKDLookupResult::Private { public: + std::string pattern; GpgME::Data keyData; std::string source; }; @@ -53,15 +54,15 @@ WKDLookupResult::WKDLookupResult() = default; WKDLookupResult::~WKDLookupResult() = default; -WKDLookupResult::WKDLookupResult(const Error &error) +WKDLookupResult::WKDLookupResult(const std::string &pattern, const Error &error) : Result{error} - , d{} + , d{new Private{pattern, {}, {}}} { } -WKDLookupResult::WKDLookupResult(const Data &keyData, const std::string &source, const Error &error) +WKDLookupResult::WKDLookupResult(const std::string &pattern, const Data &keyData, const std::string &source, const Error &error) : Result{error} - , d{new Private{keyData, source}} + , d{new Private{pattern, keyData, source}} { } @@ -95,6 +96,11 @@ bool WKDLookupResult::isNull() const return !d && !bool(error()); } +std::string WKDLookupResult::pattern() const +{ + return d ? d->pattern : std::string{}; +} + Data WKDLookupResult::keyData() const { return d ? d->keyData : Data{}; diff --git a/lang/qt/src/wkdlookupresult.h b/lang/qt/src/wkdlookupresult.h index c40220a6..5696fb6d 100644 --- a/lang/qt/src/wkdlookupresult.h +++ b/lang/qt/src/wkdlookupresult.h @@ -55,8 +55,8 @@ public: WKDLookupResult(); ~WKDLookupResult(); - explicit WKDLookupResult(const GpgME::Error &err); - explicit WKDLookupResult(const GpgME::Data &keyData, const std::string &source, const GpgME::Error &err); + explicit WKDLookupResult(const std::string &pattern, const GpgME::Error &err); + explicit WKDLookupResult(const std::string &pattern, const GpgME::Data &keyData, const std::string &source, const GpgME::Error &err); WKDLookupResult(const WKDLookupResult &other); WKDLookupResult &operator=(const WKDLookupResult &other); @@ -68,6 +68,7 @@ public: bool isNull() const; + std::string pattern() const; GpgME::Data keyData() const; std::string source() const; diff --git a/lang/qt/tests/t-wkdlookup.cpp b/lang/qt/tests/t-wkdlookup.cpp index 0fbe67a2..a09591cb 100644 --- a/lang/qt/tests/t-wkdlookup.cpp +++ b/lang/qt/tests/t-wkdlookup.cpp @@ -97,6 +97,7 @@ private Q_SLOTS: QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); QVERIFY(result.error().code() == GPG_ERR_NO_ERROR); + QCOMPARE(result.pattern(), "wk@gnupg.org"); QCOMPARE(result.source(), "https://openpgpkey.gnupg.org"); const auto keys = result.keyData().toKeys(GpgME::OpenPGP); QVERIFY(keys.size() == 1); @@ -117,6 +118,7 @@ private Q_SLOTS: const auto result = job->exec(email); QVERIFY(result.error().code() == GPG_ERR_NO_ERROR); + QCOMPARE(result.pattern(), "wk@gnupg.org"); QCOMPARE(result.source(), "https://openpgpkey.gnupg.org"); const auto keys = result.keyData().toKeys(GpgME::OpenPGP); QVERIFY(keys.size() == 1); @@ -145,6 +147,7 @@ private Q_SLOTS: QVERIFY(spy.wait(QSIGNALSPY_TIMEOUT)); QVERIFY(result.error().code() == GPG_ERR_NO_ERROR); + QCOMPARE(result.pattern(), "alfa@example.net"); QCOMPARE(result.source(), ""); QVERIFY(result.keyData().isNull()); }