This commit is contained in:
Scott E. Graves 2024-08-05 19:50:48 -05:00
parent dca0752189
commit cbb99c7b47
6 changed files with 19 additions and 11 deletions

View File

@ -90,7 +90,8 @@ public:
data_buffer data{}; data_buffer data{};
const auto key = const auto key =
utils::encryption::generate_key(request.decryption_token.value()); utils::encryption::generate_key<utils::encryption::hash_256_t>(
request.decryption_token.value());
const auto result = utils::encryption::read_encrypted_range( const auto result = utils::encryption::read_encrypted_range(
request.range.value(), key, request.range.value(), key,
[&](data_buffer &ct, std::uint64_t start_offset, [&](data_buffer &ct, std::uint64_t start_offset,

View File

@ -36,10 +36,11 @@ using reader_func = std::function<api_error(data_buffer &cypher_text,
[[nodiscard]] auto decrypt_file_name(std::string_view encryption_token, [[nodiscard]] auto decrypt_file_name(std::string_view encryption_token,
std::string &file_name) -> api_error; std::string &file_name) -> api_error;
[[nodiscard]] auto read_encrypted_range(const http_range &range, [[nodiscard]] auto
const key_type &key, reader_func reader, read_encrypted_range(const http_range &range,
std::uint64_t total_size, const utils::encryption::hash_256_t &key &key,
data_buffer &data) -> api_error; reader_func reader, std::uint64_t total_size,
data_buffer &data) -> api_error;
} // namespace repertory::utils::encryption } // namespace repertory::utils::encryption
#endif // INCLUDE_UTILS_ENCRYPT_HPP_ #endif // INCLUDE_UTILS_ENCRYPT_HPP_

View File

@ -59,7 +59,7 @@ public:
using streambuf = std::basic_streambuf<char, std::char_traits<char>>; using streambuf = std::basic_streambuf<char, std::char_traits<char>>;
private: private:
key_type key_; utils::encryption::hash_256_t key_;
stop_type &stop_requested_; stop_type &stop_requested_;
size_t error_return_; size_t error_return_;
std::unordered_map<std::size_t, data_buffer> chunk_buffers_; std::unordered_map<std::size_t, data_buffer> chunk_buffers_;

View File

@ -736,7 +736,8 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
return utils::encryption::read_encrypted_range( return utils::encryption::read_encrypted_range(
{offset, offset + size - 1U}, {offset, offset + size - 1U},
utils::encryption::generate_key(cfg.encryption_token), utils::encryption::generate_key<utils::encryption::hash_256_t>(
cfg.encryption_token),
[&](data_buffer &ct_buffer, std::uint64_t start_offset, [&](data_buffer &ct_buffer, std::uint64_t start_offset,
std::uint64_t end_offset) -> api_error { std::uint64_t end_offset) -> api_error {
return read_bytes((end_offset - start_offset + 1U), start_offset, return read_bytes((end_offset - start_offset + 1U), start_offset,

View File

@ -26,6 +26,7 @@
#include "types/repertory.hpp" #include "types/repertory.hpp"
#include "utils/collection.hpp" #include "utils/collection.hpp"
#include "utils/encrypting_reader.hpp" #include "utils/encrypting_reader.hpp"
#include "utils/encryption.hpp"
#include "utils/utils.hpp" #include "utils/utils.hpp"
namespace repertory::utils::encryption { namespace repertory::utils::encryption {
@ -66,7 +67,8 @@ auto decrypt_file_name(std::string_view encryption_token,
return api_error::success; return api_error::success;
} }
auto read_encrypted_range(const http_range &range, const key_type &key, auto read_encrypted_range(const http_range &range,
const utils::encryption::hash_256_t &key,
reader_func reader, std::uint64_t total_size, reader_func reader, std::uint64_t total_size,
data_buffer &data) -> api_error { data_buffer &data) -> api_error {
const auto encrypted_chunk_size = const auto encrypted_chunk_size =

View File

@ -167,7 +167,8 @@ encrypting_reader::encrypting_reader(
stop_type &stop_requested, std::string_view token, stop_type &stop_requested, std::string_view token,
std::optional<std::string_view> relative_parent_path, std::optional<std::string_view> relative_parent_path,
std::size_t error_return) std::size_t error_return)
: key_(utils::encryption::generate_key(token)), : key_(utils::encryption::generate_key<utils::encryption::hash_256_t>(
token)),
stop_requested_(stop_requested), stop_requested_(stop_requested),
error_return_(error_return) { error_return_(error_return) {
const auto res = native_file::create_or_open(source_path, true, source_file_); const auto res = native_file::create_or_open(source_path, true, source_file_);
@ -219,7 +220,8 @@ encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
stop_type &stop_requested, stop_type &stop_requested,
std::string_view token, std::string_view token,
std::size_t error_return) std::size_t error_return)
: key_(utils::encryption::generate_key(token)), : key_(utils::encryption::generate_key<utils::encryption::hash_256_t>(
token)),
stop_requested_(stop_requested), stop_requested_(stop_requested),
error_return_(error_return) { error_return_(error_return) {
const auto res = native_file::create_or_open(source_path, true, source_file_); const auto res = native_file::create_or_open(source_path, true, source_file_);
@ -261,7 +263,8 @@ encrypting_reader::encrypting_reader(
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>> std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
iv_list, iv_list,
std::size_t error_return) std::size_t error_return)
: key_(utils::encryption::generate_key(token)), : key_(utils::encryption::generate_key<utils::encryption::hash_256_t>(
token)),
stop_requested_(stop_requested), stop_requested_(stop_requested),
error_return_(error_return) { error_return_(error_return) {
const auto res = native_file::create_or_open(source_path, true, source_file_); const auto res = native_file::create_or_open(source_path, true, source_file_);