refactor
This commit is contained in:
parent
3814b9797d
commit
04f50f7453
@ -799,30 +799,31 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (is_encrypted) {
|
if (not is_encrypted) {
|
||||||
std::string temp;
|
return read_bytes(size, offset, data);
|
||||||
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<utils::encryption::hash_256_t>(
|
|
||||||
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);
|
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<utils::encryption::hash_256_t>(
|
||||||
|
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) {
|
} catch (const std::exception &e) {
|
||||||
utils::error::raise_error(function_name, e, "exception occurred");
|
utils::error::raise_error(function_name, e, "exception occurred");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user