qt: Add setInputEncoding to QGpgMe::EncryptJob

* lang/qt/src/encryptjob.cpp, lang/qt/src/encryptjob.h,
lang/qt/src/encryptjob_p.h: Add inputEncoding/setInputEncoding
to EncryptJob
* lang/qt/src/qgpgmeencryptjob.cpp: Use newly added inputEncoding
to set encoding hint of the encrypted content
--

This allows applications like KMail to set the input encoding of the
encrypted content, which simplify and improve the performance of
identifying the content type then decrypting it.

GnuPG-bug-id: 6616
Signed-off-by: Carl Schwan <carl.schwan@gnupg.com>
This commit is contained in:
Carl Schwan 2023-07-28 10:10:46 +02:00
parent a9b28c79e9
commit d91d037fc1
No known key found for this signature in database
GPG Key ID: ED43C5FB2746F663
4 changed files with 26 additions and 4 deletions

View File

@ -51,3 +51,15 @@ QString EncryptJob::fileName() const
auto d = jobPrivate<EncryptJobPrivate>(this);
return d->m_fileName;
}
void EncryptJob::setInputEncoding(GpgME::Data::Encoding inputEncoding)
{
auto d = jobPrivate<EncryptJobPrivate>(this);
d->m_inputEncoding = inputEncoding;
}
GpgME::Data::Encoding EncryptJob::inputEncoding() const
{
auto d = jobPrivate<EncryptJobPrivate>(this);
return d->m_inputEncoding;
}

View File

@ -38,6 +38,7 @@
#define __KLEO_ENCRYPTJOB_H__
#include "job.h"
#include "data.h"
#include <memory>
#include <vector>
@ -85,6 +86,9 @@ public:
void setFileName(const QString &fileName);
QString fileName() const;
void setInputEncoding(GpgME::Data::Encoding);
GpgME::Data::Encoding inputEncoding() const;
/**
Starts the encryption operation. \a recipients is the a list of
keys to encrypt \a plainText to. Empty (null) keys are

View File

@ -35,6 +35,7 @@
#define __QGPGME_ENCRYPTJOB_P_H__
#include "job_p.h"
#include "data.h"
namespace QGpgME
{
@ -42,6 +43,7 @@ namespace QGpgME
struct EncryptJobPrivate : public JobPrivate
{
QString m_fileName;
GpgME::Data::Encoding m_inputEncoding;
};
}

View File

@ -107,6 +107,7 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
const std::weak_ptr<QIODevice> &cipherText_,
const Context::EncryptionFlags eflags,
bool outputIsBsse64Encoded,
Data::Encoding inputEncoding,
const QString &fileName)
{
@ -118,6 +119,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 +158,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, inputEncoding(), fileName()));
return Error();
}
@ -181,6 +184,7 @@ void QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const std::shar
std::placeholders::_3, std::placeholders::_4,
eflags,
mOutputIsBase64Encoded,
inputEncoding(),
fileName()),
plainText, cipherText);
}
@ -188,7 +192,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, inputEncoding(), fileName());
cipherText = std::get<1>(r);
resultHook(r);
return mResult;