63 lines
2 KiB
C
63 lines
2 KiB
C
#include "amduat/asl/store.h"
|
|
|
|
static amduat_asl_store_error_t amduat_asl_store_validate_config(
|
|
amduat_asl_store_t *store) {
|
|
if (store == NULL || store->ops.validate_config == NULL) {
|
|
return AMDUAT_ASL_STORE_OK;
|
|
}
|
|
return store->ops.validate_config(store->ctx, store->config);
|
|
}
|
|
|
|
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) {
|
|
amduat_asl_store_error_t cfg_err;
|
|
amduat_asl_store_error_t store_err;
|
|
|
|
if (store == NULL || store->ops.put == NULL) {
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
}
|
|
cfg_err = amduat_asl_store_validate_config(store);
|
|
if (cfg_err != AMDUAT_ASL_STORE_OK) {
|
|
return cfg_err;
|
|
}
|
|
store_err = store->ops.put(store->ctx, artifact, out_ref);
|
|
if (store_err != AMDUAT_ASL_STORE_OK) {
|
|
return store_err;
|
|
}
|
|
if (out_ref != NULL && out_ref->hash_id != store->config.hash_id) {
|
|
return AMDUAT_ASL_STORE_ERR_INTEGRITY;
|
|
}
|
|
return AMDUAT_ASL_STORE_OK;
|
|
}
|
|
|
|
amduat_asl_store_error_t amduat_asl_store_get(amduat_asl_store_t *store,
|
|
amduat_reference_t ref,
|
|
amduat_artifact_t *out_artifact) {
|
|
amduat_asl_store_error_t cfg_err;
|
|
|
|
if (store == NULL || store->ops.get == NULL) {
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
}
|
|
if (ref.hash_id != store->config.hash_id) {
|
|
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
|
|
}
|
|
cfg_err = amduat_asl_store_validate_config(store);
|
|
if (cfg_err != AMDUAT_ASL_STORE_OK) {
|
|
return cfg_err;
|
|
}
|
|
return store->ops.get(store->ctx, ref, out_artifact);
|
|
}
|