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

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