qt: Add pattern used for WKD lookup to result
* lang/qt/src/qgpgmewkdlookupjob.cpp (run_wkd_get): Change type of arg email. (lookup_keys): Add pattern to result. * lang/qt/src/wkdlookupresult.h (class WKDLookupResult): Add arg pattern to c'tors. Add member function pattern. * lang/qt/src/wkdlookupresult.cpp (class WKDLookupResult::Private): Add field pattern. (WKDLookupResult::WKDLookupResult): Pass pattern to pimpl. (WKDLookupResult::pattern): New. * lang/qt/tests/t-wkdlookup.cpp (testWKDLookupAsync, testWKDLookupSync, testLookupWithNoResultAsync): Check pattern. -- GnuPG-bug-id: 5728
This commit is contained in:
parent
fd680254da
commit
af820811ec
@ -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)
|
||||
|
@ -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{};
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user