summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-08-10 12:15:55 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-08-10 12:15:55 (GMT)
commitf93f14e544c8248612b91471600a99c6dc9bb3a5 (patch)
tree02d650aede46230435306abc12fa1da222de0f2e
parenta0fc9f8ca19718cc5d521538b91ad5b8a68d0b7c (diff)
Add support for EncryptJobs with generic flags
This adds a new overloads for start and exec that instead of distinct flags like always trust just accept any GpgME::Context::EncryptFlags. Backport from git.gnupg.org/gpgme 34b456c3f. git.gnupg.org/gpgme also contains unit tests for this. This is technically an ABI break but should not create problems in practice as the new symbols are added at the bottom of the vtable and there are no known implementers of the jobs outsite of libkleo.
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/backends/qgpgme/qgpgmeencryptjob.cpp32
-rw-r--r--src/backends/qgpgme/qgpgmeencryptjob.h10
-rw-r--r--src/backends/qgpgme/qgpgmesignencryptjob.cpp32
-rw-r--r--src/backends/qgpgme/qgpgmesignencryptjob.h12
-rw-r--r--src/kleo/encryptjob.h14
-rw-r--r--src/kleo/signencryptjob.h16
7 files changed, 96 insertions, 22 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9ef8dbb..31de25c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,7 @@ include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
-set(PIM_VERSION "5.3.43")
+set(PIM_VERSION "5.3.44")
set(LIBKLEO_LIB_VERSION ${PIM_VERSION})
set(QT_REQUIRED_VERSION "5.5.0")
set(GPGMEPP_LIB_VERSION "5.3.40")
diff --git a/src/backends/qgpgme/qgpgmeencryptjob.cpp b/src/backends/qgpgme/qgpgmeencryptjob.cpp
index b3a5042..2f70a9d 100644
--- a/src/backends/qgpgme/qgpgmeencryptjob.cpp
+++ b/src/backends/qgpgme/qgpgmeencryptjob.cpp
@@ -68,7 +68,7 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
const std::vector<Key> &recipients,
const weak_ptr<QIODevice> &plainText_,
const weak_ptr<QIODevice> &cipherText_,
- bool alwaysTrust,
+ const Context::EncryptionFlags eflags,
bool outputIsBsse64Encoded)
{
@@ -81,9 +81,6 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
QGpgME::QIODeviceDataProvider in(plainText);
const Data indata(&in);
- const Context::EncryptionFlags eflags =
- alwaysTrust ? Context::AlwaysTrust : Context::None;
-
if (!cipherText) {
QGpgME::QByteArrayDataProvider out;
Data outdata(&out);
@@ -112,41 +109,54 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
}
-static QGpgMEEncryptJob::result_type encrypt_qba(Context *ctx, const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust, bool outputIsBsse64Encoded)
+static QGpgMEEncryptJob::result_type encrypt_qba(Context *ctx, const std::vector<Key> &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded)
{
const shared_ptr<QBuffer> buffer(new QBuffer);
buffer->setData(plainText);
if (!buffer->open(QIODevice::ReadOnly)) {
assert(!"This should never happen: QBuffer::open() failed");
}
- return encrypt(ctx, 0, recipients, buffer, shared_ptr<QIODevice>(), alwaysTrust, outputIsBsse64Encoded);
+ return encrypt(ctx, 0, recipients, buffer, shared_ptr<QIODevice>(), eflags, outputIsBsse64Encoded);
}
Error QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust)
{
- run(boost::bind(&encrypt_qba, _1, recipients, plainText, alwaysTrust, mOutputIsBase64Encoded));
+ run(boost::bind(&encrypt_qba, _1, recipients, plainText,
+ alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded));
return Error();
}
-void QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const shared_ptr<QIODevice> &plainText, const shared_ptr<QIODevice> &cipherText, bool alwaysTrust)
+void QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const shared_ptr<QIODevice> &plainText,
+ const shared_ptr<QIODevice> &cipherText, const Context::EncryptionFlags eflags)
{
run(boost::bind(&encrypt,
_1, _2,
recipients,
_3, _4,
- alwaysTrust,
+ eflags,
mOutputIsBase64Encoded),
plainText, cipherText);
}
-EncryptionResult QGpgMEEncryptJob::exec(const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText)
+EncryptionResult QGpgMEEncryptJob::exec(const std::vector<Key> &recipients, const QByteArray &plainText,
+ const Context::EncryptionFlags eflags, QByteArray &cipherText)
{
- const result_type r = encrypt_qba(context(), recipients, plainText, alwaysTrust, mOutputIsBase64Encoded);
+ const result_type r = encrypt_qba(context(), recipients, plainText, eflags, mOutputIsBase64Encoded);
cipherText = get<1>(r);
resultHook(r);
return mResult;
}
+void QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const shared_ptr<QIODevice> &plainText, const shared_ptr<QIODevice> &cipherText, bool alwaysTrust)
+{
+ return start(recipients, plainText, cipherText, alwaysTrust ? Context::AlwaysTrust : Context::None);
+}
+
+EncryptionResult QGpgMEEncryptJob::exec(const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText)
+{
+ return exec(recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, cipherText);
+}
+
void QGpgMEEncryptJob::resultHook(const result_type &tuple)
{
mResult = get<0>(tuple);
diff --git a/src/backends/qgpgme/qgpgmeencryptjob.h b/src/backends/qgpgme/qgpgmeencryptjob.h
index 151c9be..9819022 100644
--- a/src/backends/qgpgme/qgpgmeencryptjob.h
+++ b/src/backends/qgpgme/qgpgmeencryptjob.h
@@ -73,6 +73,16 @@ public:
GpgME::EncryptionResult exec(const std::vector<GpgME::Key> &recipients,
const QByteArray &plainText, bool alwaysTrust,
QByteArray &cipherText) Q_DECL_OVERRIDE;
+ /* from EncryptJob */
+ void start(const std::vector<GpgME::Key> &recipients,
+ const boost::shared_ptr<QIODevice> &plainText,
+ const boost::shared_ptr<QIODevice> &cipherText,
+ const GpgME::Context::EncryptionFlags flags) Q_DECL_OVERRIDE;
+
+ /* from EncryptJob */
+ GpgME::EncryptionResult exec(const std::vector<GpgME::Key> &recipients,
+ const QByteArray &plainText, const GpgME::Context::EncryptionFlags flags,
+ QByteArray &cipherText) Q_DECL_OVERRIDE;
/*! \reimp from Job */
void showErrorDialog(QWidget *parent, const QString &caption) const Q_DECL_OVERRIDE;
diff --git a/src/backends/qgpgme/qgpgmesignencryptjob.cpp b/src/backends/qgpgme/qgpgmesignencryptjob.cpp
index c532178..cd14b06 100644
--- a/src/backends/qgpgme/qgpgmesignencryptjob.cpp
+++ b/src/backends/qgpgme/qgpgmesignencryptjob.cpp
@@ -65,7 +65,9 @@ void QGpgMESignEncryptJob::setOutputIsBase64Encoded(bool on)
mOutputIsBase64Encoded = on;
}
-static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thread, const std::vector<Key> &signers, const std::vector<Key> &recipients, const weak_ptr<QIODevice> &plainText_, const weak_ptr<QIODevice> &cipherText_, bool alwaysTrust, bool outputIsBsse64Encoded)
+static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thread, const std::vector<Key> &signers,
+ const std::vector<Key> &recipients, const weak_ptr<QIODevice> &plainText_,
+ const weak_ptr<QIODevice> &cipherText_, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded)
{
const shared_ptr<QIODevice> &plainText = plainText_.lock();
const shared_ptr<QIODevice> &cipherText = cipherText_.lock();
@@ -76,9 +78,6 @@ static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thr
QGpgME::QIODeviceDataProvider in(plainText);
const Data indata(&in);
- const Context::EncryptionFlags eflags =
- alwaysTrust ? Context::AlwaysTrust : Context::None;
-
ctx->clearSigningKeys();
Q_FOREACH (const Key &signer, signers)
if (!signer.isNull())
@@ -114,35 +113,48 @@ static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thr
}
-static QGpgMESignEncryptJob::result_type sign_encrypt_qba(Context *ctx, const std::vector<Key> &signers, const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust, bool outputIsBsse64Encoded)
+static QGpgMESignEncryptJob::result_type sign_encrypt_qba(Context *ctx, const std::vector<Key> &signers,
+ const std::vector<Key> &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded)
{
const shared_ptr<QBuffer> buffer(new QBuffer);
buffer->setData(plainText);
if (!buffer->open(QIODevice::ReadOnly)) {
assert(!"This should never happen: QBuffer::open() failed");
}
- return sign_encrypt(ctx, 0, signers, recipients, buffer, shared_ptr<QIODevice>(), alwaysTrust, outputIsBsse64Encoded);
+ return sign_encrypt(ctx, 0, signers, recipients, buffer, shared_ptr<QIODevice>(), eflags, outputIsBsse64Encoded);
}
Error QGpgMESignEncryptJob::start(const std::vector<Key> &signers, const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust)
{
- run(boost::bind(&sign_encrypt_qba, _1, signers, recipients, plainText, alwaysTrust, mOutputIsBase64Encoded));
+ run(boost::bind(&sign_encrypt_qba, _1, signers, recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded));
return Error();
}
+void QGpgMESignEncryptJob::start(const std::vector<Key> &signers, const std::vector<Key> &recipients,
+ const shared_ptr<QIODevice> &plainText, const shared_ptr<QIODevice> &cipherText, const Context::EncryptionFlags eflags)
+{
+ run(boost::bind(&sign_encrypt, _1, _2, signers, recipients, _3, _4, eflags, mOutputIsBase64Encoded), plainText, cipherText);
+}
+
void QGpgMESignEncryptJob::start(const std::vector<Key> &signers, const std::vector<Key> &recipients, const shared_ptr<QIODevice> &plainText, const shared_ptr<QIODevice> &cipherText, bool alwaysTrust)
{
- run(boost::bind(&sign_encrypt, _1, _2, signers, recipients, _3, _4, alwaysTrust, mOutputIsBase64Encoded), plainText, cipherText);
+ return start(signers, recipients, plainText, cipherText, alwaysTrust ? Context::AlwaysTrust : Context::None);
}
-std::pair<SigningResult, EncryptionResult> QGpgMESignEncryptJob::exec(const std::vector<Key> &signers, const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText)
+std::pair<SigningResult, EncryptionResult> QGpgMESignEncryptJob::exec(const std::vector<Key> &signers, const std::vector<Key> &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, QByteArray &cipherText)
{
- const result_type r = sign_encrypt_qba(context(), signers, recipients, plainText, alwaysTrust, mOutputIsBase64Encoded);
+ const result_type r = sign_encrypt_qba(context(), signers, recipients, plainText, eflags, mOutputIsBase64Encoded);
cipherText = get<2>(r);
resultHook(r);
return mResult;
}
+std::pair<SigningResult, EncryptionResult> QGpgMESignEncryptJob::exec(const std::vector<Key> &signers, const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText)
+{
+ return exec(signers, recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, cipherText);
+}
+
+
void QGpgMESignEncryptJob::showErrorDialog(QWidget *parent, const QString &caption) const
{
if ((mResult.first.error() && !mResult.first.error().isCanceled()) ||
diff --git a/src/backends/qgpgme/qgpgmesignencryptjob.h b/src/backends/qgpgme/qgpgmesignencryptjob.h
index 74c4ef0..3e72716 100644
--- a/src/backends/qgpgme/qgpgmesignencryptjob.h
+++ b/src/backends/qgpgme/qgpgmesignencryptjob.h
@@ -74,12 +74,24 @@ public:
const boost::shared_ptr<QIODevice> &cipherText,
bool alwaysTrust) Q_DECL_OVERRIDE;
+ void start(const std::vector<GpgME::Key> &signers,
+ const std::vector<GpgME::Key> &recipients,
+ const boost::shared_ptr<QIODevice> &plainText,
+ const boost::shared_ptr<QIODevice> &cipherText,
+ const GpgME::Context::EncryptionFlags flags) Q_DECL_OVERRIDE;
+
std::pair<GpgME::SigningResult, GpgME::EncryptionResult>
exec(const std::vector<GpgME::Key> &signers,
const std::vector<GpgME::Key> &recipients,
const QByteArray &plainText, bool alwaysTrust,
QByteArray &cipherText) Q_DECL_OVERRIDE;
+ std::pair<GpgME::SigningResult, GpgME::EncryptionResult>
+ exec(const std::vector<GpgME::Key> &signers,
+ const std::vector<GpgME::Key> &recipients,
+ const QByteArray &plainText, const GpgME::Context::EncryptionFlags flags,
+ QByteArray &cipherText) Q_DECL_OVERRIDE;
+
/*! \reimp from Job */
void showErrorDialog(QWidget *parent, const QString &caption) const Q_DECL_OVERRIDE;
diff --git a/src/kleo/encryptjob.h b/src/kleo/encryptjob.h
index 2dc59f5..75cc3b4 100644
--- a/src/kleo/encryptjob.h
+++ b/src/kleo/encryptjob.h
@@ -39,6 +39,8 @@
#include <vector>
+#include <gpgme++/context.h>
+
class QByteArray;
class QIODevice;
@@ -110,6 +112,18 @@ public:
*/
virtual void setOutputIsBase64Encoded(bool) = 0;
+ /** Like start but with an additional argument for EncryptionFlags for
+ * more flexibility. */
+ virtual void start(const std::vector<GpgME::Key> &recipients,
+ const boost::shared_ptr<QIODevice> &plainText,
+ const boost::shared_ptr<QIODevice> &cipherText = boost::shared_ptr<QIODevice>(),
+ const GpgME::Context::EncryptionFlags flags = GpgME::Context::None) = 0;
+
+ /** Like exec but with an additional argument for EncryptionFlags for
+ * more flexibility. */
+ virtual GpgME::EncryptionResult exec(const std::vector<GpgME::Key> &recipients,
+ const QByteArray &plainText,
+ const GpgME::Context::EncryptionFlags flags, QByteArray &cipherText) = 0;
Q_SIGNALS:
void result(const GpgME::EncryptionResult &result, const QByteArray &cipherText, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error());
};
diff --git a/src/kleo/signencryptjob.h b/src/kleo/signencryptjob.h
index 6ea11e3..57e9b75 100644
--- a/src/kleo/signencryptjob.h
+++ b/src/kleo/signencryptjob.h
@@ -36,6 +36,7 @@
#include "job.h"
#include <gpgme++/global.h>
+#include <gpgme++/context.h>
#include <boost/shared_ptr.hpp>
@@ -119,6 +120,21 @@ public:
*/
virtual void setOutputIsBase64Encoded(bool) = 0;
+ /** Like start but with an additional argument for EncryptionFlags for
+ * more flexibility. */
+ virtual void start(const std::vector<GpgME::Key> &signers,
+ const std::vector<GpgME::Key> &recipients,
+ const boost::shared_ptr<QIODevice> &plainText,
+ const boost::shared_ptr<QIODevice> &cipherText = boost::shared_ptr<QIODevice>(),
+ const GpgME::Context::EncryptionFlags flags = GpgME::Context::None) = 0;
+
+ /** Like exec but with an additional argument for EncryptionFlags for
+ * more flexibility. */
+ virtual std::pair<GpgME::SigningResult, GpgME::EncryptionResult>
+ exec(const std::vector<GpgME::Key> &signers,
+ const std::vector<GpgME::Key> &recipients,
+ const QByteArray &plainText,
+ const GpgME::Context::EncryptionFlags flags, QByteArray &cipherText) = 0;
Q_SIGNALS:
void result(const GpgME::SigningResult &signingresult,
const GpgME::EncryptionResult &encryptionresult,