aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src
diff options
context:
space:
mode:
Diffstat (limited to 'lang/qt/src')
-rw-r--r--lang/qt/src/Makefile.am6
-rw-r--r--lang/qt/src/addexistingsubkeyjob.h79
-rw-r--r--lang/qt/src/job.cpp3
-rw-r--r--lang/qt/src/protocol.h2
-rw-r--r--lang/qt/src/protocol_p.h14
-rw-r--r--lang/qt/src/qgpgmeaddexistingsubkeyjob.cpp96
-rw-r--r--lang/qt/src/qgpgmeaddexistingsubkeyjob.h68
7 files changed, 268 insertions, 0 deletions
diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am
index 792049af..c4f0e35f 100644
--- a/lang/qt/src/Makefile.am
+++ b/lang/qt/src/Makefile.am
@@ -27,6 +27,7 @@ qgpgme_sources = \
dataprovider.cpp \
debug.cpp \
job.cpp multideletejob.cpp qgpgmeadduseridjob.cpp \
+ qgpgmeaddexistingsubkeyjob.cpp \
qgpgmebackend.cpp qgpgmechangeexpiryjob.cpp qgpgmechangeownertrustjob.cpp \
qgpgmechangepasswdjob.cpp qgpgmedecryptjob.cpp \
qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.cpp \
@@ -46,6 +47,7 @@ qgpgme_sources = \
# If you add one here make sure that you also add one in camelcase
qgpgme_headers= \
abstractimportjob.h \
+ addexistingsubkeyjob.h \
adduseridjob.h \
changeexpiryjob.h \
changeownertrustjob.h \
@@ -88,6 +90,7 @@ qgpgme_headers= \
dn.h
camelcase_headers= \
+ AddExistingSubkeyJob \
AddUserIDJob \
AbstractImportJob \
ChangeExpiryJob \
@@ -133,6 +136,7 @@ private_qgpgme_headers = \
qgpgme_export.h \
protocol_p.h \
job_p.h \
+ qgpgmeaddexistingsubkeyjob.h \
qgpgmeadduseridjob.h \
qgpgmebackend.h \
qgpgmechangeexpiryjob.h \
@@ -165,6 +169,7 @@ private_qgpgme_headers = \
qgpgme_moc_sources = \
abstractimportjob.moc \
+ addexistingsubkeyjob.moc \
adduseridjob.moc \
changeexpiryjob.moc \
changeownertrustjob.moc \
@@ -183,6 +188,7 @@ qgpgme_moc_sources = \
keylistjob.moc \
listallkeysjob.moc \
multideletejob.moc \
+ qgpgmeaddexistingsubkeyjob.moc \
qgpgmeadduseridjob.moc \
qgpgmechangeexpiryjob.moc \
qgpgmechangeownertrustjob.moc \
diff --git a/lang/qt/src/addexistingsubkeyjob.h b/lang/qt/src/addexistingsubkeyjob.h
new file mode 100644
index 00000000..5465778c
--- /dev/null
+++ b/lang/qt/src/addexistingsubkeyjob.h
@@ -0,0 +1,79 @@
+/*
+ addexistingsubkeyjob.h
+
+ This file is part of qgpgme, the Qt API binding for gpgme
+ Copyright (c) 2022 g10 Code GmbH
+ Software engineering by Ingo Klöcker <[email protected]>
+
+ QGpgME is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ QGpgME is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifndef __QGPGME_ADDEXISTINGSUBKEYJOB_H__
+#define __QGPGME_ADDEXISTINGSUBKEYJOB_H__
+
+#include "job.h"
+#include "qgpgme_export.h"
+
+class QString;
+
+namespace GpgME
+{
+class Error;
+class Key;
+class Subkey;
+}
+
+namespace QGpgME
+{
+
+class QGPGME_EXPORT AddExistingSubkeyJob : public Job
+{
+ Q_OBJECT
+protected:
+ explicit AddExistingSubkeyJob(QObject *parent);
+
+public:
+ ~AddExistingSubkeyJob();
+
+ /**
+ Starts the operation. \a key is the key to add the subkey \a subkey to.
+
+ The job deletes itself after it has completed the operation.
+ */
+ virtual GpgME::Error start(const GpgME::Key &key, const GpgME::Subkey &subkey) = 0;
+
+ /**
+ Runs the operation. \a key is the key to add the subkey \a subkey to.
+ */
+ virtual GpgME::Error exec(const GpgME::Key &key, const GpgME::Subkey &subkey) = 0;
+
+Q_SIGNALS:
+ void result(const GpgME::Error &result, const QString &auditLogAsHtml = {}, const GpgME::Error &auditLogError = {});
+};
+
+}
+
+#endif // __QGPGME_ADDEXISTINGSUBKEYJOB_H__
diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp
index 79951481..14fe1426 100644
--- a/lang/qt/src/job.cpp
+++ b/lang/qt/src/job.cpp
@@ -61,6 +61,7 @@
#include "downloadjob.h"
#include "deletejob.h"
#include "refreshkeysjob.h"
+#include "addexistingsubkeyjob.h"
#include "adduseridjob.h"
#include "specialjob.h"
#include "keyformailboxjob.h"
@@ -160,6 +161,7 @@ make_job_subclass(ChangePasswdJob)
make_job_subclass(DownloadJob)
make_job_subclass(DeleteJob)
make_job_subclass(RefreshKeysJob)
+make_job_subclass(AddExistingSubkeyJob)
make_job_subclass(AddUserIDJob)
make_job_subclass(SpecialJob)
make_job_subclass(KeyForMailboxJob)
@@ -194,6 +196,7 @@ make_job_subclass(GpgCardJob)
#include "downloadjob.moc"
#include "deletejob.moc"
#include "refreshkeysjob.moc"
+#include "addexistingsubkeyjob.moc"
#include "adduseridjob.moc"
#include "specialjob.moc"
#include "keyformailboxjob.moc"
diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h
index e3caac28..3ffd99b3 100644
--- a/lang/qt/src/protocol.h
+++ b/lang/qt/src/protocol.h
@@ -40,6 +40,7 @@
#include "qgpgme_export.h"
namespace QGpgME {
+class AddExistingSubkeyJob;
class CryptoConfig;
class KeyListJob;
class ListAllKeysJob;
@@ -138,6 +139,7 @@ public:
virtual SignKeyJob *signKeyJob() const = 0;
virtual ChangePasswdJob *changePasswdJob() const = 0;
virtual ChangeOwnerTrustJob *changeOwnerTrustJob() const = 0;
+ virtual AddExistingSubkeyJob *addExistingSubkeyJob() const = 0;
virtual AddUserIDJob *addUserIDJob() const = 0;
virtual SpecialJob *specialJob(const char *type, const QMap<QString, QVariant> &args) const = 0;
diff --git a/lang/qt/src/protocol_p.h b/lang/qt/src/protocol_p.h
index 08100a48..a9cfd824 100644
--- a/lang/qt/src/protocol_p.h
+++ b/lang/qt/src/protocol_p.h
@@ -57,6 +57,7 @@
#include "qgpgmechangeexpiryjob.h"
#include "qgpgmechangeownertrustjob.h"
#include "qgpgmechangepasswdjob.h"
+#include "qgpgmeaddexistingsubkeyjob.h"
#include "qgpgmeadduseridjob.h"
#include "qgpgmekeyformailboxjob.h"
#include "qgpgmewkdlookupjob.h"
@@ -371,6 +372,19 @@ public:
return new QGpgME::QGpgMEChangeOwnerTrustJob(context);
}
+ QGpgME:: AddExistingSubkeyJob *addExistingSubkeyJob() const override
+ {
+ if (mProtocol != GpgME::OpenPGP) {
+ return nullptr; // only supported by gpg
+ }
+
+ GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
+ if (!context) {
+ return nullptr;
+ }
+ return new QGpgME::QGpgMEAddExistingSubkeyJob{context};
+ }
+
QGpgME::AddUserIDJob *addUserIDJob() const Q_DECL_OVERRIDE
{
if (mProtocol != GpgME::OpenPGP) {
diff --git a/lang/qt/src/qgpgmeaddexistingsubkeyjob.cpp b/lang/qt/src/qgpgmeaddexistingsubkeyjob.cpp
new file mode 100644
index 00000000..32e2c292
--- /dev/null
+++ b/lang/qt/src/qgpgmeaddexistingsubkeyjob.cpp
@@ -0,0 +1,96 @@
+/*
+ qgpgmeaddexistingsubkeyjob.cpp
+
+ This file is part of qgpgme, the Qt API binding for gpgme
+ Copyright (c) 2022 g10 Code GmbH
+ Software engineering by Ingo Klöcker <[email protected]>
+
+ QGpgME is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ QGpgME is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include "qgpgmeaddexistingsubkeyjob.h"
+
+#include "dataprovider.h"
+
+#include <QDateTime>
+
+#include "context.h"
+#include "data.h"
+#include "gpgaddexistingsubkeyeditinteractor.h"
+#include "key.h"
+
+#include <gpg-error.h>
+
+using namespace QGpgME;
+using namespace GpgME;
+
+QGpgMEAddExistingSubkeyJob::QGpgMEAddExistingSubkeyJob(Context *context)
+ : mixin_type{context}
+{
+ lateInitialization();
+}
+
+QGpgMEAddExistingSubkeyJob::~QGpgMEAddExistingSubkeyJob() = default;
+
+static QGpgMEAddExistingSubkeyJob::result_type add_subkey(Context *ctx, const Key &key, const Subkey &subkey)
+{
+ std::unique_ptr<GpgAddExistingSubkeyEditInteractor> interactor{new GpgAddExistingSubkeyEditInteractor{subkey.keyGrip()}};
+
+ if (!subkey.neverExpires()) {
+ const auto expiry = QDateTime::fromSecsSinceEpoch(subkey.expirationTime(), Qt::UTC).toString(u"yyyyMMdd'T'hhmmss").toStdString();
+ interactor->setExpiry(expiry);
+ }
+
+ QGpgME::QByteArrayDataProvider dp;
+ Data data(&dp);
+ assert(!data.isNull());
+
+ ctx->setFlag("extended-edit", "1");
+
+ const Error err = ctx->edit(key, std::unique_ptr<EditInteractor>(interactor.release()), data);
+ Error ae;
+ const QString log = _detail::audit_log_as_html(ctx, ae);
+ return std::make_tuple(err, log, ae);
+}
+
+Error QGpgMEAddExistingSubkeyJob::start(const GpgME::Key &key, const GpgME::Subkey &subkey)
+{
+ run(std::bind(&add_subkey, std::placeholders::_1, key, subkey));
+ return {};
+}
+
+Error QGpgMEAddExistingSubkeyJob::exec(const GpgME::Key &key, const GpgME::Subkey &subkey)
+{
+ const result_type r = add_subkey(context(), key, subkey);
+ resultHook(r);
+ return std::get<0>(r);
+}
+
+#include "qgpgmeaddexistingsubkeyjob.moc"
diff --git a/lang/qt/src/qgpgmeaddexistingsubkeyjob.h b/lang/qt/src/qgpgmeaddexistingsubkeyjob.h
new file mode 100644
index 00000000..15727552
--- /dev/null
+++ b/lang/qt/src/qgpgmeaddexistingsubkeyjob.h
@@ -0,0 +1,68 @@
+/*
+ qgpgmeaddexistingsubkeyjob.h
+
+ This file is part of qgpgme, the Qt API binding for gpgme
+ Copyright (c) 2022 g10 Code GmbH
+ Software engineering by Ingo Klöcker <[email protected]>
+
+ QGpgME is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ QGpgME is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifndef __QGPGME_QGPGMEADDEXISTINGSUBKEYJOB_H__
+#define __QGPGME_QGPGMEADDEXISTINGSUBKEYJOB_H__
+
+#include "threadedjobmixin.h"
+#include "addexistingsubkeyjob.h"
+
+namespace QGpgME
+{
+
+class QGpgMEAddExistingSubkeyJob
+#ifdef Q_MOC_RUN
+ : public AddExistingSubkeyJob
+#else
+ : public _detail::ThreadedJobMixin<AddExistingSubkeyJob>
+#endif
+{
+ Q_OBJECT
+#ifdef Q_MOC_RUN
+public Q_SLOTS:
+ void slotFinished();
+#endif
+public:
+ explicit QGpgMEAddExistingSubkeyJob(GpgME::Context *context);
+ ~QGpgMEAddExistingSubkeyJob();
+
+ /* from AddExistingSubkeyJob */
+ GpgME::Error start(const GpgME::Key &key, const GpgME::Subkey &subkey) override;
+
+ /* from AddExistingSubkeyJob */
+ GpgME::Error exec(const GpgME::Key &key, const GpgME::Subkey &subkey) override;
+};
+
+}
+
+#endif // __QGPGME_QGPGMEADDEXISTINGSUBKEYJOB_H__