aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src/qgpgmeencryptjob.cpp
diff options
context:
space:
mode:
authorCarl Schwan <[email protected]>2023-07-28 08:10:46 +0000
committerCarl Schwan <[email protected]>2023-08-03 09:53:06 +0000
commitd91d037fc19f0bbec44210099dc0d0e358d3fd4a (patch)
tree1f445207a7811ef99f425c2512d3763fc2ab0a61 /lang/qt/src/qgpgmeencryptjob.cpp
parentcore: Prevent wrong plaintext when verifying clearsigned signature (diff)
downloadgpgme-d91d037fc19f0bbec44210099dc0d0e358d3fd4a.tar.gz
gpgme-d91d037fc19f0bbec44210099dc0d0e358d3fd4a.zip
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 <[email protected]>
Diffstat (limited to 'lang/qt/src/qgpgmeencryptjob.cpp')
-rw-r--r--lang/qt/src/qgpgmeencryptjob.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/lang/qt/src/qgpgmeencryptjob.cpp b/lang/qt/src/qgpgmeencryptjob.cpp
index 5ea6162c..cfb8d4ac 100644
--- a/lang/qt/src/qgpgmeencryptjob.cpp
+++ b/lang/qt/src/qgpgmeencryptjob.cpp
@@ -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;