refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-09-01 10:24:32 -05:00
parent 9656828700
commit b143962dac
3 changed files with 20 additions and 23 deletions

View File

@@ -30,7 +30,7 @@
#include "providers/s3/s3_provider.hpp" #include "providers/s3/s3_provider.hpp"
#include "providers/sia/sia_provider.hpp" #include "providers/sia/sia_provider.hpp"
#include "utils/collection.hpp" #include "utils/collection.hpp"
#include "utils/file_utils.hpp" #include "utils/file.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "utils/time.hpp" #include "utils/time.hpp"

View File

@@ -133,19 +133,7 @@ struct kdf_config final {
[[nodiscard]] auto create_subkey(kdf_context ctx, std::size_t unique_id_, [[nodiscard]] auto create_subkey(kdf_context ctx, std::size_t unique_id_,
const hash_t &master_key) const const hash_t &master_key) const
-> std::pair<hash_t, kdf_config> { -> std::pair<hash_t, kdf_config> {
REPERTORY_USES_FUNCTION_NAME(); auto sub_key = derive_subkey<hash_t>(ctx, unique_id_, master_key);
hash_t sub_key;
auto res = crypto_kdf_derive_from_key(
sub_key.data(), sub_key.size(), unique_id_,
get_kdf_context_name(ctx).data(), master_key.data());
if (res != 0) {
throw repertory::utils::error::create_exception(
function_name, {
"failed to create sub-key",
std::to_string(res),
});
}
auto cfg = *this; auto cfg = *this;
cfg.unique_id = unique_id_; cfg.unique_id = unique_id_;
@@ -154,18 +142,19 @@ struct kdf_config final {
} }
template <typename hash_t> template <typename hash_t>
[[nodiscard]] auto recreate_subkey(kdf_context ctx, [[nodiscard]] static auto derive_subkey(kdf_context ctx,
const hash_t &master_key) const -> hash_t { std::size_t unique_id_,
const hash_t &master_key) -> hash_t {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
hash_t sub_key; hash_t sub_key{};
auto res = crypto_kdf_derive_from_key( auto res = crypto_kdf_derive_from_key(
sub_key.data(), sub_key.size(), unique_id, sub_key.data(), sub_key.size(), unique_id_,
get_kdf_context_name(ctx).data(), master_key.data()); get_kdf_context_name(ctx).data(), master_key.data());
if (res != 0) { if (res != 0) {
throw repertory::utils::error::create_exception( throw repertory::utils::error::create_exception(
function_name, { function_name, {
"failed to recreate sub-key", "failed to derive sub-key",
std::to_string(res), std::to_string(res),
}); });
} }
@@ -173,6 +162,12 @@ struct kdf_config final {
return sub_key; return sub_key;
} }
template <typename hash_t>
[[nodiscard]] auto recreate_subkey(kdf_context ctx,
const hash_t &master_key) const -> hash_t {
return derive_subkey<hash_t>(ctx, unique_id, master_key);
}
[[nodiscard]] static auto from_header(data_cspan data, kdf_config &cfg, [[nodiscard]] static auto from_header(data_cspan data, kdf_config &cfg,
bool ignore_checksum = false) -> bool; bool ignore_checksum = false) -> bool;

View File

@@ -299,10 +299,12 @@ encrypting_reader::encrypting_reader(
: stop_requested_cb_(std::move(stop_requested_cb)), : stop_requested_cb_(std::move(stop_requested_cb)),
error_return_(error_return), error_return_(error_return),
source_file_(utils::file::file::open_or_create_file(source_path, true)) { source_file_(utils::file::file::open_or_create_file(source_path, true)) {
keys_.first = configs.first.recreate_subkey( keys_ = {
utils::encryption::kdf_context::data, master_key); configs.first.recreate_subkey(utils::encryption::kdf_context::data,
keys_.second = configs.second.recreate_subkey( master_key),
utils::encryption::kdf_context::path, master_key); configs.second.recreate_subkey(utils::encryption::kdf_context::path,
master_key),
};
kdf_headers_ = { kdf_headers_ = {
configs.first.to_header(), configs.first.to_header(),
configs.second.to_header(), configs.second.to_header(),