aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src
diff options
context:
space:
mode:
Diffstat (limited to 'lang/qt/src')
-rw-r--r--lang/qt/src/Makefile.am2
-rw-r--r--lang/qt/src/importjob.cpp78
-rw-r--r--lang/qt/src/importjob.h8
-rw-r--r--lang/qt/src/qgpgmeimportjob.cpp34
4 files changed, 116 insertions, 6 deletions
diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am
index 261eff60..b9171a60 100644
--- a/lang/qt/src/Makefile.am
+++ b/lang/qt/src/Makefile.am
@@ -40,7 +40,7 @@ qgpgme_sources = \
qgpgmekeyformailboxjob.cpp qgpgme_debug.cpp \
qgpgmetofupolicyjob.cpp qgpgmequickjob.cpp \
defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp \
- qgpgmegpgcardjob.cpp changeexpiryjob.cpp \
+ qgpgmegpgcardjob.cpp changeexpiryjob.cpp importjob.cpp \
dn.cpp cryptoconfig.cpp wkdlookupresult.cpp
# If you add one here make sure that you also add one in camelcase
diff --git a/lang/qt/src/importjob.cpp b/lang/qt/src/importjob.cpp
new file mode 100644
index 00000000..3f28606f
--- /dev/null
+++ b/lang/qt/src/importjob.cpp
@@ -0,0 +1,78 @@
+/*
+ importjob.cpp
+
+ This file is part of qgpgme, the Qt API binding for gpgme
+ Copyright (c) 2021 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 "importjob.h"
+#include "job_p.h"
+
+#include <context.h>
+
+using namespace GpgME;
+using namespace QGpgME;
+
+namespace
+{
+struct ImportJobPrivate : public JobPrivate
+{
+ ImportJobPrivate()
+ {
+ }
+
+ ~ImportJobPrivate() override = default;
+
+ Key::Origin m_keyOrigin = Key::OriginUnknown;
+ QString m_keyOriginUrl;
+};
+}
+
+void ImportJob::setKeyOrigin(GpgME::Key::Origin origin, const QString &url)
+{
+ const auto d = jobPrivate<ImportJobPrivate>(this);
+ d->m_keyOrigin = origin;
+ d->m_keyOriginUrl = url;
+}
+
+GpgME::Key::Origin ImportJob::keyOrigin() const
+{
+ const auto d = jobPrivate<ImportJobPrivate>(this);
+ return d->m_keyOrigin;
+}
+
+QString ImportJob::keyOriginUrl() const
+{
+ const auto d = jobPrivate<ImportJobPrivate>(this);
+ return d->m_keyOriginUrl;
+}
diff --git a/lang/qt/src/importjob.h b/lang/qt/src/importjob.h
index 7437fbdc..1ded1cde 100644
--- a/lang/qt/src/importjob.h
+++ b/lang/qt/src/importjob.h
@@ -40,6 +40,8 @@
#include <QtCore/QByteArray>
+#include <gpgme++/key.h>
+
namespace GpgME
{
class Error;
@@ -68,7 +70,11 @@ class QGPGME_EXPORT ImportJob : public AbstractImportJob
protected:
explicit ImportJob(QObject *parent);
public:
- ~ImportJob();
+ ~ImportJob() override;
+
+ void setKeyOrigin(GpgME::Key::Origin origin, const QString &url = {});
+ GpgME::Key::Origin keyOrigin() const;
+ QString keyOriginUrl() const;
/**
Starts the importing operation. \a keyData contains the data to
diff --git a/lang/qt/src/qgpgmeimportjob.cpp b/lang/qt/src/qgpgmeimportjob.cpp
index a62d05f9..ad5c2aee 100644
--- a/lang/qt/src/qgpgmeimportjob.cpp
+++ b/lang/qt/src/qgpgmeimportjob.cpp
@@ -55,10 +55,36 @@ QGpgMEImportJob::QGpgMEImportJob(Context *context)
lateInitialization();
}
-QGpgMEImportJob::~QGpgMEImportJob() {}
+QGpgMEImportJob::~QGpgMEImportJob() = default;
-static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &certData)
+static const char *originToString(Key::Origin origin)
{
+ static const std::map<Key::Origin, const char *> mapping = {
+ { Key::OriginUnknown, "unknown" },
+ { Key::OriginKS, "ks" },
+ { Key::OriginDane, "dane" },
+ { Key::OriginWKD, "wkd" },
+ { Key::OriginURL, "url" },
+ { Key::OriginFile, "file" },
+ { Key::OriginSelf, "self" },
+ };
+ const auto it = mapping.find(origin);
+ return (it != std::end(mapping)) ? it->second : nullptr;
+}
+
+static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &certData, Key::Origin keyOrigin, const QString &keyOriginUrl)
+{
+ if (keyOrigin != Key::OriginUnknown) {
+ if (const auto origin = originToString(keyOrigin)) {
+ std::string value{origin};
+ if (!keyOriginUrl.isEmpty()) {
+ value += ",";
+ value += keyOriginUrl.toStdString();
+ }
+ ctx->setFlag("key-origin", value.c_str());
+ }
+ }
+
QGpgME::QByteArrayDataProvider dp(certData);
Data data(&dp);
@@ -70,13 +96,13 @@ static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &c
Error QGpgMEImportJob::start(const QByteArray &certData)
{
- run(std::bind(&import_qba, std::placeholders::_1, certData));
+ run(std::bind(&import_qba, std::placeholders::_1, certData, keyOrigin(), keyOriginUrl()));
return Error();
}
GpgME::ImportResult QGpgME::QGpgMEImportJob::exec(const QByteArray &keyData)
{
- const result_type r = import_qba(context(), keyData);
+ const result_type r = import_qba(context(), keyData, keyOrigin(), keyOriginUrl());
resultHook(r);
return mResult;
}