updated build system
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-08-28 20:21:21 -05:00
parent 8cbaa83206
commit 69d91413fc
3 changed files with 45 additions and 53 deletions

View File

@@ -141,6 +141,8 @@ private:
void common_initialize_kdf_data(const kdf_config &cfg,
const utils::hash::hash_256_t &master_key);
void common_initialize_kdf_keys(std::string_view token, kdf_config &cfg);
void common_initialize_kdf_path(const utils::hash::hash_256_t &master_key);
void create_encrypted_paths(std::string_view file_name,

View File

@@ -230,18 +230,10 @@ encrypting_reader::encrypting_reader(
stop_type_callback stop_requested_cb, std::string_view token,
kdf_config cfg, std::optional<std::string> relative_parent_path,
std::size_t error_return)
: keys_(
utils::encryption::generate_key<utils::hash::hash_256_t>(token, cfg),
utils::encryption::generate_key<utils::hash::hash_256_t>(token)),
stop_requested_cb_(std::move(stop_requested_cb)),
: stop_requested_cb_(std::move(stop_requested_cb)),
error_return_(error_return),
source_file_(utils::file::file::open_or_create_file(source_path, true)) {
kdf_headers_ = {cfg.to_header(), cfg.to_header()};
data_buffer result;
utils::encryption::encrypt_data(
keys_.second, reinterpret_cast<const unsigned char *>(file_name.data()),
file_name.size(), result);
common_initialize_kdf_keys(token, cfg);
common_initialize(true);
create_encrypted_paths(file_name, relative_parent_path);
}
@@ -251,16 +243,13 @@ encrypting_reader::encrypting_reader(stop_type_callback stop_requested_cb,
std::string_view source_path,
std::string_view token, kdf_config cfg,
std::size_t error_return)
: keys_(
utils::encryption::generate_key<utils::hash::hash_256_t>(token, cfg),
utils::encryption::generate_key<utils::hash::hash_256_t>(token)),
stop_requested_cb_(std::move(stop_requested_cb)),
: stop_requested_cb_(std::move(stop_requested_cb)),
error_return_(error_return),
source_file_(utils::file::file::open_or_create_file(source_path, true)),
encrypted_file_name_(
utils::path::strip_to_file_name(std::string{encrypted_file_path})),
encrypted_file_path_(encrypted_file_path) {
kdf_headers_ = {cfg.to_header(), cfg.to_header()};
common_initialize_kdf_keys(token, cfg);
common_initialize(true);
}
@@ -271,17 +260,14 @@ encrypting_reader::encrypting_reader(
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
iv_list,
std::size_t error_return)
: keys_(
utils::encryption::generate_key<utils::hash::hash_256_t>(token, cfg),
utils::encryption::generate_key<utils::hash::hash_256_t>(token)),
stop_requested_cb_(std::move(stop_requested_cb)),
: stop_requested_cb_(std::move(stop_requested_cb)),
error_return_(error_return),
source_file_(utils::file::file::open_or_create_file(source_path, true)),
encrypted_file_name_(
utils::path::strip_to_file_name(std::string{encrypted_file_path})),
encrypted_file_path_(encrypted_file_path),
iv_list_(std::move(iv_list)) {
kdf_headers_ = {cfg.to_header(), cfg.to_header()};
common_initialize_kdf_keys(token, cfg);
common_initialize(false);
}
@@ -294,17 +280,6 @@ encrypting_reader::encrypting_reader(
error_return_(error_return),
source_file_(utils::file::file::open_or_create_file(source_path, true)) {
common_initialize_kdf_data(cfg, master_key);
kdf_config path_cfg;
std::tie(keys_.second, path_cfg) = cfg.create_subkey(
kdf_context::path, utils::generate_secure_random<std::uint64_t>(),
master_key);
kdf_headers_->second = path_cfg.to_header();
data_buffer result;
utils::encryption::encrypt_data(
keys_.second, reinterpret_cast<const unsigned char *>(file_name.data()),
file_name.size(), result);
common_initialize(true);
create_encrypted_paths(file_name, relative_parent_path);
}
@@ -315,8 +290,7 @@ encrypting_reader::encrypting_reader(stop_type_callback stop_requested_cb,
const utils::hash::hash_256_t &master_key,
const kdf_config &cfg,
std::size_t error_return)
: keys_(),
stop_requested_cb_(std::move(stop_requested_cb)),
: stop_requested_cb_(std::move(stop_requested_cb)),
error_return_(error_return),
source_file_(utils::file::file::open_or_create_file(source_path, true)),
encrypted_file_name_(
@@ -458,6 +432,14 @@ void encrypting_reader::common_initialize_kdf_data(
kdf_headers_ = {data_cfg.to_header(), {}};
}
void encrypting_reader::common_initialize_kdf_keys(std::string_view token,
kdf_config &cfg) {
auto key =
utils::encryption::generate_key<utils::hash::hash_256_t>(token, cfg);
keys_ = {key, key};
kdf_headers_ = {cfg.to_header(), cfg.to_header()};
}
void encrypting_reader::common_initialize_kdf_path(
const utils::hash::hash_256_t &master_key) {
REPERTORY_USES_FUNCTION_NAME();

View File

@@ -150,8 +150,9 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
ASSERT_TRUE(utils::encryption::read_encrypted_range(range, key, uses_kdf,
reader, total_size, out));
std::vector<unsigned char> want(plain.begin() + begin,
plain.begin() + end + 1U);
std::vector<unsigned char> want(
plain.begin() + static_cast<std::ptrdiff_t>(begin),
plain.begin() + static_cast<std::ptrdiff_t>(end) + 1U);
EXPECT_EQ(out, want);
}
@@ -168,8 +169,9 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
ASSERT_TRUE(utils::encryption::read_encrypted_range(range, key, uses_kdf,
reader, total_size, out));
std::vector<unsigned char> want(plain.begin() + begin,
plain.begin() + end + 1U);
std::vector<unsigned char> want(
plain.begin() + static_cast<std::ptrdiff_t>(begin),
plain.begin() + static_cast<std::ptrdiff_t>(end) + 1U);
EXPECT_EQ(out, want);
}
@@ -186,8 +188,9 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
ASSERT_TRUE(utils::encryption::read_encrypted_range(range, key, uses_kdf,
reader, total_size, out));
std::vector<unsigned char> want(plain.begin() + begin,
plain.begin() + end + 1U);
std::vector<unsigned char> want(
plain.begin() + static_cast<std::ptrdiff_t>(begin),
plain.begin() + static_cast<std::ptrdiff_t>(end) + 1U);
EXPECT_EQ(out, want);
}
@@ -203,8 +206,9 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
ASSERT_TRUE(utils::encryption::read_encrypted_range(range, key, uses_kdf,
reader, total_size, out));
std::vector<unsigned char> want(plain.begin() + begin,
plain.begin() + end + 1U);
std::vector<unsigned char> want(
plain.begin() + static_cast<std::ptrdiff_t>(begin),
plain.begin() + static_cast<std::ptrdiff_t>(end) + 1U);
EXPECT_EQ(out, want);
}
@@ -239,8 +243,9 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
bytes_read));
EXPECT_EQ(bytes_read, sink.size());
std::vector<unsigned char> want(plain.begin() + begin,
plain.begin() + end + 1U);
std::vector<unsigned char> want(
plain.begin() + static_cast<std::ptrdiff_t>(begin),
plain.begin() + static_cast<std::ptrdiff_t>(end) + 1U);
EXPECT_TRUE(std::equal(sink.begin(), sink.end(), want.begin(), want.end()));
}
@@ -338,7 +343,7 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
std::uint64_t begin = static_cast<std::uint64_t>(chunk);
std::uint64_t end = begin + 1024U - 1U;
if (end >= plain_sz)
end = (std::uint64_t)plain_sz - 1U;
end = static_cast<std::uint64_t>(plain_sz) - 1U;
ASSERT_GE(end, begin);
http_range range{begin, end};
@@ -346,8 +351,9 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
ASSERT_TRUE(utils::encryption::read_encrypted_range(range, key, uses_kdf,
reader, total_size, out));
std::vector<unsigned char> want(plain.begin() + begin,
plain.begin() + end + 1U);
std::vector<unsigned char> want(
plain.begin() + static_cast<std::ptrdiff_t>(begin),
plain.begin() + static_cast<std::ptrdiff_t>(end) + 1U);
EXPECT_EQ(out, want);
}
@@ -388,7 +394,8 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
range, key, uses_kdf, reader, total_size, sink.data(), sink.size(),
bytes_read));
EXPECT_EQ(bytes_read, sink.size());
EXPECT_TRUE(std::equal(sink.begin(), sink.end(), plain.begin() + begin));
EXPECT_TRUE(std::equal(sink.begin(), sink.end(),
plain.begin() + static_cast<std::ptrdiff_t>(begin)));
}
TEST_P(utils_encryption_read_encrypted_range_fixture,
@@ -403,8 +410,9 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
std::size_t expected_len =
static_cast<std::size_t>(static_cast<std::uint64_t>(plain_sz) - begin);
std::vector<unsigned char> want(plain.begin() + begin,
plain.begin() + plain_sz);
std::vector<unsigned char> want(
plain.begin() + static_cast<std::ptrdiff_t>(begin),
plain.begin() + static_cast<std::ptrdiff_t>(plain_sz));
ASSERT_EQ(out.size(), expected_len);
EXPECT_EQ(out, want);
@@ -414,8 +422,8 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
range, key, uses_kdf, reader, total_size, buf.data(), buf.size(),
bytes_read));
EXPECT_EQ(bytes_read, std::min<std::size_t>(buf.size(), expected_len));
EXPECT_TRUE(
std::equal(buf.begin(), buf.begin() + bytes_read, plain.begin() + begin));
EXPECT_TRUE(std::equal(buf.begin(), buf.begin() + bytes_read,
plain.begin() + static_cast<std::ptrdiff_t>(begin)));
}
TEST_P(utils_encryption_read_encrypted_range_fixture,
@@ -433,8 +441,8 @@ TEST_P(utils_encryption_read_encrypted_range_fixture,
range, key, uses_kdf, reader, total_size, buf.data(), buf.size(),
bytes_read));
EXPECT_EQ(bytes_read, 64U);
EXPECT_TRUE(
std::equal(buf.begin(), buf.begin() + 64U, plain.begin() + begin));
EXPECT_TRUE(std::equal(buf.begin(), buf.begin() + 64U,
plain.begin() + static_cast<std::ptrdiff_t>(begin)));
}
INSTANTIATE_TEST_SUITE_P(no_kdf_and_kdf,