updated build system

This commit is contained in:
Scott E. Graves 2024-08-02 12:01:25 -05:00
parent 7c538b471d
commit fb26aa04b6
5 changed files with 12 additions and 21 deletions

View File

@ -111,10 +111,6 @@ public:
return error_return_; return error_return_;
} }
[[nodiscard]] static constexpr auto get_header_size() -> std::size_t {
return header_size_;
}
[[nodiscard]] auto get_iv_list() [[nodiscard]] auto get_iv_list()
-> std::vector<std::array<unsigned char, -> std::vector<std::array<unsigned char,
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>> { crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>> {

View File

@ -73,8 +73,6 @@ auto read_encrypted_range(const http_range &range, const key_type &key,
utils::encryption::encrypting_reader::get_encrypted_chunk_size(); utils::encryption::encrypting_reader::get_encrypted_chunk_size();
const auto data_chunk_size = const auto data_chunk_size =
utils::encryption::encrypting_reader::get_data_chunk_size(); utils::encryption::encrypting_reader::get_data_chunk_size();
const auto header_size =
utils::encryption::encrypting_reader::get_header_size();
const auto start_chunk = const auto start_chunk =
static_cast<std::size_t>(range.begin / data_chunk_size); static_cast<std::size_t>(range.begin / data_chunk_size);
@ -86,8 +84,8 @@ auto read_encrypted_range(const http_range &range, const key_type &key,
data_buffer cypher; data_buffer cypher;
const auto start_offset = chunk * encrypted_chunk_size; const auto start_offset = chunk * encrypted_chunk_size;
const auto end_offset = std::min( const auto end_offset = std::min(
start_offset + (total_size - (chunk * data_chunk_size)) + header_size - start_offset + (total_size - (chunk * data_chunk_size)) +
1U, encryption_header_size - 1U,
static_cast<std::uint64_t>(start_offset + encrypted_chunk_size - 1U)); static_cast<std::uint64_t>(start_offset + encrypted_chunk_size - 1U));
const auto result = reader(cypher, start_offset, end_offset); const auto result = reader(cypher, start_offset, end_offset);

View File

@ -203,8 +203,7 @@ encrypting_reader::encrypting_reader(
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(
file_size, static_cast<std::uint64_t>(data_chunk_size_)); file_size, static_cast<std::uint64_t>(data_chunk_size_));
total_size_ = total_size_ = file_size + (total_chunks * encryption_header_size);
file_size + (total_chunks * encrypting_reader::get_header_size());
last_data_chunk_ = total_chunks - 1U; last_data_chunk_ = total_chunks - 1U;
last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size
: (file_size % data_chunk_size_) == 0U : (file_size % data_chunk_size_) == 0U
@ -244,8 +243,7 @@ encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(
file_size, static_cast<std::uint64_t>(data_chunk_size_)); file_size, static_cast<std::uint64_t>(data_chunk_size_));
total_size_ = total_size_ = file_size + (total_chunks * encryption_header_size);
file_size + (total_chunks * encrypting_reader::get_header_size());
last_data_chunk_ = total_chunks - 1U; last_data_chunk_ = total_chunks - 1U;
last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size
: (file_size % data_chunk_size_) == 0U : (file_size % data_chunk_size_) == 0U
@ -287,8 +285,7 @@ encrypting_reader::encrypting_reader(
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(
file_size, static_cast<std::uint64_t>(data_chunk_size_)); file_size, static_cast<std::uint64_t>(data_chunk_size_));
total_size_ = total_size_ = file_size + (total_chunks * encryption_header_size);
file_size + (total_chunks * encrypting_reader::get_header_size());
last_data_chunk_ = total_chunks - 1U; last_data_chunk_ = total_chunks - 1U;
last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size
: (file_size % data_chunk_size_) == 0U : (file_size % data_chunk_size_) == 0U
@ -322,7 +319,7 @@ auto encrypting_reader::calculate_decrypted_size(std::uint64_t total_size)
return total_size - (utils::divide_with_ceiling( return total_size - (utils::divide_with_ceiling(
total_size, static_cast<std::uint64_t>( total_size, static_cast<std::uint64_t>(
get_encrypted_chunk_size())) * get_encrypted_chunk_size())) *
get_header_size()); encryption_header_size);
} }
auto encrypting_reader::calculate_encrypted_size(std::string_view source_path) auto encrypting_reader::calculate_encrypted_size(std::string_view source_path)
@ -336,7 +333,7 @@ auto encrypting_reader::calculate_encrypted_size(std::string_view source_path)
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(
file_size, static_cast<std::uint64_t>(data_chunk_size_)); file_size, static_cast<std::uint64_t>(data_chunk_size_));
return file_size + (total_chunks * encrypting_reader::get_header_size()); return file_size + (total_chunks * encryption_header_size);
} }
auto encrypting_reader::create_iostream() const auto encrypting_reader::create_iostream() const
@ -367,7 +364,7 @@ auto encrypting_reader::reader_function(char *buffer, size_t size,
data_buffer file_data(chunk == last_data_chunk_ data_buffer file_data(chunk == last_data_chunk_
? last_data_chunk_size_ ? last_data_chunk_size_
: data_chunk_size_); : data_chunk_size_);
chunk_buffer.resize(file_data.size() + get_header_size()); chunk_buffer.resize(file_data.size() + encryption_header_size);
std::size_t bytes_read{}; std::size_t bytes_read{};
if ((ret = source_file_->read_bytes(&file_data[0u], file_data.size(), if ((ret = source_file_->read_bytes(&file_data[0u], file_data.size(),

View File

@ -32,8 +32,7 @@ static const std::string buffer = "cow moose dog chicken";
static const std::string token = "moose"; static const std::string token = "moose";
static void test_encrypted_result(const data_buffer &result) { static void test_encrypted_result(const data_buffer &result) {
EXPECT_EQ(buffer.size() + EXPECT_EQ(buffer.size() + utils::encryption::encryption_header_size,
utils::encryption::encrypting_reader::get_header_size(),
result.size()); result.size());
std::string data; std::string data;
EXPECT_TRUE(utils::encryption::decrypt_data(token, result, data)); EXPECT_TRUE(utils::encryption::decrypt_data(token, result, data));

View File

@ -271,8 +271,9 @@ auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
auto json_text = stream.str(); auto json_text = stream.str();
#if defined(PROJECT_ENABLE_LIBSODIUM) #if defined(PROJECT_ENABLE_LIBSODIUM)
if (password.has_value()) { if (password.has_value()) {
auto data = utils::encryption::decrypt_data(json_text, *password); auto decrypted_data =
json_text = {data.begin(), data.end()}; utils::encryption::decrypt_data(json_text, *password);
json_text = {decrypted_data.begin(), decrypted_data.end()};
} }
#endif // defined(PROJECT_ENABLE_LIBSODIUM) #endif // defined(PROJECT_ENABLE_LIBSODIUM)
if (not json_text.empty()) { if (not json_text.empty()) {