diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index 19eae3df..37beab2a 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -27,12 +27,11 @@ #include "file_manager/i_file_manager.hpp" #include "types/repertory.hpp" #include "types/s3.hpp" -#include "types/startup_exception.hpp" #include "utils/collection.hpp" #include "utils/encrypting_reader.hpp" #include "utils/encryption.hpp" #include "utils/error_utils.hpp" -#include "utils/file_utils.hpp" +#include "utils/file.hpp" #include "utils/path.hpp" #include "utils/polling.hpp" #include "utils/string.hpp" @@ -748,25 +747,21 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size, if (res != api_error::success) { return res; } + const auto total_size = utils::string::to_uint64(temp); - auto total_size = utils::string::to_uint64(temp); - - res = api_error::success; - if (utils::encryption::read_encrypted_range( - {offset, offset + size - 1U}, - utils::encryption::generate_key( - cfg.encryption_token), - [&](data_buffer &ct_buffer, std::uint64_t start_offset, - std::uint64_t end_offset) -> bool { - res = read_bytes((end_offset - start_offset + 1U), start_offset, - ct_buffer); - return res == api_error::success; - }, - total_size, data)) { - return api_error::success; - } - - return res == api_error::success ? api_error::decryption_error : res; + return utils::encryption::read_encrypted_range( + {offset, offset + size - 1U}, + utils::encryption::generate_key( + cfg.encryption_token), + [&](data_buffer &ct_buffer, std::uint64_t start_offset, + std::uint64_t end_offset) -> bool { + return read_bytes((end_offset - start_offset + 1U), + start_offset, + ct_buffer) == api_error::success; + }, + total_size, data) + ? api_error::success + : api_error::decryption_error; } return read_bytes(size, offset, data); @@ -888,18 +883,16 @@ auto s3_provider::upload_file_impl(const std::string &api_path, const std::string &source_path, stop_type &stop_requested) -> api_error { std::uint64_t file_size{}; - auto file = utils::file::file{source_path}; - if (file.exists()) { - auto opt_size = file.size(); + if (utils::file::file{source_path}.exists()) { + auto opt_size = utils::file::file{source_path}.size(); if (not opt_size.has_value()) { return api_error::comm_error; } - file_size = opt_size.value(); } - auto cfg = get_config().get_s3_config(); - auto is_encrypted = not cfg.encryption_token.empty(); + const auto cfg = get_config().get_s3_config(); + const auto is_encrypted = not cfg.encryption_token.empty(); std::string key; if (is_encrypted) { @@ -909,7 +902,7 @@ auto s3_provider::upload_file_impl(const std::string &api_path, } } - auto object_name = + const auto object_name = utils::path::create_api_path(is_encrypted ? key : api_path); curl::requests::http_put_file put_file{}; diff --git a/support/src/utils/encryption.cpp b/support/src/utils/encryption.cpp index 22d77ced..d5c0be90 100644 --- a/support/src/utils/encryption.cpp +++ b/support/src/utils/encryption.cpp @@ -109,7 +109,7 @@ auto read_encrypted_range(const http_range &range, source_offset = 0U; } - return false; + return true; } #endif // defined(PROJECT_ENABLE_CURL) } // namespace repertory::utils::encryption