138 lines
4.8 KiB
C
138 lines
4.8 KiB
C
#ifndef AMDUAT_BYTESTORE_H
|
|
#define AMDUAT_BYTESTORE_H
|
|
|
|
#include "amduat/asl/core.h"
|
|
#include "amduat/hash/asl1.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum {
|
|
AMDUAT_BYTESTORE_OK = 0,
|
|
AMDUAT_BYTESTORE_ERR_POLICY_SIZE = 1,
|
|
AMDUAT_BYTESTORE_ERR_IDENTITY_MISMATCH = 2,
|
|
AMDUAT_BYTESTORE_ERR_STREAM_ORDER = 3,
|
|
AMDUAT_BYTESTORE_ERR_STREAM_TRUNCATED = 4,
|
|
AMDUAT_BYTESTORE_ERR_AREA_VIOLATION = 5,
|
|
AMDUAT_BYTESTORE_ERR_CRASH_SIMULATION = 6,
|
|
AMDUAT_BYTESTORE_ERR_STORE_MISSING = 7,
|
|
AMDUAT_BYTESTORE_ERR_UNSUPPORTED = 8,
|
|
AMDUAT_BYTESTORE_ERR_IO = 9,
|
|
AMDUAT_BYTESTORE_ERR_INVALID = 10
|
|
} amduat_bytestore_error_t;
|
|
|
|
typedef struct {
|
|
amduat_hash_id_t hash_id;
|
|
size_t max_object_size;
|
|
const char *public_root;
|
|
const char *secure_root;
|
|
} amduat_bytestore_config_t;
|
|
|
|
typedef struct {
|
|
bool present;
|
|
size_t size;
|
|
} amduat_bytestore_stat_t;
|
|
|
|
typedef struct {
|
|
/* Return 1 for a chunk, 0 for end-of-stream, -1 on error. */
|
|
int (*next)(void *ctx, amduat_octets_t *out_chunk);
|
|
void *ctx;
|
|
} amduat_bytestore_stream_t;
|
|
|
|
typedef struct {
|
|
amduat_bytestore_error_t (*put)(void *ctx,
|
|
amduat_octets_t payload,
|
|
amduat_reference_t *out_cid);
|
|
amduat_bytestore_error_t (*put_stream)(void *ctx,
|
|
amduat_bytestore_stream_t stream,
|
|
amduat_reference_t *out_cid);
|
|
amduat_bytestore_error_t (*import_cor)(void *ctx,
|
|
amduat_octets_t envelope,
|
|
amduat_reference_t *out_cid);
|
|
amduat_bytestore_error_t (*export_cor)(void *ctx,
|
|
amduat_reference_t cid,
|
|
amduat_octets_t *out_envelope);
|
|
amduat_bytestore_error_t (*get)(void *ctx,
|
|
amduat_reference_t cid,
|
|
amduat_octets_t *out_bytes);
|
|
amduat_bytestore_error_t (*stat)(void *ctx,
|
|
amduat_reference_t cid,
|
|
amduat_bytestore_stat_t *out_stat);
|
|
amduat_bytestore_error_t (*assert_area_isolation)(void *ctx,
|
|
const char *public_root,
|
|
const char *secure_root);
|
|
amduat_bytestore_error_t (*validate_config)(void *ctx,
|
|
amduat_bytestore_config_t config);
|
|
} amduat_bytestore_ops_t;
|
|
|
|
static inline void amduat_bytestore_ops_init(amduat_bytestore_ops_t *ops) {
|
|
if (ops == NULL) {
|
|
return;
|
|
}
|
|
ops->put = NULL;
|
|
ops->put_stream = NULL;
|
|
ops->import_cor = NULL;
|
|
ops->export_cor = NULL;
|
|
ops->get = NULL;
|
|
ops->stat = NULL;
|
|
ops->assert_area_isolation = NULL;
|
|
ops->validate_config = NULL;
|
|
}
|
|
|
|
typedef struct {
|
|
amduat_bytestore_config_t config;
|
|
amduat_bytestore_ops_t ops;
|
|
void *ctx;
|
|
} amduat_bytestore_t;
|
|
|
|
void amduat_bytestore_init(amduat_bytestore_t *store,
|
|
amduat_bytestore_config_t config,
|
|
amduat_bytestore_ops_t ops,
|
|
void *ctx);
|
|
|
|
amduat_bytestore_error_t amduat_bytestore_put(amduat_bytestore_t *store,
|
|
amduat_octets_t payload,
|
|
amduat_reference_t *out_cid);
|
|
amduat_bytestore_error_t amduat_bytestore_put_stream(
|
|
amduat_bytestore_t *store,
|
|
amduat_bytestore_stream_t stream,
|
|
amduat_reference_t *out_cid);
|
|
amduat_bytestore_error_t amduat_bytestore_import_cor(
|
|
amduat_bytestore_t *store,
|
|
amduat_octets_t envelope,
|
|
amduat_reference_t *out_cid);
|
|
amduat_bytestore_error_t amduat_bytestore_export_cor(
|
|
amduat_bytestore_t *store,
|
|
amduat_reference_t cid,
|
|
amduat_octets_t *out_envelope);
|
|
amduat_bytestore_error_t amduat_bytestore_get(amduat_bytestore_t *store,
|
|
amduat_reference_t cid,
|
|
amduat_octets_t *out_bytes);
|
|
amduat_bytestore_error_t amduat_bytestore_stat(
|
|
amduat_bytestore_t *store,
|
|
amduat_reference_t cid,
|
|
amduat_bytestore_stat_t *out_stat);
|
|
amduat_bytestore_error_t amduat_bytestore_assert_area_isolation(
|
|
amduat_bytestore_t *store,
|
|
const char *public_root,
|
|
const char *secure_root);
|
|
|
|
bool amduat_bytestore_cid_for_payload(amduat_hash_id_t hash_id,
|
|
amduat_octets_t payload,
|
|
amduat_reference_t *out_cid);
|
|
|
|
bool amduat_bytestore_cid_for_stream(amduat_hash_id_t hash_id,
|
|
amduat_bytestore_stream_t stream,
|
|
amduat_reference_t *out_cid);
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif /* AMDUAT_BYTESTORE_H */
|