diff options
| author | Ingo Klöcker <[email protected]> | 2023-06-19 15:52:30 +0000 |
|---|---|---|
| committer | Ingo Klöcker <[email protected]> | 2023-06-19 16:21:46 +0000 |
| commit | e608315392cc5b7ddf51e16dce5fe7e99b83f011 (patch) | |
| tree | fc455de8a1d6131d1780c2c64bc50fef6d98da48 /lang/qt/src/qgpgmeencryptarchivejob.cpp | |
| parent | core: Support writing the sign/encrypt output directly to a file (diff) | |
| download | gpgme-e608315392cc5b7ddf51e16dce5fe7e99b83f011.tar.gz gpgme-e608315392cc5b7ddf51e16dce5fe7e99b83f011.zip | |
qt: Support writing signed/encrypted archives directly to a file
* lang/qt/src/encryptarchivejob.cpp, lang/qt/src/encryptarchivejob.h
(EncryptArchiveJob): Add member functions setRecipients, recipients,
setInputPaths, inputPaths, setOutputFile, outputFile,
setEncryptionFlags, encryptionFlags.
* lang/qt/src/encryptarchivejob_p.h (EncryptArchiveJobPrivate): Add
members m_recipients, m_inputPaths, m_outputFilePath, m_encryptionFlags.
* lang/qt/src/qgpgmeencryptarchivejob.cpp (encrypt): Move creation of
outdata to encrypt_to_io_device.
(encrypt_to_io_device, encrypt_to_filename): New.
(QGpgMEEncryptArchiveJob::start): Use encrypt_to_io_device instead of
encrypt.
(QGpgMEEncryptArchiveJobPrivate::startIt): Start the job with the
values from member variables.
* lang/qt/src/qgpgmesignarchivejob.cpp (sign): Move creation of
outdata to sign_to_io_device.
(sign_to_io_device, sign_to_filename): New.
(QGpgMESignArchiveJob::start): Use sign_to_io_device instead of sign.
(QGpgMESignArchiveJobPrivate::startIt): Start the job with the
values from member variables.
* lang/qt/src/qgpgmesignencryptarchivejob.cpp (sign_encrypt): Move
creation of outdata to sign_encrypt_to_io_device.
(sign_encrypt_to_io_device, sign_encrypt_to_filename): New.
(QGpgMESignEncryptArchiveJob::start): Use sign_encrypt_to_io_device
instead of sign_encrypt.
(QGpgMESignEncryptArchiveJobPrivate::startIt): Start the job with the
values from member variables.
* lang/qt/src/signarchivejob.cpp, lang/qt/src/signarchivejob.h
(SignArchiveJob): Add member functions setSigner, signers,
setInputPaths, inputPaths, setOutputFile, outputFile.
* lang/qt/src/signarchivejob_p.h (SignArchiveJobPrivate): Add
members m_signers, m_inputPaths, m_outputFilePath.
* lang/qt/src/signencryptarchivejob.cpp,
lang/qt/src/signencryptarchivejob.h (SignEncryptArchiveJob): Add
member functions setSigner, signers, setRecipients, recipients,
setInputPaths, inputPaths, setOutputFile, outputFile,
setEncryptionFlags, encryptionFlags.
* lang/qt/src/signencryptarchivejob_p.h (SignEncryptArchiveJobPrivate):
Add members m_signers, m_recipients, m_inputPaths, m_outputFilePath,
m_encryptionFlags.
* lang/qt/tests/run-encryptarchivejob.cpp (createOutput): Remove.
(checkOutputFilePath): New.
(main): Create file output writing to stdout if no archive name (or "-")
is given. Exit if file with given archive name already exists. Make
the jobs write the created archive directly to the given archive name.
* lang/qt/tests/run-signarchivejob.cpp (createOutput): Remove.
(checkOutputFilePath): New.
(main): Create file output writing to stdout if no archive name (or "-")
is given. Exit if file with given archive name already exists. Make
the jobs write the created archive directly to the given archive name.
--
This makes it possible to tell gpgtar to write the created archive
directly to a specified file bypassing GpgME's Data IO.
GnuPG-bug-id: 6530
Diffstat (limited to 'lang/qt/src/qgpgmeencryptarchivejob.cpp')
| -rw-r--r-- | lang/qt/src/qgpgmeencryptarchivejob.cpp | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/lang/qt/src/qgpgmeencryptarchivejob.cpp b/lang/qt/src/qgpgmeencryptarchivejob.cpp index 6ae310e7..c7f84182 100644 --- a/lang/qt/src/qgpgmeencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmeencryptarchivejob.cpp @@ -44,6 +44,8 @@ #include "encryptarchivejob_p.h" #include "filelistdataprovider.h" +#include <QFile> + #include <data.h> using namespace QGpgME; @@ -65,11 +67,7 @@ public: ~QGpgMEEncryptArchiveJobPrivate() override = default; private: - GpgME::Error startIt() override - { - Q_ASSERT(!"Not supported by this Job class."); - return Error::fromCode(GPG_ERR_NOT_SUPPORTED); - } + GpgME::Error startIt() override; void startNow() override { @@ -90,25 +88,18 @@ QGpgMEEncryptArchiveJob::QGpgMEEncryptArchiveJob(Context *context) } static QGpgMEEncryptArchiveJob::result_type encrypt(Context *ctx, - QThread *thread, const std::vector<Key> &recipients, const std::vector<QString> &paths, - const std::weak_ptr<QIODevice> &cipherText_, + GpgME::Data &outdata, Context::EncryptionFlags flags, const QString &baseDirectory) { - const std::shared_ptr<QIODevice> cipherText = cipherText_.lock(); - const _detail::ToThreadMover ctMover(cipherText, thread); - QGpgME::FileListDataProvider in{paths}; Data indata(&in); if (!baseDirectory.isEmpty()) { indata.setFileName(baseDirectory.toStdString()); } - QGpgME::QIODeviceDataProvider out{cipherText}; - Data outdata(&out); - flags = static_cast<Context::EncryptionFlags>(flags | Context::EncryptArchive); const EncryptionResult res = ctx->encrypt(recipients, indata, outdata, flags); Error ae; @@ -116,6 +107,35 @@ static QGpgMEEncryptArchiveJob::result_type encrypt(Context *ctx, return std::make_tuple(res, log, ae); } +static QGpgMEEncryptArchiveJob::result_type encrypt_to_io_device(Context *ctx, + QThread *thread, + const std::vector<Key> &recipients, + const std::vector<QString> &paths, + const std::weak_ptr<QIODevice> &cipherText_, + Context::EncryptionFlags flags, + const QString &baseDirectory) +{ + const std::shared_ptr<QIODevice> cipherText = cipherText_.lock(); + const _detail::ToThreadMover ctMover(cipherText, thread); + QGpgME::QIODeviceDataProvider out{cipherText}; + Data outdata(&out); + + return encrypt(ctx, recipients, paths, outdata, flags, baseDirectory); +} + +static QGpgMEEncryptArchiveJob::result_type encrypt_to_filename(Context *ctx, + const std::vector<Key> &recipients, + const std::vector<QString> &paths, + const QString &outputFile, + Context::EncryptionFlags flags, + const QString &baseDirectory) +{ + Data outdata; + outdata.setFileName(QFile::encodeName(outputFile).constData()); + + return encrypt(ctx, recipients, paths, outdata, flags, baseDirectory); +} + GpgME::Error QGpgMEEncryptArchiveJob::start(const std::vector<GpgME::Key> &recipients, const std::vector<QString> &paths, const std::shared_ptr<QIODevice> &cipherText, @@ -125,7 +145,7 @@ GpgME::Error QGpgMEEncryptArchiveJob::start(const std::vector<GpgME::Key> &recip return Error::fromCode(GPG_ERR_INV_VALUE); } - run(std::bind(&encrypt, + run(std::bind(&encrypt_to_io_device, std::placeholders::_1, std::placeholders::_2, recipients, @@ -137,4 +157,17 @@ GpgME::Error QGpgMEEncryptArchiveJob::start(const std::vector<GpgME::Key> &recip return {}; } +GpgME::Error QGpgMEEncryptArchiveJobPrivate::startIt() +{ + if (m_outputFilePath.isEmpty()) { + return Error::fromCode(GPG_ERR_INV_VALUE); + } + + q->run([=](Context *ctx) { + return encrypt_to_filename(ctx, m_recipients, m_inputPaths, m_outputFilePath, m_encryptionFlags, m_baseDirectory); + }); + + return {}; +} + #include "qgpgmeencryptarchivejob.moc" |
