Coverage Report

Created: 2025-08-03 10:06

/src/node/src/node_crypto.cc
Line
Count
Source (jump to first uncovered line)
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
8.84k
  V(AES)                                                                       \
41
8.84k
  V(CipherBase)                                                                \
42
8.84k
  V(DiffieHellman)                                                             \
43
8.84k
  V(DSAAlg)                                                                    \
44
8.84k
  V(ECDH)                                                                      \
45
8.84k
  V(Hash)                                                                      \
46
8.84k
  V(HKDFJob)                                                                   \
47
8.84k
  V(Hmac)                                                                      \
48
8.84k
  V(Keygen)                                                                    \
49
8.84k
  V(Keys)                                                                      \
50
8.84k
  V(NativeKeyObject)                                                           \
51
8.84k
  V(PBKDF2Job)                                                                 \
52
8.84k
  V(Random)                                                                    \
53
8.84k
  V(RSAAlg)                                                                    \
54
8.84k
  V(SecureContext)                                                             \
55
8.84k
  V(Sign)                                                                      \
56
8.84k
  V(SPKAC)                                                                     \
57
8.84k
  V(Timing)                                                                    \
58
8.84k
  V(Util)                                                                      \
59
8.84k
  V(Verify)                                                                    \
60
8.84k
  V(X509Certificate)
61
62
#ifdef OPENSSL_NO_SCRYPT
63
#define SCRYPT_NAMESPACE_LIST(V)
64
#else
65
8.84k
#define SCRYPT_NAMESPACE_LIST(V) V(ScryptJob)
66
#endif  // OPENSSL_NO_SCRYPT
67
68
#define CRYPTO_NAMESPACE_LIST(V)                                               \
69
8.84k
  CRYPTO_NAMESPACE_LIST_BASE(V)                                                \
70
8.84k
  SCRYPT_NAMESPACE_LIST(V)
71
72
void Initialize(Local<Object> target,
73
                Local<Value> unused,
74
                Local<Context> context,
75
8.84k
                void* priv) {
76
8.84k
  Environment* env = Environment::GetCurrent(context);
77
78
8.84k
  if (!InitCryptoOnce(env->isolate())) {
79
0
    return;
80
0
  }
81
82
194k
#define V(Namespace) Namespace::Initialize(env, target);
83
194k
  CRYPTO_NAMESPACE_LIST(V)
84
8.84k
#undef V
85
8.84k
}
86
87
0
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
88
0
#define V(Namespace) Namespace::RegisterExternalReferences(registry);
89
0
  CRYPTO_NAMESPACE_LIST(V)
90
0
#undef V
91
0
}
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)