qt: Extend signkeyjob to handle remarks and dups

* lang/qt/src/qgpgmesignkeyjob.cpp: Handle remarks and
dupeOK.
* lang/qt/src/signkeyjob.h (SignKeyJob::setDupeOk),
(SignKeyJob::setRemark): New.

--
This API makes it easy for Kleopatra to add remarks for:
GnuPG-Bug-Id: T4734
This commit is contained in:
Andre Heinecke 2019-10-29 16:33:58 +01:00
parent 36f7f7a478
commit 373acd6923
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C
4 changed files with 61 additions and 3 deletions

5
NEWS
View File

@ -8,10 +8,15 @@ Noteworthy changes in version 1.14.0 (unreleased)
* cpp: The sign key edit-interactor now supports multiple signatures
from the same key. [#4734]
* qt: Extended signkeyjob to handle remarks and multiple signatures.
[#4734]
* Interface changes relative to the 1.13.1 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cpp: UserID::remark NEW.
cpp: GpgSignKeyEditInteractor::setDupeOk NEW.
qt: SignKeyJob::setDupeOk NEW.
qt: SignKeyJob::setRemark NEW.
Noteworthy changes in version 1.13.1 (2019-06-13)

View File

@ -57,14 +57,17 @@ QGpgMESignKeyJob::QGpgMESignKeyJob(Context *context)
m_checkLevel(0),
m_exportable(false),
m_nonRevocable(false),
m_started(false)
m_started(false),
m_dupeOk(false)
{
lateInitialization();
}
QGpgMESignKeyJob::~QGpgMESignKeyJob() {}
static QGpgMESignKeyJob::result_type sign_key(Context *ctx, const Key &key, const std::vector<unsigned int> &uids, unsigned int checkLevel, const Key &signer, unsigned int opts)
static QGpgMESignKeyJob::result_type sign_key(Context *ctx, const Key &key, const std::vector<unsigned int> &uids,
unsigned int checkLevel, const Key &signer, unsigned int opts,
bool dupeOk, const QString &remark)
{
QGpgME::QByteArrayDataProvider dp;
Data data(&dp);
@ -74,6 +77,15 @@ static QGpgMESignKeyJob::result_type sign_key(Context *ctx, const Key &key, cons
skei->setCheckLevel(checkLevel);
skei->setSigningOptions(opts);
if (dupeOk) {
ctx->setFlag("extended-edit", "1");
skei->setDupeOk(true);
}
if (!remark.isEmpty()) {
ctx->addSignatureNotation("rem@gnupg.org", remark.toUtf8().constData());
}
if (!signer.isNull())
if (const Error err = ctx->addSigningKey(signer)) {
return std::make_tuple(err, QString(), Error());
@ -93,7 +105,8 @@ Error QGpgMESignKeyJob::start(const Key &key)
if (m_exportable) {
opts |= GpgSignKeyEditInteractor::Exportable;
}
run(std::bind(&sign_key, std::placeholders::_1, key, m_userIDsToSign, m_checkLevel, m_signingKey, opts));
run(std::bind(&sign_key, std::placeholders::_1, key, m_userIDsToSign, m_checkLevel, m_signingKey, opts,
m_dupeOk, m_remark));
m_started = true;
return Error();
}
@ -127,4 +140,16 @@ void QGpgMESignKeyJob::setNonRevocable(bool nonRevocable)
assert(!m_started);
m_nonRevocable = nonRevocable;
}
void QGpgMESignKeyJob::setRemark(const QString &remark)
{
assert(!m_started);
m_remark = remark;
}
void QGpgMESignKeyJob::setDupeOk(bool value)
{
assert(!m_started);
m_dupeOk = value;
}
#include "qgpgmesignkeyjob.moc"

View File

@ -39,6 +39,8 @@
#include "threadedjobmixin.h"
#include <QString>
#ifdef BUILDING_QGPGME
# include "key.h"
#else
@ -82,6 +84,12 @@ public:
/* from SignKeyJob */
void setNonRevocable(bool nonRevocable) Q_DECL_OVERRIDE;
/* from SignKeyJob */
void setRemark(const QString &remark) Q_DECL_OVERRIDE;
/* from SignKeyJob */
void setDupeOk(bool value) Q_DECL_OVERRIDE;
private:
std::vector<unsigned int> m_userIDsToSign;
GpgME::Key m_signingKey;
@ -89,6 +97,8 @@ private:
bool m_exportable;
bool m_nonRevocable;
bool m_started;
bool m_dupeOk;
QString m_remark;
};
}

View File

@ -45,6 +45,8 @@ class Error;
class Key;
}
class QString;
namespace QGpgME
{
@ -109,6 +111,22 @@ public:
*/
virtual void setNonRevocable(bool nonRevocable) = 0;
/**
* Set this if it is ok to overwrite an existing signature. In that
* case the context has to have the flag "extended-edit" set to 1 through
* Context::setFlag before calling edit.
*
* Not pure virtual for ABI compatibility.
**/
virtual void setDupeOk(bool) {};
/**
* Add a remark to the signature. This uses rem@gnupg.org as a notation.
*
* Not pure virtual for ABI compatibility.
**/
virtual void setRemark(const QString &) {};
Q_SIGNALS:
void result(const GpgME::Error &result, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error());
};