GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_crypto.cc Lines: 9 10 90.0 %
Date: 2022-01-19 04:14:09 Branches: 1 2 50.0 %

Line Branch Exec Source
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
72
4359
void Initialize(Local<Object> target,
73
                Local<Value> unused,
74
                Local<Context> context,
75
                void* priv) {
76
4359
  Environment* env = Environment::GetCurrent(context);
77
78
  // TODO(joyeecheung): this needs to be called again if the instance is
79
  // deserialized from a snapshot with the crypto bindings.
80
4359
  if (!InitCryptoOnce(env->isolate())) {
81
    return;
82
  }
83
84
#define V(Namespace) Namespace::Initialize(env, target);
85
4359
  CRYPTO_NAMESPACE_LIST(V)
86
#undef V
87
}
88
89
4916
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
90
#define V(Namespace) Namespace::RegisterExternalReferences(registry);
91
4916
  CRYPTO_NAMESPACE_LIST(V)
92
#undef V
93
4916
}
94
}  // namespace crypto
95
}  // namespace node
96
97
4977
NODE_MODULE_CONTEXT_AWARE_INTERNAL(crypto, node::crypto::Initialize)
98
4916
NODE_MODULE_EXTERNAL_REFERENCE(crypto, node::crypto::RegisterExternalReferences)