From 15718cb2954d9df9af979f574cec859feb2ba052 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 8 Jan 2024 11:33:28 +0100 Subject: [PATCH] qt,cpp: Implement adding ADSKs to existing keys * lang/cpp/src/context.cpp: Add functions for adding ADSKs. * lang/cpp/src/context.h: Ditto. * lang/qt/src/qgpgmequickjob.cpp: Add implementation of ADSK job. * lang/qt/src/qgpgmequickjob.h: Ditto. * lang/qt/src/quickjob.h: Add job for adding ADSKs. --- lang/cpp/src/context.cpp | 10 ++++++++++ lang/cpp/src/context.h | 3 +++ lang/qt/src/qgpgmequickjob.cpp | 11 +++++++++++ lang/qt/src/qgpgmequickjob.h | 1 + lang/qt/src/quickjob.h | 3 +++ 5 files changed, 28 insertions(+) diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index 7d04e9cc..57f92394 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -1799,6 +1799,16 @@ Error Context::startRevokeSignature(const Key &key, const Key &signingKey, key.impl(), signingKey.impl(), uids.c_str(), flags)); } +Error Context::addAdsk(const Key &k, const char *adsk) +{ + return Error(d->lasterr = gpgme_op_createsubkey(d->ctx, k.impl(), adsk, 0, 0, GPGME_CREATE_ADSK)); +} + +Error Context::startAddAdsk(const Key &k, const char *adsk) +{ + return Error(d->lasterr = gpgme_op_createsubkey_start(d->ctx, k.impl(), adsk, 0, 0, GPGME_CREATE_ADSK)); +} + Error Context::setFlag(const char *name, const char *value) { return Error(d->lasterr = gpgme_set_ctx_flag(d->ctx, name, value)); diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h index 4d7fedf0..c4f968f4 100644 --- a/lang/cpp/src/context.h +++ b/lang/cpp/src/context.h @@ -324,6 +324,9 @@ public: Error startRevokeSignature(const Key &key, const Key &signingKey, const std::vector &userIds = std::vector()); + Error addAdsk(const Key &k, const char *adsk); + Error startAddAdsk(const Key &k, const char *adsk); + // using TofuInfo::Policy Error setTofuPolicy(const Key &k, unsigned int policy); Error setTofuPolicyStart(const Key &k, unsigned int policy); diff --git a/lang/qt/src/qgpgmequickjob.cpp b/lang/qt/src/qgpgmequickjob.cpp index 33f1178a..1c6023a4 100644 --- a/lang/qt/src/qgpgmequickjob.cpp +++ b/lang/qt/src/qgpgmequickjob.cpp @@ -109,6 +109,12 @@ static QGpgMEQuickJob::result_type revokeSignatureWorker(Context *ctx, return std::make_tuple(err, QString(), Error()); } +static QGpgMEQuickJob::result_type addAdskWorker(Context *ctx, const Key &key, const char *adsk) +{ + const auto err = ctx->addAdsk(key, adsk); + return std::make_tuple(err, QString(), Error()); +} + void QGpgMEQuickJob::startCreate(const QString &uid, const char *algo, const QDateTime &expires, @@ -142,4 +148,9 @@ void QGpgMEQuickJob::startRevokeSignature(const Key &key, const Key &signingKey, run(std::bind(&revokeSignatureWorker, std::placeholders::_1, key, signingKey, userIds)); } +void QGpgMEQuickJob::startAddAdsk(const GpgME::Key &key, const char *adsk) +{ + run(std::bind(&addAdskWorker, std::placeholders::_1, key, adsk)); +} + #include "qgpgmequickjob.moc" diff --git a/lang/qt/src/qgpgmequickjob.h b/lang/qt/src/qgpgmequickjob.h index 2f59d8d4..07b89e18 100644 --- a/lang/qt/src/qgpgmequickjob.h +++ b/lang/qt/src/qgpgmequickjob.h @@ -71,6 +71,7 @@ public: unsigned int flags = 0) override; void startRevokeSignature(const GpgME::Key &key, const GpgME::Key &signingKey, const std::vector &userIds = std::vector()) override; + void startAddAdsk(const GpgME::Key &key, const char *adsk) override; }; } diff --git a/lang/qt/src/quickjob.h b/lang/qt/src/quickjob.h index 612a53d0..2d159bbe 100644 --- a/lang/qt/src/quickjob.h +++ b/lang/qt/src/quickjob.h @@ -85,6 +85,9 @@ public: virtual void startRevokeSignature(const GpgME::Key &key, const GpgME::Key &signingKey, const std::vector &userIds = std::vector()) = 0; + /** Start --quick-add-adsk */ + virtual void startAddAdsk(const GpgME::Key &key, const char *adsk) = 0; + Q_SIGNALS: void result(const GpgME::Error &error, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error());