diff options
Diffstat (limited to 'src/core/function/gpg/GpgFileOpera.cpp')
-rw-r--r-- | src/core/function/gpg/GpgFileOpera.cpp | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp index 929c02ea..a8e33725 100644 --- a/src/core/function/gpg/GpgFileOpera.cpp +++ b/src/core/function/gpg/GpgFileOpera.cpp @@ -27,8 +27,6 @@ */ #include "GpgFileOpera.h" -#include <unistd.h> - #include "core/function/ArchiveFileOperator.h" #include "core/function/gpg/GpgBasicOperator.h" #include "core/model/GFBuffer.h" @@ -77,37 +75,35 @@ void GpgFileOpera::EncryptDirectory(std::vector<GpgKey> keys, bool ascii, const std::filesystem::path& out_path, const GpgOperationCallback& cb) { + std::shared_ptr<GFDataExchanger> ex = std::make_shared<GFDataExchanger>(8192); + RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { - std::array<int, 2> pipe_fds; - if (pipe(pipe_fds.data()) != 0) { - SPDLOG_ERROR( - "cannot create pipe for directory archive and encryt process"); - return GPG_ERR_EPIPE; - } - - ArchiveFileOperator::NewArchive2Fd( - in_path, pipe_fds[1], [](GFError err, const DataObjectPtr&) { - SPDLOG_DEBUG("new archive 2 fd operation, err: {}", err); - }); - std::vector<gpgme_key_t> recipients(keys.begin(), keys.end()); // Last entry data_in array has to be nullptr recipients.emplace_back(nullptr); - GpgData data_in(pipe_fds[0]); + GpgData data_in(ex); GpgData data_out(out_path, false); + SPDLOG_DEBUG("encrypt directory start"); + auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext(); auto err = CheckGpgError(gpgme_op_encrypt(ctx, recipients.data(), GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out)); data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx))}); + SPDLOG_DEBUG("encrypt directory finished, err: {}", err); return err; }, cb, "gpgme_op_encrypt", "2.1.0"); + + ArchiveFileOperator::NewArchive2DataExchanger( + in_path, ex, [=](GFError err, const DataObjectPtr&) { + SPDLOG_DEBUG("new archive 2 fd operation, err: {}", err); + }); } void GpgFileOpera::DecryptFile(const std::filesystem::path& in_path, @@ -131,31 +127,20 @@ void GpgFileOpera::DecryptFile(const std::filesystem::path& in_path, void GpgFileOpera::DecryptArchive(const std::filesystem::path& in_path, const std::filesystem::path& out_path, const GpgOperationCallback& cb) { - SPDLOG_DEBUG("decrypt archive start, cuurent thread: {}", - QThread::currentThread()->currentThreadId()); - RunGpgOperaAsync( - [=](const DataObjectPtr& data_object) -> GpgError { - std::array<int, 2> pipe_fds; - if (pipe(pipe_fds.data()) != 0) { - SPDLOG_ERROR( - "cannot create pipe for directory archive and encryt process"); - return GPG_ERR_EPIPE; - } + std::shared_ptr<GFDataExchanger> ex = std::make_shared<GFDataExchanger>(8192); - SPDLOG_DEBUG("decrypt archive processing, cuurent thread: {}", - QThread::currentThread()->currentThreadId()); - ArchiveFileOperator::ExtractArchiveFromFd( - pipe_fds[0], out_path, [](GFError err, const DataObjectPtr&) { - SPDLOG_DEBUG("extract archive from fd operation, err: {}", err); - }); + ArchiveFileOperator::ExtractArchiveFromDataExchanger( + ex, out_path, [](GFError err, const DataObjectPtr&) { + SPDLOG_DEBUG("extract archive from fd operation, err: {}", err); + }); + RunGpgOperaAsync( + [=](const DataObjectPtr& data_object) -> GpgError { GpgData data_in(in_path, true); - GpgData data_out(pipe_fds[1]); + GpgData data_out(ex); - SPDLOG_DEBUG("start to decrypt archive: {}", in_path.string()); auto err = CheckGpgError( gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out)); - SPDLOG_DEBUG("decryption of archive done: {}", in_path.string()); data_object->Swap( {GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext()))}); |