aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpg/function/GpgFileOpera.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-12-02 21:35:16 +0000
committerSaturneric <[email protected]>2021-12-02 21:35:16 +0000
commit1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc (patch)
tree58cabfa5c0065632b97823b6e6f068c04f1fa2e9 /src/gpg/function/GpgFileOpera.cpp
parentFix and Modified. (diff)
downloadGpgFrontend-1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc.tar.gz
GpgFrontend-1e3f1d13a6fb1bfc8f24be83032df1e92350dbcc.zip
Fixed.
1. Fixed known issue in File Operations.
Diffstat (limited to 'src/gpg/function/GpgFileOpera.cpp')
-rw-r--r--src/gpg/function/GpgFileOpera.cpp53
1 files changed, 29 insertions, 24 deletions
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;
}