diff --git a/repertory/librepertory/include/utils/encrypting_reader.hpp b/repertory/librepertory/include/utils/encrypting_reader.hpp index 68c97581..e896bf86 100644 --- a/repertory/librepertory/include/utils/encrypting_reader.hpp +++ b/repertory/librepertory/include/utils/encrypting_reader.hpp @@ -111,10 +111,6 @@ public: return error_return_; } - [[nodiscard]] static constexpr auto get_header_size() -> std::size_t { - return header_size_; - } - [[nodiscard]] auto get_iv_list() -> std::vector> { diff --git a/repertory/librepertory/src/utils/encrypt.cpp b/repertory/librepertory/src/utils/encrypt.cpp index ecfa2b5b..f7092b20 100644 --- a/repertory/librepertory/src/utils/encrypt.cpp +++ b/repertory/librepertory/src/utils/encrypt.cpp @@ -73,8 +73,6 @@ auto read_encrypted_range(const http_range &range, const key_type &key, utils::encryption::encrypting_reader::get_encrypted_chunk_size(); const auto 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 = static_cast(range.begin / data_chunk_size); @@ -86,8 +84,8 @@ auto read_encrypted_range(const http_range &range, const key_type &key, data_buffer cypher; const auto start_offset = chunk * encrypted_chunk_size; const auto end_offset = std::min( - start_offset + (total_size - (chunk * data_chunk_size)) + header_size - - 1U, + start_offset + (total_size - (chunk * data_chunk_size)) + + encryption_header_size - 1U, static_cast(start_offset + encrypted_chunk_size - 1U)); const auto result = reader(cypher, start_offset, end_offset); diff --git a/repertory/librepertory/src/utils/encrypting_reader.cpp b/repertory/librepertory/src/utils/encrypting_reader.cpp index 8af0cf8f..8dd552ee 100644 --- a/repertory/librepertory/src/utils/encrypting_reader.cpp +++ b/repertory/librepertory/src/utils/encrypting_reader.cpp @@ -203,8 +203,7 @@ encrypting_reader::encrypting_reader( const auto total_chunks = utils::divide_with_ceiling( file_size, static_cast(data_chunk_size_)); - total_size_ = - file_size + (total_chunks * encrypting_reader::get_header_size()); + total_size_ = file_size + (total_chunks * encryption_header_size); last_data_chunk_ = total_chunks - 1U; last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size : (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( file_size, static_cast(data_chunk_size_)); - total_size_ = - file_size + (total_chunks * encrypting_reader::get_header_size()); + total_size_ = file_size + (total_chunks * encryption_header_size); last_data_chunk_ = total_chunks - 1U; last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size : (file_size % data_chunk_size_) == 0U @@ -287,8 +285,7 @@ encrypting_reader::encrypting_reader( const auto total_chunks = utils::divide_with_ceiling( file_size, static_cast(data_chunk_size_)); - total_size_ = - file_size + (total_chunks * encrypting_reader::get_header_size()); + total_size_ = file_size + (total_chunks * encryption_header_size); last_data_chunk_ = total_chunks - 1U; last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size : (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( total_size, static_cast( get_encrypted_chunk_size())) * - get_header_size()); + encryption_header_size); } 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( file_size, static_cast(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 @@ -367,7 +364,7 @@ auto encrypting_reader::reader_function(char *buffer, size_t size, data_buffer file_data(chunk == last_data_chunk_ ? last_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{}; if ((ret = source_file_->read_bytes(&file_data[0u], file_data.size(), diff --git a/repertory/repertory_test/src/encryption_test.cpp b/repertory/repertory_test/src/encryption_test.cpp index 503e8edd..f6a39c7c 100644 --- a/repertory/repertory_test/src/encryption_test.cpp +++ b/repertory/repertory_test/src/encryption_test.cpp @@ -32,8 +32,7 @@ static const std::string buffer = "cow moose dog chicken"; static const std::string token = "moose"; static void test_encrypted_result(const data_buffer &result) { - EXPECT_EQ(buffer.size() + - utils::encryption::encrypting_reader::get_header_size(), + EXPECT_EQ(buffer.size() + utils::encryption::encryption_header_size, result.size()); std::string data; EXPECT_TRUE(utils::encryption::decrypt_data(token, result, data)); diff --git a/support/3rd_party/src/utils/file.cpp b/support/3rd_party/src/utils/file.cpp index 5207fe6d..715b17cc 100644 --- a/support/3rd_party/src/utils/file.cpp +++ b/support/3rd_party/src/utils/file.cpp @@ -271,8 +271,9 @@ auto read_json_file(std::string_view path, nlohmann::json &data) -> bool { auto json_text = stream.str(); #if defined(PROJECT_ENABLE_LIBSODIUM) if (password.has_value()) { - auto data = utils::encryption::decrypt_data(json_text, *password); - json_text = {data.begin(), data.end()}; + auto decrypted_data = + utils::encryption::decrypt_data(json_text, *password); + json_text = {decrypted_data.begin(), decrypted_data.end()}; } #endif // defined(PROJECT_ENABLE_LIBSODIUM) if (not json_text.empty()) {