Skip to content

Commit

Permalink
fixup! de-duplicate store code in decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Wernli committed Feb 16, 2024
1 parent 6d40008 commit 7e92949
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ noinst_HEADERS = \
signature.h \
slot.h \
store.h \
store_internals.h \
util.h
pkcs11_LTLIBRARIES = pkcs11.la

Expand Down
14 changes: 5 additions & 9 deletions src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <openssl/asn1t.h>
#include <openssl/bio.h>
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <openssl/core.h>

#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) \
Expand Down
19 changes: 9 additions & 10 deletions src/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "provider.h"
#include <openssl/store.h>
#include "store_internals.h"
#include "store.h"

struct p11prov_store_ctx {
P11PROV_CTX *provctx;
Expand Down Expand Up @@ -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[] = {
Expand Down
6 changes: 6 additions & 0 deletions src/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
#ifndef _STORE_H
#define _STORE_H

#include <openssl/core.h>

#define DISPATCH_STORE_FN(name) DECL_DISPATCH_FUNC(store, p11prov_store, name)
#define DISPATCH_STORE_ELEM(NAME, name) \
{ \
OSSL_FUNC_STORE_##NAME, (void (*)(void))p11prov_store_##name \
}
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 */
13 changes: 0 additions & 13 deletions src/store_internals.h

This file was deleted.

0 comments on commit 7e92949

Please sign in to comment.