diff options
author | Saturneric <[email protected]> | 2021-12-02 21:35:16 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-12-02 21:35:16 +0000 |
commit | 1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc (patch) | |
tree | 58cabfa5c0065632b97823b6e6f068c04f1fa2e9 /src/gpg | |
parent | Fix and Modified. (diff) | |
download | GpgFrontend-1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc.tar.gz GpgFrontend-1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc.zip |
Fixed.
1. Fixed known issue in File Operations.
Diffstat (limited to 'src/gpg')
-rw-r--r-- | src/gpg/function/BasicOperator.cpp | 22 | ||||
-rw-r--r-- | src/gpg/function/BasicOperator.h | 6 | ||||
-rw-r--r-- | src/gpg/function/GpgFileOpera.cpp | 53 | ||||
-rw-r--r-- | src/gpg/function/GpgFileOpera.h | 7 |
4 files changed, 47 insertions, 41 deletions
diff --git a/src/gpg/function/BasicOperator.cpp b/src/gpg/function/BasicOperator.cpp index e92d4cfe..912119e2 100644 --- a/src/gpg/function/BasicOperator.cpp +++ b/src/gpg/function/BasicOperator.cpp @@ -29,16 +29,16 @@ #include "gpg/function/GpgKeyGetter.h" GpgFrontend::GpgError GpgFrontend::BasicOperator::Encrypt( - GpgFrontend::KeyArgsList&& keys, GpgFrontend::BypeArrayRef in_buffer, + KeyListPtr keys, GpgFrontend::BypeArrayRef in_buffer, GpgFrontend::ByteArrayPtr& out_buffer, GpgFrontend::GpgEncrResult& result) { // gpgme_encrypt_result_t e_result; - gpgme_key_t recipients[keys.size() + 1]; + gpgme_key_t recipients[keys->size() + 1]; int index = 0; - for (const auto& key : keys) recipients[index++] = gpgme_key_t(key); + for (const auto& key : *keys) recipients[index++] = gpgme_key_t(key); // Last entry data_in array has to be nullptr - recipients[keys.size()] = nullptr; + recipients[keys->size()] = nullptr; GpgData data_in(in_buffer.data(), in_buffer.size()), data_out; @@ -90,7 +90,7 @@ GpgFrontend::GpgError GpgFrontend::BasicOperator::Verify( return err; } -GpgFrontend::GpgError GpgFrontend::BasicOperator::Sign(KeyArgsList&& keys, +GpgFrontend::GpgError GpgFrontend::BasicOperator::Sign(KeyListPtr keys, BypeArrayRef in_buffer, ByteArrayPtr& out_buffer, gpgme_sig_mode_t mode, @@ -98,7 +98,7 @@ GpgFrontend::GpgError GpgFrontend::BasicOperator::Sign(KeyArgsList&& keys, gpgme_error_t err; // Set Singers of this opera - SetSigners(keys); + SetSigners(*keys); GpgData data_in(in_buffer.data(), in_buffer.size()), data_out; @@ -149,21 +149,21 @@ gpgme_error_t GpgFrontend::BasicOperator::DecryptVerify( } gpgme_error_t GpgFrontend::BasicOperator::EncryptSign( - KeyArgsList&& keys, KeyArgsList&& signers, BypeArrayRef in_buffer, + KeyListPtr keys, KeyListPtr signers, BypeArrayRef in_buffer, ByteArrayPtr& out_buffer, GpgEncrResult& encr_result, GpgSignResult& sign_result) { gpgme_error_t err; - SetSigners(signers); + SetSigners(*signers); // gpgme_encrypt_result_t e_result; - gpgme_key_t recipients[keys.size() + 1]; + gpgme_key_t recipients[keys->size() + 1]; // set key for user int index = 0; - for (const auto& key : keys) recipients[index++] = gpgme_key_t(key); + for (const auto& key : *keys) recipients[index++] = gpgme_key_t(key); // Last entry dataIn array has to be nullptr - recipients[keys.size()] = nullptr; + recipients[keys->size()] = nullptr; GpgData data_in(in_buffer.data(), in_buffer.size()), data_out; diff --git a/src/gpg/function/BasicOperator.h b/src/gpg/function/BasicOperator.h index e83ade70..39f93668 100644 --- a/src/gpg/function/BasicOperator.h +++ b/src/gpg/function/BasicOperator.h @@ -34,10 +34,10 @@ namespace GpgFrontend { class BasicOperator : public SingletonFunctionObject<BasicOperator> { public: - gpg_error_t Encrypt(KeyArgsList&& keys, BypeArrayRef in_buffer, + gpg_error_t Encrypt(KeyListPtr keys, BypeArrayRef in_buffer, ByteArrayPtr& out_buffer, GpgEncrResult& result); - gpgme_error_t EncryptSign(KeyArgsList&& keys, KeyArgsList&& signers, + gpgme_error_t EncryptSign(KeyListPtr keys, KeyListPtr signers, BypeArrayRef in_buffer, ByteArrayPtr& out_buffer, GpgEncrResult& encr_result, GpgSignResult& sign_result); @@ -52,7 +52,7 @@ class BasicOperator : public SingletonFunctionObject<BasicOperator> { gpgme_error_t Verify(BypeArrayRef in_buffer, ByteArrayPtr& sig_buffer, GpgVerifyResult& result) const; - gpg_error_t Sign(KeyArgsList&& key_fprs, BypeArrayRef in_buffer, + gpg_error_t Sign(KeyListPtr keys, BypeArrayRef in_buffer, ByteArrayPtr& out_buffer, gpgme_sig_mode_t mode, GpgSignResult& result); diff --git a/src/gpg/function/GpgFileOpera.cpp b/src/gpg/function/GpgFileOpera.cpp index 67504c0d..c3f75cf8 100644 --- a/src/gpg/function/GpgFileOpera.cpp +++ b/src/gpg/function/GpgFileOpera.cpp @@ -30,16 +30,18 @@ #include "gpg/function/BasicOperator.h" GpgFrontend::GpgError GpgFrontend::GpgFileOpera::EncryptFile( - KeyArgsList&& keys, const std::string& path, GpgEncrResult& result) { + KeyListPtr keys, const std::string& path, GpgEncrResult& result) { std::string in_buffer = read_all_data_in_file(path); std::unique_ptr<std::string> out_buffer; auto err = BasicOperator::GetInstance().Encrypt(std::move(keys), in_buffer, out_buffer, result); - assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); - - write_buffer_to_file(path + ".asc", *out_buffer); + if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) + if (!write_buffer_to_file(path + ".asc", *out_buffer)) { + throw std::runtime_error("write_buffer_to_file error"); + }; + return err; } @@ -59,12 +61,15 @@ GpgFrontend::GpgError GpgFrontend::GpgFileOpera::DecryptFile( if (!(file_extension == ".asc" || file_extension == ".gpg")) out_file_name += ".out"; - write_buffer_to_file(out_file_name, *out_buffer); + if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) + if (!write_buffer_to_file(out_file_name, *out_buffer)) { + throw std::runtime_error("write_buffer_to_file error"); + }; return err; } -gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyArgsList&& keys, +gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyListPtr keys, const std::string& path, GpgSignResult& result) { auto in_buffer = read_all_data_in_file(path); @@ -73,9 +78,10 @@ gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyArgsList&& keys, auto err = BasicOperator::GetInstance().Sign( std::move(keys), in_buffer, out_buffer, GPGME_SIG_MODE_DETACH, result); - assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); - - write_buffer_to_file(path + ".sig", *out_buffer); + if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) + if (!write_buffer_to_file(path + ".sig", *out_buffer)) { + throw std::runtime_error("write_buffer_to_file error"); + }; return err; } @@ -103,29 +109,26 @@ gpgme_error_t GpgFrontend::GpgFileOpera::VerifyFile(const std::string& path, // TODO gpg_error_t GpgFrontend::GpgFileOpera::EncryptSignFile( - KeyArgsList&& keys, const std::string& path, GpgEncrResult& encr_res, - GpgSignResult& sign_res) { + KeyListPtr keys, KeyListPtr signer_keys, const std::string& path, + GpgEncrResult& encr_res, GpgSignResult& sign_res) { auto in_buffer = read_all_data_in_file(path); std::unique_ptr<std::string> out_buffer = nullptr; - // TODO Fill the vector - std::vector<GpgKey> signerKeys; - // TODO dealing with signer keys auto err = BasicOperator::GetInstance().EncryptSign( - std::move(keys), std::move(signerKeys), in_buffer, out_buffer, encr_res, + std::move(keys), std::move(signer_keys), in_buffer, out_buffer, encr_res, sign_res); auto out_path = path + ".gpg"; LOG(INFO) << "EncryptSignFile out_path" << out_path; LOG(INFO) << "EncryptSignFile out_buffer size" << out_buffer->size(); - bool result = write_buffer_to_file(out_path, *out_buffer); - LOG(INFO) << "EncryptSignFile write_buffer_to_file result" << result; - if (result) - return err; - else - throw std::runtime_error("write_buffer_to_file failed."); + if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) + if (!write_buffer_to_file(out_path, *out_buffer)) { + throw std::runtime_error("write_buffer_to_file error"); + }; + + return err; } gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile( @@ -149,9 +152,11 @@ gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile( out_file_name = path + ".out"; LOG(INFO) << "GpgFrontend::GpgFileOpera::DecryptVerifyFile out_file_name" << out_file_name; - if (!write_buffer_to_file(out_file_name, *out_buffer)) { - throw std::runtime_error("write_buffer_to_file error"); - }; + + if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) + if (!write_buffer_to_file(out_file_name, *out_buffer)) { + throw std::runtime_error("write_buffer_to_file error"); + }; return err; } diff --git a/src/gpg/function/GpgFileOpera.h b/src/gpg/function/GpgFileOpera.h index 5b467357..4aaf09f1 100644 --- a/src/gpg/function/GpgFileOpera.h +++ b/src/gpg/function/GpgFileOpera.h @@ -33,17 +33,18 @@ namespace GpgFrontend { class GpgFileOpera : public SingletonFunctionObject<GpgFileOpera> { public: - static GpgError EncryptFile(KeyArgsList&& keys, const std::string& path, + static GpgError EncryptFile(KeyListPtr keys, const std::string& path, GpgEncrResult& result); static GpgError DecryptFile(const std::string& path, GpgDecrResult& result); - static GpgError SignFile(KeyArgsList&& keys, const std::string& path, + static GpgError SignFile(KeyListPtr keys, const std::string& path, GpgSignResult& result); static GpgError VerifyFile(const std::string& path, GpgVerifyResult& result); - static GpgError EncryptSignFile(KeyArgsList&& keys, const std::string& path, + static GpgError EncryptSignFile(KeyListPtr keys, KeyListPtr signer_keys, + const std::string& path, GpgEncrResult& encr_res, GpgSignResult& sign_res); |