[PATCH gpgme] qt: Add setInputEncoding to QGpgMe::EncryptJob
Ingo Klöcker
kloecker at kde.org
Fri Jul 28 10:38:57 CEST 2023
Compared to reviews on GitLab this is really painful.
On Freitag, 28. Juli 2023 10:16:02 CEST Carl Schwan via Gnupg-devel wrote:
> * lang/qt/src/encryptjob.h, lang/qt/src/qgpgmeencryptjob.cpp,
> lang/qt/src/qgpgmeencryptjob.h: Add setInputEncoding to EncryptJob
> --
>
> This allows applications like KMail to set the input encoding of the
> encrypted content, which simplify and improve the performance of
> identify the content type then decrypting it.
>
> GnuPG-bug-id: 6616
> Signed-off-by: Carl Schwan <carl.schwan at gnupg.com>
> ---
> lang/qt/src/encryptjob.h | 4 ++++
> lang/qt/src/qgpgmeencryptjob.cpp | 20 +++++++++++++++-----
> lang/qt/src/qgpgmeencryptjob.h | 5 +++++
> 3 files changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/lang/qt/src/encryptjob.h b/lang/qt/src/encryptjob.h
> index 8135053e..7d4b3049 100644
> --- a/lang/qt/src/encryptjob.h
> +++ b/lang/qt/src/encryptjob.h
> @@ -38,6 +38,7 @@
> #define __KLEO_ENCRYPTJOB_H__
>
> #include "job.h"
> +#include "data.h"
>
> #include <memory>
> #include <vector>
> @@ -119,6 +120,9 @@ public:
> */
> virtual void setOutputIsBase64Encoded(bool) = 0;
>
> + /** Set the input encoding */
> + virtual void setInputEncoding(GpgME::Data::Encoding) = 0;
> +
Usually, adding virtuals before other virtuals will cause crashes. I did this
in a past GpgME release and we had to do a patch release to fix this. I'm
not sure whether adding a pure virtual is okay because it doesn't change
the vtable of the public EncryptJob. I use abidiff to check that I didn't
break ABI. Using a non-virtual setter as setFileName() would save us any
worrying about ABI breakage.
> /** Like start but with an additional argument for EncryptionFlags for
> * more flexibility. */
> virtual void start(const std::vector<GpgME::Key> &recipients,
> diff --git a/lang/qt/src/qgpgmeencryptjob.cpp
> b/lang/qt/src/qgpgmeencryptjob.cpp index 5ea6162c..cf43d7cb 100644
> --- a/lang/qt/src/qgpgmeencryptjob.cpp
> +++ b/lang/qt/src/qgpgmeencryptjob.cpp
> @@ -88,7 +88,8 @@ private:
>
> QGpgMEEncryptJob::QGpgMEEncryptJob(Context *context)
>
> : mixin_type(context),
>
> - mOutputIsBase64Encoded(false)
> + mOutputIsBase64Encoded(false),
> + mInputEncoding(Data::Encoding::AutoEncoding)
> {
> setJobPrivate(this, std::unique_ptr<QGpgMEEncryptJobPrivate>{new
> QGpgMEEncryptJobPrivate{this}}); lateInitialization();
> @@ -101,12 +102,18 @@ void QGpgMEEncryptJob::setOutputIsBase64Encoded(bool
> on) mOutputIsBase64Encoded = on;
> }
>
> +void QGpgMEEncryptJob::setInputEncoding(Data::Encoding encoding)
> +{
> + mInputEncoding = encoding;
> +}
> +
> static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
> const std::vector<Key> &recipients,
> const std::weak_ptr<QIODevice> &plainText_,
> const std::weak_ptr<QIODevice> &cipherText_,
> const Context::EncryptionFlags eflags,
> bool outputIsBsse64Encoded,
> + Data::Encoding inputEncoding,
> const QString &fileName)
> {
>
> @@ -118,6 +125,8 @@ static QGpgMEEncryptJob::result_type encrypt(Context
> *ctx, QThread *thread,
>
> QGpgME::QIODeviceDataProvider in(plainText);
> Data indata(&in);
> + indata.setEncoding(inputEncoding);
> +
> if (!plainText->isSequential()) {
> indata.setSizeHint(plainText->size());
> }
> @@ -155,20 +164,20 @@ 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, const
> Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, const QString
> &fileName) +static QGpgMEEncryptJob::result_type encrypt_qba(Context *ctx,
> const std::vector<Key> &recipients, const QByteArray &plainText, const
> Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, Data::Encoding
> inputEncoding, const QString &fileName) {
> const std::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, nullptr, recipients, buffer,
> std::shared_ptr<QIODevice>(), eflags, outputIsBsse64Encoded, fileName); +
> return encrypt(ctx, nullptr, recipients, buffer,
> std::shared_ptr<QIODevice>(), eflags, outputIsBsse64Encoded, inputEncoding,
> fileName); }
>
> Error QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const
> QByteArray &plainText, bool alwaysTrust) {
> run(std::bind(&encrypt_qba, std::placeholders::_1, recipients,
> plainText, - alwaysTrust ? Context::AlwaysTrust :
> Context::None, mOutputIsBase64Encoded, fileName())); +
> alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded,
> mInputEncoding, fileName())); return Error();
> }
>
> @@ -181,6 +190,7 @@ void QGpgMEEncryptJob::start(const std::vector<Key>
> &recipients, const std::shar std::placeholders::_3, std::placeholders::_4,
> eflags,
> mOutputIsBase64Encoded,
> + mInputEncoding,
> fileName()),
> plainText, cipherText);
> }
> @@ -188,7 +198,7 @@ void QGpgMEEncryptJob::start(const std::vector<Key>
> &recipients, const std::shar 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,
> eflags, mOutputIsBase64Encoded, fileName()); + const result_type r =
> encrypt_qba(context(), recipients, plainText, eflags,
> mOutputIsBase64Encoded, mInputEncoding, fileName()); cipherText =
> std::get<1>(r);
> resultHook(r);
> return mResult;
> diff --git a/lang/qt/src/qgpgmeencryptjob.h b/lang/qt/src/qgpgmeencryptjob.h
> index 07b05f8f..a32b70cf 100644
> --- a/lang/qt/src/qgpgmeencryptjob.h
> +++ b/lang/qt/src/qgpgmeencryptjob.h
> @@ -38,6 +38,7 @@
> #include "encryptjob.h"
>
> #include "threadedjobmixin.h"
> +#include "data.h"
>
> #ifdef BUILDING_QGPGME
> # include "encryptionresult.h"
> @@ -97,11 +98,15 @@ public:
> /* from EncryptJob */
> void setOutputIsBase64Encoded(bool on) override;
>
> + /* from EncryptJob */
> + void setInputEncoding(GpgME::Data::Encoding encoding) override;
> +
> /* from ThreadedJobMixin */
> void resultHook(const result_type &r) override;
>
> private:
> bool mOutputIsBase64Encoded;
> + GpgME::Data::Encoding mInputEncoding;
> GpgME::EncryptionResult mResult;
> };
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20230728/f1bde4f2/attachment.sig>
More information about the Gnupg-devel
mailing list