1 // Copyright Joyent, Inc. and other Node contributors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 #include "node_crypto.h"
23 #include "async_wrap-inl.h"
24 #include "debug_utils-inl.h"
25 #include "memory_tracker-inl.h"
26 #include "node_external_reference.h"
27 #include "threadpoolwork-inl.h"
28 #include "v8.h"
29
30 namespace node {
31
32 using v8::Context;
33 using v8::Local;
34 using v8::Object;
35 using v8::Value;
36
37 namespace crypto {
38
39 #define CRYPTO_NAMESPACE_LIST_BASE(V) \
40 V(AES) \
41 V(CipherBase) \
42 V(DiffieHellman) \
43 V(DSAAlg) \
44 V(ECDH) \
45 V(Hash) \
46 V(HKDFJob) \
47 V(Hmac) \
48 V(Keygen) \
49 V(Keys) \
50 V(NativeKeyObject) \
51 V(PBKDF2Job) \
52 V(Random) \
53 V(RSAAlg) \
54 V(SecureContext) \
55 V(Sign) \
56 V(SPKAC) \
57 V(Timing) \
58 V(Util) \
59 V(Verify) \
60 V(X509Certificate)
61
62 #ifdef OPENSSL_NO_SCRYPT
63 #define SCRYPT_NAMESPACE_LIST(V)
64 #else
65 #define SCRYPT_NAMESPACE_LIST(V) V(ScryptJob)
66 #endif // OPENSSL_NO_SCRYPT
67
68 #define CRYPTO_NAMESPACE_LIST(V) \
69 CRYPTO_NAMESPACE_LIST_BASE(V) \
70 SCRYPT_NAMESPACE_LIST(V)
71
Initialize(Local<Object> target,Local<Value> unused,Local<Context> context,void * priv)72 void Initialize(Local<Object> target,
73 Local<Value> unused,
74 Local<Context> context,
75 void* priv) {
76 Environment* env = Environment::GetCurrent(context);
77
78 if (!InitCryptoOnce(env->isolate())) {
79 return;
80 }
81
82 #define V(Namespace) Namespace::Initialize(env, target);
83 CRYPTO_NAMESPACE_LIST(V)
84 #undef V
85 }
86
RegisterExternalReferences(ExternalReferenceRegistry * registry)87 void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
88 #define V(Namespace) Namespace::RegisterExternalReferences(registry);
89 CRYPTO_NAMESPACE_LIST(V)
90 #undef V
91 }
92 } // namespace crypto
93 } // namespace node
94
95 NODE_BINDING_CONTEXT_AWARE_INTERNAL(crypto, node::crypto::Initialize)
96 NODE_BINDING_EXTERNAL_REFERENCE(crypto,
97 node::crypto::RegisterExternalReferences)
98