From 04f50f74531979589a7f4b0d276cf81c4955b707 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 2 Dec 2024 13:56:08 -0600 Subject: [PATCH] refactor --- .../src/providers/s3/s3_provider.cpp | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index 47f41e03..ea80bb5f 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -799,30 +799,31 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size, return res; }; - if (is_encrypted) { - std::string temp; - auto res = get_item_meta(api_path, META_SIZE, temp); - if (res != api_error::success) { - return res; - } - const auto total_size = utils::string::to_uint64(temp); - - 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; + if (not is_encrypted) { + return read_bytes(size, offset, data); } - return read_bytes(size, offset, data); + std::string temp; + auto res = get_item_meta(api_path, META_SIZE, temp); + if (res != api_error::success) { + return res; + } + + const auto total_size = utils::string::to_uint64(temp); + 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; + } catch (const std::exception &e) { utils::error::raise_error(function_name, e, "exception occurred"); }