Skip to content
Snippets Groups Projects
Commit 9bea814e authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

[dnssec] keystore: internal context initialization via pointer

Some providers may not need the context.
parent a417f88f
No related branches found
No related tags found
1 merge request!332libdnssec
......@@ -8,7 +8,7 @@
typedef struct keystore_functions {
// construction of internal context
void *(*ctx_new)(void *custom_data);
int (*ctx_new)(void **ctx_ptr, void *custom_data);
void (*ctx_free)(void *ctx);
// keystore open/close
int (*open)(void *ctx, const char *config);
......
......@@ -23,13 +23,13 @@ int keystore_create(dnssec_keystore_t **store_ptr,
store->functions = functions;
store->ctx = functions->ctx_new(ctx_custom_data);
if (!store->ctx) {
int result = functions->ctx_new(&store->ctx, ctx_custom_data);
if (result != DNSSEC_EOK) {
free(store);
return DNSSEC_ENOMEM;
}
int result = functions->open(store->ctx, open_config);
result = functions->open(store->ctx, open_config);
if (result != DNSSEC_EOK) {
dnssec_keystore_close(store);
return result;
......
......@@ -14,9 +14,15 @@ typedef struct pkcs11_ctx {
/* -- internal API --------------------------------------------------------- */
static void *pkcs11_ctx_new(_unused_ void *data)
static int pkcs11_ctx_new(void **ctx_ptr, _unused_ void *data)
{
return calloc(1, sizeof(pkcs11_ctx_t));
pkcs11_ctx_t *ctx = calloc(1, sizeof(*ctx));
if (!ctx) {
return DNSSEC_ENOMEM;
}
*ctx_ptr = ctx;
return DNSSEC_EOK;
}
static void pkcs11_ctx_free(void *ctx)
......
......@@ -20,19 +20,21 @@ typedef struct pkcs8_ctx {
/* -- internal API --------------------------------------------------------- */
static void *pkcs8_ctx_new(void *data)
static int pkcs8_ctx_new(void **ctx_ptr, void *data)
{
assert(ctx_ptr);
assert(data);
pkcs8_ctx_t *ctx = calloc(1, sizeof(*ctx));
if (!ctx) {
return NULL;
return DNSSEC_ENOMEM;
}
dnssec_keystore_pkcs8_functions_t *functions = data;
ctx->functions = functions;
return ctx;
*ctx_ptr = ctx;
return DNSSEC_EOK;
}
static void pkcs8_ctx_free(void *ctx)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment