diff --git a/src/Makefile.am b/src/Makefile.am index 14440d92..a5db81df 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,6 @@ noinst_HEADERS = \ signature.h \ slot.h \ store.h \ - store_internals.h \ util.h pkcs11_LTLIBRARIES = pkcs11.la diff --git a/src/decoder.c b/src/decoder.c index 79c8a37d..01c1f13e 100644 --- a/src/decoder.c +++ b/src/decoder.c @@ -4,7 +4,8 @@ #include "provider.h" #include "decoder.h" -#include "store_internals.h" +#include "store.h" +#include "util.h" #include "pk11_uri.h" #include #include @@ -57,12 +58,7 @@ static char *obj_uri_get1(P11PROV_PK11_URI *obj) P11PROV_debug("Failed to get URI"); return NULL; } - char *null_terminated_uri = OPENSSL_zalloc(uri_len + 1); - if (!null_terminated_uri) { - return NULL; - } - memcpy(null_terminated_uri, uri, uri_len); - return null_terminated_uri; + return p11prov_alloc_sprintf(uri_len, "%s", uri); } struct desired_data_type_cbdata { @@ -129,7 +125,7 @@ static int p11prov_der_decoder_p11prov_obj_decode( struct desired_data_type_cbdata cbdata = { desired_data_type, object_cb, object_cbarg }; - p11prov_store_quickload(ctx->provctx, uri, filter_for_desired_data_type, + p11prov_store_direct_fetch(ctx->provctx, uri, filter_for_desired_data_type, &cbdata, pw_cb, pw_cbarg); ret = RET_OSSL_STOP_DECODING; @@ -140,7 +136,7 @@ static int p11prov_der_decoder_p11prov_obj_decode( OPENSSL_free(uri); P11PROV_PK11_URI_free(obj); BIO_free(bin); - P11PROV_debug("der decoder (cary on:%d)", ret); + P11PROV_debug("der decoder (carry on:%d)", ret); return ret; } diff --git a/src/decoder.h b/src/decoder.h index ee482358..e3cd4f10 100644 --- a/src/decoder.h +++ b/src/decoder.h @@ -7,7 +7,7 @@ #include #define RET_OSSL_CARRY_ON_DECODING 1 -#define RET_OSSL_STOP_DECODING 1 +#define RET_OSSL_STOP_DECODING 0 /* DECODERs */ #define DISPATCH_TEXT_DECODER_FN(type, name) \ diff --git a/src/store.c b/src/store.c index f2122bc6..330f2fd0 100644 --- a/src/store.c +++ b/src/store.c @@ -3,7 +3,7 @@ #include "provider.h" #include -#include "store_internals.h" +#include "store.h" struct p11prov_store_ctx { P11PROV_CTX *provctx; @@ -590,24 +590,23 @@ static int p11prov_store_set_ctx_params(void *pctx, const OSSL_PARAM params[]) return RET_OSSL_OK; } -void p11prov_store_quickload(void *provctx, const char *uri, - OSSL_CALLBACK *object_cb, void *object_cbarg, - OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg) +int p11prov_store_direct_fetch(void *provctx, const char *uri, + OSSL_CALLBACK *object_cb, void *object_cbarg, + OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg) { struct p11prov_store_ctx *ctx = NULL; ctx = p11prov_store_open(provctx, uri); if (!ctx) { - goto done; + return RET_OSSL_ERR; } - while ( - RET_OSSL_OK - == p11prov_store_load(ctx, object_cb, object_cbarg, pw_cb, pw_cbarg)) { - ; + int ret = RET_OSSL_OK; + while (ret == RET_OSSL_OK) { + ret = p11prov_store_load(ctx, object_cb, object_cbarg, pw_cb, pw_cbarg); } -done: p11prov_store_ctx_free(ctx); + return RET_OSSL_OK; } const OSSL_DISPATCH p11prov_store_functions[] = { diff --git a/src/store.h b/src/store.h index 84708a0f..4cce30cf 100644 --- a/src/store.h +++ b/src/store.h @@ -4,6 +4,8 @@ #ifndef _STORE_H #define _STORE_H +#include + #define DISPATCH_STORE_FN(name) DECL_DISPATCH_FUNC(store, p11prov_store, name) #define DISPATCH_STORE_ELEM(NAME, name) \ { \ @@ -11,4 +13,8 @@ } extern const OSSL_DISPATCH p11prov_store_functions[]; +int p11prov_store_direct_fetch(void *provctx, const char *uri, + OSSL_CALLBACK *object_cb, void *object_cbarg, + OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg); + #endif /* _STORE_H */ diff --git a/src/store_internals.h b/src/store_internals.h deleted file mode 100644 index 9782d195..00000000 --- a/src/store_internals.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (C) 2022 Simo Sorce - SPDX-License-Identifier: Apache-2.0 */ - -#ifndef _STORE_INTERNALS_H -#define _STORE_INTERNALS_H - -#include - -void p11prov_store_quickload(void *provctx, const char *uri, - OSSL_CALLBACK *object_cb, void *object_cbarg, - OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg); - -#endif /* _STORE_INTERNALS_H */