aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2018-12-21 08:03:53 -0800
committerDoug Hogan <[email protected]>2018-12-21 08:40:53 -0800
commit2bd13b4d55664518e4b2741de813ac726fe87892 (patch)
treeeb4506976e4842d65707e9822516813ca007f282 /lib/crypto
parentc1eb6e52b503fdcb7f69052e69b392ea6df3bdab (diff)
downloadotp-2bd13b4d55664518e4b2741de813ac726fe87892.tar.gz
otp-2bd13b4d55664518e4b2741de813ac726fe87892.tar.bz2
otp-2bd13b4d55664518e4b2741de813ac726fe87892.zip
Make engine ctx init internal to engine.c per PR feedback
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/c_src/crypto.c10
-rw-r--r--lib/crypto/c_src/engine.c24
-rw-r--r--lib/crypto/c_src/engine.h10
3 files changed, 25 insertions, 19 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 5b42b976bb..27a0ebfd6b 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -190,17 +190,9 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
if (!init_cipher_ctx(env)) {
return __LINE__;
}
-
-#ifdef HAS_ENGINE_SUPPORT
- engine_ctx_rtype = enif_open_resource_type(env, NULL, "ENGINE_CTX",
- (ErlNifResourceDtor*) engine_ctx_dtor,
- ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER,
- NULL);
- if (!engine_ctx_rtype) {
- PRINTF_ERR0("CRYPTO: Could not open resource type 'ENGINE_CTX'");
+ if (!init_engine_ctx(env)) {
return __LINE__;
}
-#endif
if (library_initialized) {
/* Repeated loading of this library (module upgrade).
diff --git a/lib/crypto/c_src/engine.c b/lib/crypto/c_src/engine.c
index ffafa909e6..dc8e1828ce 100644
--- a/lib/crypto/c_src/engine.c
+++ b/lib/crypto/c_src/engine.c
@@ -21,12 +21,17 @@
#include "engine.h"
#ifdef HAS_ENGINE_SUPPORT
-ErlNifResourceType* engine_ctx_rtype;
+struct engine_ctx {
+ ENGINE *engine;
+ char *id;
+};
+
+static ErlNifResourceType* engine_ctx_rtype;
static int get_engine_load_cmd_list(ErlNifEnv* env, const ERL_NIF_TERM term, char **cmds, int i);
static int zero_terminate(ErlNifBinary bin, char **buf);
-void engine_ctx_dtor(ErlNifEnv* env, struct engine_ctx* ctx) {
+static void engine_ctx_dtor(ErlNifEnv* env, struct engine_ctx* ctx) {
PRINTF_ERR0("engine_ctx_dtor");
if(ctx->id) {
PRINTF_ERR1(" non empty ctx->id=%s", ctx->id);
@@ -75,6 +80,21 @@ static int zero_terminate(ErlNifBinary bin, char **buf) {
}
#endif /* HAS_ENGINE_SUPPORT */
+int init_engine_ctx(ErlNifEnv *env) {
+#ifdef HAS_ENGINE_SUPPORT
+ engine_ctx_rtype = enif_open_resource_type(env, NULL, "ENGINE_CTX",
+ (ErlNifResourceDtor*) engine_ctx_dtor,
+ ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER,
+ NULL);
+ if (engine_ctx_rtype == NULL) {
+ PRINTF_ERR0("CRYPTO: Could not open resource type 'ENGINE_CTX'");
+ return 0;
+ }
+#endif
+
+ return 1;
+}
+
ERL_NIF_TERM engine_by_id_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{/* (EngineId) */
#ifdef HAS_ENGINE_SUPPORT
diff --git a/lib/crypto/c_src/engine.h b/lib/crypto/c_src/engine.h
index 93d55fd513..4a2eed9672 100644
--- a/lib/crypto/c_src/engine.h
+++ b/lib/crypto/c_src/engine.h
@@ -24,18 +24,12 @@
#include "common.h"
#ifdef HAS_ENGINE_SUPPORT
-struct engine_ctx {
- ENGINE *engine;
- char *id;
-};
-
-extern ErlNifResourceType* engine_ctx_rtype;
-
int get_engine_and_key_id(ErlNifEnv *env, ERL_NIF_TERM key, char ** id, ENGINE **e);
char *get_key_password(ErlNifEnv *env, ERL_NIF_TERM key);
-void engine_ctx_dtor(ErlNifEnv* env, struct engine_ctx* ctx);
#endif /* HAS_ENGINE_SUPPORT */
+int init_engine_ctx(ErlNifEnv *env);
+
ERL_NIF_TERM engine_by_id_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM engine_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM engine_finish_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);