2025-12-19 19:22:40 +01:00
|
|
|
#include "amduat/asl/store.h"
|
2025-12-21 23:09:44 +01:00
|
|
|
#include "amduat/enc/asl1_core.h"
|
|
|
|
|
#include "amduat/hash/asl1.h"
|
|
|
|
|
|
|
|
|
|
static bool amduat_asl_store_config_supported(
|
|
|
|
|
const amduat_asl_store_config_t *config) {
|
|
|
|
|
const amduat_hash_asl1_desc_t *hash_desc;
|
|
|
|
|
|
|
|
|
|
if (config == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (amduat_enc_asl1_core_desc_lookup(config->encoding_profile_id) == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
hash_desc = amduat_hash_asl1_desc_lookup(config->hash_id);
|
|
|
|
|
if (hash_desc == NULL || hash_desc->digest_len == 0 ||
|
|
|
|
|
hash_desc->impl.digest == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-12-19 19:22:40 +01:00
|
|
|
|
|
|
|
|
void amduat_asl_store_init(amduat_asl_store_t *store,
|
|
|
|
|
amduat_asl_store_config_t config,
|
|
|
|
|
amduat_asl_store_ops_t ops,
|
|
|
|
|
void *ctx) {
|
|
|
|
|
if (store == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
store->config = config;
|
|
|
|
|
store->ops = ops;
|
|
|
|
|
store->ctx = ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
amduat_asl_store_error_t amduat_asl_store_put(amduat_asl_store_t *store,
|
|
|
|
|
amduat_artifact_t artifact,
|
|
|
|
|
amduat_reference_t *out_ref) {
|
|
|
|
|
if (store == NULL || store->ops.put == NULL) {
|
|
|
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
|
|
|
}
|
2025-12-21 23:09:44 +01:00
|
|
|
if (!amduat_asl_store_config_supported(&store->config)) {
|
|
|
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
|
|
|
}
|
2025-12-19 19:22:40 +01:00
|
|
|
return store->ops.put(store->ctx, artifact, out_ref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
amduat_asl_store_error_t amduat_asl_store_get(amduat_asl_store_t *store,
|
|
|
|
|
amduat_reference_t ref,
|
|
|
|
|
amduat_artifact_t *out_artifact) {
|
|
|
|
|
if (store == NULL || store->ops.get == NULL) {
|
|
|
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
|
|
|
}
|
2025-12-21 23:09:44 +01:00
|
|
|
if (!amduat_asl_store_config_supported(&store->config)) {
|
|
|
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
if (ref.hash_id != store->config.hash_id) {
|
|
|
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
|
|
|
}
|
2025-12-19 19:22:40 +01:00
|
|
|
return store->ops.get(store->ctx, ref, out_artifact);
|
|
|
|
|
}
|