qt: Use --quick-set-ownertrust if available

* lang/qt/src/qgpgmechangeownertrustjob.cpp (set_owner_trust): New.
(QGpgMEChangeOwnerTrustJob::start): Use set_owner_trust if gpg is new
enough.

* lang/qt/tests/t-ownertrust.cpp
(ChangeOwnerTrustTest::testChangeOwnerTrust): Log unexpected error.
--

Using the --quick-set-ownertrust command to set the owner trust is much
more robust than using the edit interface. Prefer the former if gpg
supports it.

GnuPG-bug-id: 7239
This commit is contained in:
Ingo Klöcker 2024-08-06 18:08:11 +02:00
parent 668a1344c6
commit a73eee3655
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
2 changed files with 19 additions and 1 deletions

View File

@ -5,6 +5,8 @@
Copyright (c) 2008 Klarälvdalens Datakonsult AB
Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH
Copyright (c) 2024 g10 Code GmbH
Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@ -42,6 +44,7 @@
#include <gpgme++/context.h>
#include <gpgme++/data.h>
#include <gpgme++/engineinfo.h>
#include <gpgme++/gpgsetownertrusteditinteractor.h>
#include <gpgme++/key.h>
@ -59,6 +62,14 @@ QGpgMEChangeOwnerTrustJob::QGpgMEChangeOwnerTrustJob(Context *context)
QGpgMEChangeOwnerTrustJob::~QGpgMEChangeOwnerTrustJob() {}
static QGpgMEChangeOwnerTrustJob::result_type set_owner_trust(Context *ctx, const Key &key, Key::OwnerTrust trust)
{
const Error err = ctx->setOwnerTrust(key, trust);
Error ae;
const QString log = _detail::audit_log_as_html(ctx, ae);
return std::make_tuple(err, log, ae);
}
static QGpgMEChangeOwnerTrustJob::result_type change_ownertrust(Context *ctx, const Key &key, Key::OwnerTrust trust)
{
EditInteractor *ei = new GpgSetOwnerTrustEditInteractor(trust);
@ -75,7 +86,11 @@ static QGpgMEChangeOwnerTrustJob::result_type change_ownertrust(Context *ctx, co
Error QGpgMEChangeOwnerTrustJob::start(const Key &key, Key::OwnerTrust trust)
{
run(std::bind(&change_ownertrust, std::placeholders::_1, key, trust));
if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.4.6") {
run(std::bind(&change_ownertrust, std::placeholders::_1, key, trust));
} else {
run(std::bind(&set_owner_trust, std::placeholders::_1, key, trust));
}
return Error();
}
#include "qgpgmechangeownertrustjob.moc"

View File

@ -89,6 +89,9 @@ private Q_SLOTS:
ChangeOwnerTrustJob *job3 = openpgp()->changeOwnerTrustJob();
connect(job3, &ChangeOwnerTrustJob::result, this, [this](Error e)
{
if (e) {
qDebug() << "Error in result: " << e;
}
QVERIFY(!e);
Q_EMIT asyncDone();
});