From 34b456c3fb9e59788b07a75441da482bb28bda87 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Tue, 9 Aug 2016 13:10:08 +0200 Subject: Qt: Add support for EncryptJobs with generic flags * lang/qt/src/encryptjob.h, lang/qt/src/signencryptjob.h, lang/qt/src/qgpgmeencryptjob.h, lang/qt/src/qgpgmeencryptjob.cpp, lang/qt/src/qgpgmesignencryptjob.cpp, lang/qt/src/qgpgmeencryptjob.cpp: Add start and exec overloads that accept generic EncryptFlags. -- While this technically is an ABI break (vtable change) there are no known classes outside qgpgme that inherit encryptjob or signencryptjob. And the new functions should be added to the bottom of the vtable. --- lang/qt/src/qgpgmesignencryptjob.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'lang/qt/src/qgpgmesignencryptjob.cpp') diff --git a/lang/qt/src/qgpgmesignencryptjob.cpp b/lang/qt/src/qgpgmesignencryptjob.cpp index d19ab0fc..d2e45b13 100644 --- a/lang/qt/src/qgpgmesignencryptjob.cpp +++ b/lang/qt/src/qgpgmesignencryptjob.cpp @@ -62,7 +62,9 @@ void QGpgMESignEncryptJob::setOutputIsBase64Encoded(bool on) mOutputIsBase64Encoded = on; } -static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thread, const std::vector &signers, const std::vector &recipients, const std::weak_ptr &plainText_, const std::weak_ptr &cipherText_, bool alwaysTrust, bool outputIsBsse64Encoded) +static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thread, const std::vector &signers, + const std::vector &recipients, const std::weak_ptr &plainText_, + const std::weak_ptr &cipherText_, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded) { const std::shared_ptr &plainText = plainText_.lock(); const std::shared_ptr &cipherText = cipherText_.lock(); @@ -73,9 +75,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()) @@ -111,35 +110,48 @@ static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thr } -static QGpgMESignEncryptJob::result_type sign_encrypt_qba(Context *ctx, const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust, bool outputIsBsse64Encoded) +static QGpgMESignEncryptJob::result_type sign_encrypt_qba(Context *ctx, const std::vector &signers, + const std::vector &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded) { const std::shared_ptr 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, std::shared_ptr(), alwaysTrust, outputIsBsse64Encoded); + return sign_encrypt(ctx, 0, signers, recipients, buffer, std::shared_ptr(), eflags, outputIsBsse64Encoded); } Error QGpgMESignEncryptJob::start(const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust) { - run(std::bind(&sign_encrypt_qba, std::placeholders::_1, signers, recipients, plainText, alwaysTrust, mOutputIsBase64Encoded)); + run(std::bind(&sign_encrypt_qba, std::placeholders::_1, signers, recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded)); return Error(); } +void QGpgMESignEncryptJob::start(const std::vector &signers, const std::vector &recipients, + const std::shared_ptr &plainText, const std::shared_ptr &cipherText, const Context::EncryptionFlags eflags) +{ + run(std::bind(&sign_encrypt, std::placeholders::_1, std::placeholders::_2, signers, recipients, std::placeholders::_3, std::placeholders::_4, eflags, mOutputIsBase64Encoded), plainText, cipherText); +} + void QGpgMESignEncryptJob::start(const std::vector &signers, const std::vector &recipients, const std::shared_ptr &plainText, const std::shared_ptr &cipherText, bool alwaysTrust) { - run(std::bind(&sign_encrypt, std::placeholders::_1, std::placeholders::_2, signers, recipients, std::placeholders::_3, std::placeholders::_4, alwaysTrust, mOutputIsBase64Encoded), plainText, cipherText); + return start(signers, recipients, plainText, cipherText, alwaysTrust ? Context::AlwaysTrust : Context::None); } -std::pair QGpgMESignEncryptJob::exec(const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText) +std::pair QGpgMESignEncryptJob::exec(const std::vector &signers, const std::vector &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 = std::get<2>(r); resultHook(r); return mResult; } +std::pair QGpgMESignEncryptJob::exec(const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText) +{ + return exec(signers, recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, cipherText); +} + + #if 0 TODO port? -- cgit v1.2.3