diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2021-09-27 10:24:40 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2021-10-19 12:44:53 +0300 |
commit | 3a7b2d7e519181a7d5f3521be767f1f8c1a4a1c4 (patch) | |
tree | ef0f4589f849c0bd460e502ba6146acb867445d3 /src/node_crypto.cc | |
parent | 5d0d611eb0793329cbebfb8d4a37b32dd0e1a795 (diff) |
src: register external references in crypto bindings
PR-URL: https://github.com/nodejs/node/pull/40239
Refs: https://github.com/nodejs/node/pull/38905
Refs: https://github.com/nodejs/node/issues/37476
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r-- | src/node_crypto.cc | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index b37e47d35b9..8563b14036c 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -22,8 +22,9 @@ #include "node_crypto.h" #include "async_wrap-inl.h" #include "debug_utils-inl.h" -#include "threadpoolwork-inl.h" #include "memory_tracker-inl.h" +#include "node_external_reference.h" +#include "threadpoolwork-inl.h" #include "v8.h" namespace node { @@ -36,48 +37,63 @@ using v8::Value; namespace crypto { +#define CRYPTO_NAMESPACE_LIST_BASE(V) \ + V(AES) \ + V(CipherBase) \ + V(DiffieHellman) \ + V(DSAAlg) \ + V(ECDH) \ + V(Hash) \ + V(HKDFJob) \ + V(Hmac) \ + V(Keygen) \ + V(Keys) \ + V(NativeKeyObject) \ + V(PBKDF2Job) \ + V(Random) \ + V(RSAAlg) \ + V(SecureContext) \ + V(Sign) \ + V(SPKAC) \ + V(Timing) \ + V(Util) \ + V(Verify) \ + V(X509Certificate) + +#ifdef OPENSSL_NO_SCRYPT +#define SCRYPT_NAMESPACE_LIST(V) +#else +#define SCRYPT_NAMESPACE_LIST(V) V(ScryptJob) +#endif // OPENSSL_NO_SCRYPT + +#define CRYPTO_NAMESPACE_LIST(V) \ + CRYPTO_NAMESPACE_LIST_BASE(V) \ + SCRYPT_NAMESPACE_LIST(V) + void Initialize(Local<Object> target, Local<Value> unused, Local<Context> context, void* priv) { Environment* env = Environment::GetCurrent(context); - static uv_once_t init_once = UV_ONCE_INIT; - TryCatch try_catch{env->isolate()}; - uv_once(&init_once, InitCryptoOnce); - if (try_catch.HasCaught() && !try_catch.HasTerminated()) { - try_catch.ReThrow(); + // TODO(joyeecheung): this needs to be called again if the instance is + // deserialized from a snapshot with the crypto bindings. + if (!InitCryptoOnce(env->isolate())) { return; } - AES::Initialize(env, target); - CipherBase::Initialize(env, target); - DiffieHellman::Initialize(env, target); - DSAAlg::Initialize(env, target); - ECDH::Initialize(env, target); - Hash::Initialize(env, target); - HKDFJob::Initialize(env, target); - Hmac::Initialize(env, target); - Keygen::Initialize(env, target); - Keys::Initialize(env, target); - NativeKeyObject::Initialize(env, target); - PBKDF2Job::Initialize(env, target); - Random::Initialize(env, target); - RSAAlg::Initialize(env, target); - SecureContext::Initialize(env, target); - Sign::Initialize(env, target); - SPKAC::Initialize(env, target); - Timing::Initialize(env, target); - Util::Initialize(env, target); - Verify::Initialize(env, target); - X509Certificate::Initialize(env, target); - -#ifndef OPENSSL_NO_SCRYPT - ScryptJob::Initialize(env, target); -#endif +#define V(Namespace) Namespace::Initialize(env, target); + CRYPTO_NAMESPACE_LIST(V) +#undef V } +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { +#define V(Namespace) Namespace::RegisterExternalReferences(registry); + CRYPTO_NAMESPACE_LIST(V) +#undef V +} } // namespace crypto } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(crypto, node::crypto::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(crypto, node::crypto::RegisterExternalReferences) |