#include "amduat/asl/store.h" #include #include static amduat_asl_store_error_t stub_put(void *ctx, amduat_artifact_t artifact, amduat_reference_t *out_ref) { amduat_hash_id_t *hash_id = (amduat_hash_id_t *)ctx; if (out_ref != NULL) { uint8_t digest = 0xaa; *out_ref = amduat_reference(*hash_id, amduat_octets(&digest, sizeof(digest))); } (void)artifact; return AMDUAT_ASL_STORE_OK; } static amduat_asl_store_error_t stub_get_not_found(void *ctx, amduat_reference_t ref, amduat_artifact_t *out_artifact) { (void)ctx; (void)ref; (void)out_artifact; return AMDUAT_ASL_STORE_ERR_NOT_FOUND; } static amduat_asl_store_error_t stub_get_io(void *ctx, amduat_reference_t ref, amduat_artifact_t *out_artifact) { (void)ctx; (void)ref; (void)out_artifact; return AMDUAT_ASL_STORE_ERR_IO; } static int test_not_found_mapping(void) { amduat_asl_store_ops_t ops; amduat_asl_store_t store; amduat_asl_store_config_t cfg = {0}; amduat_reference_t ref; amduat_artifact_t artifact; amduat_asl_store_error_t err; amduat_asl_store_ops_init(&ops); ops.get = stub_get_not_found; cfg.hash_id = 0x0001u; amduat_asl_store_init(&store, cfg, ops, NULL); ref = amduat_reference(cfg.hash_id, amduat_octets(NULL, 0u)); memset(&artifact, 0, sizeof(artifact)); err = amduat_asl_store_get(&store, ref, &artifact); return err == AMDUAT_ASL_STORE_ERR_NOT_FOUND ? 0 : 1; } static int test_io_mapping(void) { amduat_asl_store_ops_t ops; amduat_asl_store_t store; amduat_asl_store_config_t cfg = {0}; amduat_reference_t ref; amduat_artifact_t artifact; amduat_asl_store_error_t err; amduat_asl_store_ops_init(&ops); ops.get = stub_get_io; cfg.hash_id = 0x0001u; amduat_asl_store_init(&store, cfg, ops, NULL); ref = amduat_reference(cfg.hash_id, amduat_octets(NULL, 0u)); memset(&artifact, 0, sizeof(artifact)); err = amduat_asl_store_get(&store, ref, &artifact); return err == AMDUAT_ASL_STORE_ERR_IO ? 0 : 1; } static int test_integrity_mapping(void) { amduat_asl_store_ops_t ops; amduat_asl_store_t store; amduat_asl_store_config_t cfg = {0}; amduat_artifact_t artifact; amduat_reference_t ref; amduat_hash_id_t wrong_hash = 0x00ffu; amduat_asl_store_error_t err; amduat_asl_store_ops_init(&ops); ops.put = stub_put; cfg.hash_id = 0x0001u; amduat_asl_store_init(&store, cfg, ops, &wrong_hash); memset(&artifact, 0, sizeof(artifact)); err = amduat_asl_store_put(&store, artifact, &ref); if (err != AMDUAT_ASL_STORE_ERR_INTEGRITY) { return 1; } amduat_reference_free(&ref); return 0; } static int test_unsupported_mapping(void) { amduat_asl_store_ops_t ops; amduat_asl_store_t store; amduat_asl_store_config_t cfg = {0}; amduat_reference_t ref; amduat_artifact_t artifact; amduat_asl_store_error_t err; amduat_asl_store_ops_init(&ops); cfg.hash_id = 0x0001u; amduat_asl_store_init(&store, cfg, ops, NULL); ref = amduat_reference(cfg.hash_id, amduat_octets(NULL, 0u)); memset(&artifact, 0, sizeof(artifact)); err = amduat_asl_store_get(&store, ref, &artifact); if (err != AMDUAT_ASL_STORE_ERR_UNSUPPORTED) { return 1; } err = amduat_asl_store_put(&store, artifact, &ref); return err == AMDUAT_ASL_STORE_ERR_UNSUPPORTED ? 0 : 1; } int main(void) { if (test_not_found_mapping() != 0) { fprintf(stderr, "not_found mapping failed\n"); return 1; } if (test_io_mapping() != 0) { fprintf(stderr, "io mapping failed\n"); return 1; } if (test_integrity_mapping() != 0) { fprintf(stderr, "integrity mapping failed\n"); return 1; } if (test_unsupported_mapping() != 0) { fprintf(stderr, "unsupported mapping failed\n"); return 1; } return 0; }