@encharm/cws 4.5.2 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/CLAUDE.md +81 -0
- package/README.md +10 -5
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node127.node +0 -0
- package/dist/bindings/cws_linux_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node127.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node147.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node127.node +0 -0
- package/dist/bindings/cws_win32_x64_node137.node +0 -0
- package/dist/bindings/cws_win32_x64_node147.node +0 -0
- package/package.json +1 -1
- package/src/Addon.cpp +2 -1
- package/src/Addon.h +70 -14
- package/src/Hub.h +1 -0
- package/src/Networking.h +11 -0
- package/src/Socket.h +201 -6
- package/src/WebSocket.cpp +4 -1
- package/src/cSNode.cpp +2 -0
- package/src/cSNode.h +4 -0
- package/src/headers/24/tracing/agent.h +195 -0
- package/src/headers/24/tracing/trace_event.h +722 -0
- package/src/headers/26/acorn_version.h +6 -0
- package/src/headers/26/aliased_buffer-inl.h +264 -0
- package/src/headers/26/aliased_buffer.h +205 -0
- package/src/headers/26/aliased_struct-inl.h +143 -0
- package/src/headers/26/aliased_struct.h +248 -0
- package/src/headers/26/amaro_version.h +6 -0
- package/src/headers/26/async_context_frame.h +33 -0
- package/src/headers/26/async_wrap-inl.h +123 -0
- package/src/headers/26/async_wrap.h +254 -0
- package/src/headers/26/base_object-inl.h +333 -0
- package/src/headers/26/base_object.h +339 -0
- package/src/headers/26/base_object_types.h +76 -0
- package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/26/blob_serializer_deserializer.h +142 -0
- package/src/headers/26/builtin_info.h +57 -0
- package/src/headers/26/callback_queue-inl.h +97 -0
- package/src/headers/26/callback_queue.h +79 -0
- package/src/headers/26/cares_wrap.h +475 -0
- package/src/headers/26/cleanup_queue-inl.h +36 -0
- package/src/headers/26/cleanup_queue.h +79 -0
- package/src/headers/26/compile_cache.h +134 -0
- package/src/headers/26/connect_wrap.h +26 -0
- package/src/headers/26/connection_wrap.h +30 -0
- package/src/headers/26/cppgc_helpers-inl.h +69 -0
- package/src/headers/26/cppgc_helpers.h +162 -0
- package/src/headers/26/crypto/crypto_aes.h +107 -0
- package/src/headers/26/crypto/crypto_argon2.h +88 -0
- package/src/headers/26/crypto/crypto_bio.h +193 -0
- package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
- package/src/headers/26/crypto/crypto_cipher.h +291 -0
- package/src/headers/26/crypto/crypto_common.h +48 -0
- package/src/headers/26/crypto/crypto_context.h +219 -0
- package/src/headers/26/crypto/crypto_dh.h +104 -0
- package/src/headers/26/crypto/crypto_dsa.h +50 -0
- package/src/headers/26/crypto/crypto_ec.h +102 -0
- package/src/headers/26/crypto/crypto_hash.h +157 -0
- package/src/headers/26/crypto/crypto_hkdf.h +62 -0
- package/src/headers/26/crypto/crypto_hmac.h +92 -0
- package/src/headers/26/crypto/crypto_kem.h +131 -0
- package/src/headers/26/crypto/crypto_keygen.h +382 -0
- package/src/headers/26/crypto/crypto_keys.h +366 -0
- package/src/headers/26/crypto/crypto_kmac.h +79 -0
- package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
- package/src/headers/26/crypto/crypto_pqc.h +39 -0
- package/src/headers/26/crypto/crypto_random.h +127 -0
- package/src/headers/26/crypto/crypto_rsa.h +108 -0
- package/src/headers/26/crypto/crypto_scrypt.h +85 -0
- package/src/headers/26/crypto/crypto_sig.h +159 -0
- package/src/headers/26/crypto/crypto_spkac.h +21 -0
- package/src/headers/26/crypto/crypto_timing.h +20 -0
- package/src/headers/26/crypto/crypto_tls.h +342 -0
- package/src/headers/26/crypto/crypto_turboshake.h +105 -0
- package/src/headers/26/crypto/crypto_util.h +775 -0
- package/src/headers/26/crypto/crypto_x509.h +140 -0
- package/src/headers/26/dataqueue/queue.h +311 -0
- package/src/headers/26/debug_utils-inl.h +291 -0
- package/src/headers/26/debug_utils.h +200 -0
- package/src/headers/26/diagnosticfilename-inl.h +33 -0
- package/src/headers/26/embedded_data.h +17 -0
- package/src/headers/26/encoding_binding.h +59 -0
- package/src/headers/26/env-inl.h +956 -0
- package/src/headers/26/env.h +1294 -0
- package/src/headers/26/env_properties.h +562 -0
- package/src/headers/26/ffi/data.h +30 -0
- package/src/headers/26/ffi/fast.h +96 -0
- package/src/headers/26/ffi/jit_memory.h +26 -0
- package/src/headers/26/ffi/types.h +99 -0
- package/src/headers/26/handle_wrap.h +123 -0
- package/src/headers/26/histogram-inl.h +211 -0
- package/src/headers/26/histogram.h +474 -0
- package/src/headers/26/inspector/dom_storage_agent.h +68 -0
- package/src/headers/26/inspector/inspector_object_utils.h +38 -0
- package/src/headers/26/inspector/io_agent.h +30 -0
- package/src/headers/26/inspector/main_thread_interface.h +116 -0
- package/src/headers/26/inspector/network_agent.h +110 -0
- package/src/headers/26/inspector/network_inspector.h +45 -0
- package/src/headers/26/inspector/network_requests_buffer.h +195 -0
- package/src/headers/26/inspector/network_resource_manager.h +29 -0
- package/src/headers/26/inspector/node_json.h +24 -0
- package/src/headers/26/inspector/node_string.h +101 -0
- package/src/headers/26/inspector/notification_emitter.h +38 -0
- package/src/headers/26/inspector/protocol_helper.h +27 -0
- package/src/headers/26/inspector/runtime_agent.h +41 -0
- package/src/headers/26/inspector/storage_agent.h +33 -0
- package/src/headers/26/inspector/target_agent.h +59 -0
- package/src/headers/26/inspector/target_manager.h +70 -0
- package/src/headers/26/inspector/tracing_agent.h +43 -0
- package/src/headers/26/inspector/worker_agent.h +40 -0
- package/src/headers/26/inspector/worker_inspector.h +124 -0
- package/src/headers/26/inspector_agent.h +168 -0
- package/src/headers/26/inspector_io.h +78 -0
- package/src/headers/26/inspector_profiler.h +149 -0
- package/src/headers/26/inspector_socket.h +60 -0
- package/src/headers/26/inspector_socket_server.h +110 -0
- package/src/headers/26/js_native_api.h +634 -0
- package/src/headers/26/js_native_api_types.h +244 -0
- package/src/headers/26/js_native_api_v8.h +485 -0
- package/src/headers/26/js_native_api_v8_internals.h +45 -0
- package/src/headers/26/js_stream.h +57 -0
- package/src/headers/26/json_utils.h +172 -0
- package/src/headers/26/large_pages/node_large_page.h +34 -0
- package/src/headers/26/lru_cache-inl.h +69 -0
- package/src/headers/26/memory_tracker-inl.h +461 -0
- package/src/headers/26/memory_tracker.h +341 -0
- package/src/headers/26/module_wrap.h +231 -0
- package/src/headers/26/ncrypto.h +2008 -0
- package/src/headers/26/node.h +1693 -0
- package/src/headers/26/node_api.h +265 -0
- package/src/headers/26/node_api_internals.h +48 -0
- package/src/headers/26/node_api_types.h +58 -0
- package/src/headers/26/node_binding.h +170 -0
- package/src/headers/26/node_blob.h +160 -0
- package/src/headers/26/node_bob-inl.h +36 -0
- package/src/headers/26/node_bob.h +107 -0
- package/src/headers/26/node_buffer.h +92 -0
- package/src/headers/26/node_builtins.h +239 -0
- package/src/headers/26/node_concepts.h +46 -0
- package/src/headers/26/node_config_file.h +77 -0
- package/src/headers/26/node_constants.h +82 -0
- package/src/headers/26/node_context_data.h +171 -0
- package/src/headers/26/node_contextify.h +261 -0
- package/src/headers/26/node_crypto.h +66 -0
- package/src/headers/26/node_debug.h +30 -0
- package/src/headers/26/node_diagnostics_channel.h +121 -0
- package/src/headers/26/node_dir.h +52 -0
- package/src/headers/26/node_dotenv.h +45 -0
- package/src/headers/26/node_errors.h +378 -0
- package/src/headers/26/node_exit_code.h +54 -0
- package/src/headers/26/node_external_reference.h +171 -0
- package/src/headers/26/node_ffi.h +212 -0
- package/src/headers/26/node_file-inl.h +421 -0
- package/src/headers/26/node_file.h +561 -0
- package/src/headers/26/node_file_utils.h +39 -0
- package/src/headers/26/node_hash.h +212 -0
- package/src/headers/26/node_http2.h +1202 -0
- package/src/headers/26/node_http2_state.h +159 -0
- package/src/headers/26/node_http_common-inl.h +199 -0
- package/src/headers/26/node_http_common.h +535 -0
- package/src/headers/26/node_i18n.h +132 -0
- package/src/headers/26/node_internals.h +485 -0
- package/src/headers/26/node_locks.h +184 -0
- package/src/headers/26/node_main_instance.h +67 -0
- package/src/headers/26/node_mem-inl.h +113 -0
- package/src/headers/26/node_mem.h +45 -0
- package/src/headers/26/node_messaging.h +389 -0
- package/src/headers/26/node_metadata.h +172 -0
- package/src/headers/26/node_modules.h +102 -0
- package/src/headers/26/node_mutex.h +323 -0
- package/src/headers/26/node_object_wrap.h +145 -0
- package/src/headers/26/node_options-inl.h +524 -0
- package/src/headers/26/node_options.h +710 -0
- package/src/headers/26/node_perf.h +167 -0
- package/src/headers/26/node_perf_common.h +103 -0
- package/src/headers/26/node_platform.h +290 -0
- package/src/headers/26/node_process-inl.h +26 -0
- package/src/headers/26/node_process.h +112 -0
- package/src/headers/26/node_profiling.h +38 -0
- package/src/headers/26/node_realm-inl.h +156 -0
- package/src/headers/26/node_realm.h +236 -0
- package/src/headers/26/node_report.h +43 -0
- package/src/headers/26/node_revert.h +82 -0
- package/src/headers/26/node_root_certs.h +2937 -0
- package/src/headers/26/node_sea.h +101 -0
- package/src/headers/26/node_shadow_realm.h +46 -0
- package/src/headers/26/node_snapshot_builder.h +57 -0
- package/src/headers/26/node_snapshotable.h +167 -0
- package/src/headers/26/node_sockaddr-inl.h +248 -0
- package/src/headers/26/node_sockaddr.h +459 -0
- package/src/headers/26/node_sqlite.h +607 -0
- package/src/headers/26/node_stat_watcher.h +73 -0
- package/src/headers/26/node_task_runner.h +92 -0
- package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/26/node_threadsafe_cow.h +105 -0
- package/src/headers/26/node_union_bytes.h +81 -0
- package/src/headers/26/node_url.h +101 -0
- package/src/headers/26/node_url_pattern.h +118 -0
- package/src/headers/26/node_v8.h +78 -0
- package/src/headers/26/node_v8_embedder.h +26 -0
- package/src/headers/26/node_v8_platform-inl.h +96 -0
- package/src/headers/26/node_version.h +116 -0
- package/src/headers/26/node_wasi.h +184 -0
- package/src/headers/26/node_wasm_web_api.h +55 -0
- package/src/headers/26/node_watchdog.h +164 -0
- package/src/headers/26/node_webstorage.h +62 -0
- package/src/headers/26/node_worker.h +162 -0
- package/src/headers/26/path.h +36 -0
- package/src/headers/26/permission/boolean_permission.h +50 -0
- package/src/headers/26/permission/fs_permission.h +192 -0
- package/src/headers/26/permission/permission.h +155 -0
- package/src/headers/26/permission/permission_base.h +79 -0
- package/src/headers/26/pipe_wrap.h +80 -0
- package/src/headers/26/quic/application.h +279 -0
- package/src/headers/26/quic/arena.h +373 -0
- package/src/headers/26/quic/bindingdata.h +440 -0
- package/src/headers/26/quic/cid.h +127 -0
- package/src/headers/26/quic/data.h +358 -0
- package/src/headers/26/quic/defs.h +417 -0
- package/src/headers/26/quic/endpoint.h +519 -0
- package/src/headers/26/quic/guard.h +5 -0
- package/src/headers/26/quic/http3.h +25 -0
- package/src/headers/26/quic/packet.h +166 -0
- package/src/headers/26/quic/preferredaddress.h +72 -0
- package/src/headers/26/quic/session.h +770 -0
- package/src/headers/26/quic/session_manager.h +107 -0
- package/src/headers/26/quic/sessionticket.h +110 -0
- package/src/headers/26/quic/streams.h +518 -0
- package/src/headers/26/quic/tlscontext.h +353 -0
- package/src/headers/26/quic/tokens.h +263 -0
- package/src/headers/26/quic/transportparams.h +184 -0
- package/src/headers/26/req_wrap-inl.h +175 -0
- package/src/headers/26/req_wrap.h +79 -0
- package/src/headers/26/spawn_sync.h +243 -0
- package/src/headers/26/stream_base-inl.h +170 -0
- package/src/headers/26/stream_base.h +487 -0
- package/src/headers/26/stream_pipe.h +76 -0
- package/src/headers/26/stream_wrap.h +137 -0
- package/src/headers/26/string_bytes.h +114 -0
- package/src/headers/26/string_decoder-inl.h +31 -0
- package/src/headers/26/string_decoder.h +49 -0
- package/src/headers/26/tcp_wrap.h +138 -0
- package/src/headers/26/threadpoolwork-inl.h +70 -0
- package/src/headers/26/timer_wrap-inl.h +32 -0
- package/src/headers/26/timer_wrap.h +87 -0
- package/src/headers/26/timers.h +70 -0
- package/src/headers/26/tracing/agent.h +125 -0
- package/src/headers/26/tracing/agent_legacy.h +146 -0
- package/src/headers/26/tracing/agent_perfetto.h +145 -0
- package/src/headers/26/tracing/node_trace_buffer.h +91 -0
- package/src/headers/26/tracing/node_trace_writer.h +79 -0
- package/src/headers/26/tracing/trace_event.h +27 -0
- package/src/headers/26/tracing/trace_event_helper.h +40 -0
- package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
- package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
- package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
- package/src/headers/26/tracing/traced_value.h +167 -0
- package/src/headers/26/tty_wrap.h +65 -0
- package/src/headers/26/udp_wrap.h +231 -0
- package/src/headers/26/undici_version.h +6 -0
- package/src/headers/26/util-inl.h +788 -0
- package/src/headers/26/util.h +1207 -0
- package/src/headers/26/v8-cpp-heap-external.h +56 -0
- package/src/headers/26/v8-external-memory-accounter.h +60 -0
- package/src/headers/26/v8-fast-api-calls.h +784 -0
- package/src/headers/26/v8-inspector-protocol.h +13 -0
- package/src/headers/26/v8-inspector.h +458 -0
- package/src/headers/26/v8-metrics.h +273 -0
- package/src/headers/26/v8-trace-categories.h +28 -0
- package/src/headers/26/v8-unwinder-state.h +30 -0
- package/src/headers/26/v8-util.h +549 -0
- package/src/headers/26/v8-value-serializer-version.h +24 -0
- package/src/headers/26/v8-version-string.h +38 -0
- package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
- package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
- package/src/headers/26/zlib_version.h +6 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#ifndef SRC_CLEANUP_QUEUE_H_
|
|
2
|
+
#define SRC_CLEANUP_QUEUE_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <cstddef>
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <unordered_set>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
#include "memory_tracker.h"
|
|
12
|
+
|
|
13
|
+
namespace node {
|
|
14
|
+
|
|
15
|
+
class CleanupQueue : public MemoryRetainer {
|
|
16
|
+
public:
|
|
17
|
+
typedef void (*Callback)(void*);
|
|
18
|
+
|
|
19
|
+
CleanupQueue() = default;
|
|
20
|
+
|
|
21
|
+
// Not copyable.
|
|
22
|
+
CleanupQueue(const CleanupQueue&) = delete;
|
|
23
|
+
|
|
24
|
+
SET_MEMORY_INFO_NAME(CleanupQueue)
|
|
25
|
+
SET_NO_MEMORY_INFO()
|
|
26
|
+
inline size_t SelfSize() const override;
|
|
27
|
+
|
|
28
|
+
inline bool empty() const;
|
|
29
|
+
|
|
30
|
+
inline void Add(Callback cb, void* arg);
|
|
31
|
+
inline void Remove(Callback cb, void* arg);
|
|
32
|
+
void Drain();
|
|
33
|
+
|
|
34
|
+
private:
|
|
35
|
+
class CleanupHookCallback {
|
|
36
|
+
public:
|
|
37
|
+
CleanupHookCallback(Callback fn,
|
|
38
|
+
void* arg,
|
|
39
|
+
uint64_t insertion_order_counter)
|
|
40
|
+
: fn_(fn),
|
|
41
|
+
arg_(arg),
|
|
42
|
+
insertion_order_counter_(insertion_order_counter) {}
|
|
43
|
+
|
|
44
|
+
// Only hashes `arg_`, since that is usually enough to identify the hook.
|
|
45
|
+
struct Hash {
|
|
46
|
+
size_t operator()(const CleanupHookCallback& cb) const;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Compares by `fn_` and `arg_` being equal.
|
|
50
|
+
struct Equal {
|
|
51
|
+
bool operator()(const CleanupHookCallback& a,
|
|
52
|
+
const CleanupHookCallback& b) const;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
private:
|
|
56
|
+
friend class CleanupQueue;
|
|
57
|
+
Callback fn_;
|
|
58
|
+
void* arg_;
|
|
59
|
+
|
|
60
|
+
// We keep track of the insertion order for these objects, so that we can
|
|
61
|
+
// call the callbacks in reverse order when we are cleaning up.
|
|
62
|
+
uint64_t insertion_order_counter_;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
std::vector<CleanupHookCallback> GetOrdered() const;
|
|
66
|
+
|
|
67
|
+
// Use an unordered_set, so that we have efficient insertion and removal.
|
|
68
|
+
std::unordered_set<CleanupHookCallback,
|
|
69
|
+
CleanupHookCallback::Hash,
|
|
70
|
+
CleanupHookCallback::Equal>
|
|
71
|
+
cleanup_hooks_;
|
|
72
|
+
uint64_t cleanup_hook_counter_ = 0;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace node
|
|
76
|
+
|
|
77
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
78
|
+
|
|
79
|
+
#endif // SRC_CLEANUP_QUEUE_H_
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#ifndef SRC_COMPILE_CACHE_H_
|
|
2
|
+
#define SRC_COMPILE_CACHE_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <cinttypes>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <string_view>
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
#include "v8.h"
|
|
12
|
+
|
|
13
|
+
namespace node {
|
|
14
|
+
class Environment;
|
|
15
|
+
|
|
16
|
+
#define CACHED_CODE_TYPES(V) \
|
|
17
|
+
V(kCommonJS, 0) \
|
|
18
|
+
V(kESM, 1) \
|
|
19
|
+
V(kStrippedTypeScript, 2)
|
|
20
|
+
|
|
21
|
+
enum class CachedCodeType : uint8_t {
|
|
22
|
+
#define V(type, value) type = value,
|
|
23
|
+
CACHED_CODE_TYPES(V)
|
|
24
|
+
#undef V
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
struct CompileCacheEntry {
|
|
28
|
+
std::unique_ptr<v8::ScriptCompiler::CachedData> cache{nullptr};
|
|
29
|
+
uint32_t cache_key;
|
|
30
|
+
uint32_t code_hash;
|
|
31
|
+
uint32_t code_size;
|
|
32
|
+
|
|
33
|
+
std::string cache_filename;
|
|
34
|
+
std::string source_filename;
|
|
35
|
+
CachedCodeType type;
|
|
36
|
+
bool refreshed = false;
|
|
37
|
+
bool persisted = false;
|
|
38
|
+
|
|
39
|
+
// Copy the cache into a new store for V8 to consume. Caller takes
|
|
40
|
+
// ownership.
|
|
41
|
+
v8::ScriptCompiler::CachedData* CopyCache() const;
|
|
42
|
+
const char* type_name() const;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
#define COMPILE_CACHE_STATUS(V) \
|
|
46
|
+
V(FAILED) /* Failed to enable the cache */ \
|
|
47
|
+
V(ENABLED) /* Was not enabled before, and now enabled. */ \
|
|
48
|
+
V(ALREADY_ENABLED) /* Was already enabled. */ \
|
|
49
|
+
V(DISABLED) /* Has been disabled by NODE_DISABLE_COMPILE_CACHE. */
|
|
50
|
+
|
|
51
|
+
enum class CompileCacheEnableStatus : uint8_t {
|
|
52
|
+
#define V(status) status,
|
|
53
|
+
COMPILE_CACHE_STATUS(V)
|
|
54
|
+
#undef V
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
struct CompileCacheEnableResult {
|
|
58
|
+
CompileCacheEnableStatus status;
|
|
59
|
+
std::string cache_directory;
|
|
60
|
+
std::string message; // Set in case of failure.
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
enum class EnableOption : uint8_t {
|
|
64
|
+
DEFAULT = 0,
|
|
65
|
+
PORTABLE = 1 << 0,
|
|
66
|
+
// Only read existing cache entries: nothing is compiled into the in-memory
|
|
67
|
+
// store for persisting, nothing is written to disk, and the cache directory
|
|
68
|
+
// is not created if it does not exist.
|
|
69
|
+
READ_ONLY = 1 << 1,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
inline constexpr EnableOption operator|(EnableOption a, EnableOption b) {
|
|
73
|
+
return static_cast<EnableOption>(static_cast<uint8_t>(a) |
|
|
74
|
+
static_cast<uint8_t>(b));
|
|
75
|
+
}
|
|
76
|
+
inline constexpr bool HasOption(EnableOption value, EnableOption flag) {
|
|
77
|
+
return (static_cast<uint8_t>(value) & static_cast<uint8_t>(flag)) != 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
class CompileCacheHandler {
|
|
81
|
+
public:
|
|
82
|
+
explicit CompileCacheHandler(Environment* env);
|
|
83
|
+
CompileCacheEnableResult Enable(Environment* env,
|
|
84
|
+
const std::string& dir,
|
|
85
|
+
EnableOption option = EnableOption::DEFAULT);
|
|
86
|
+
|
|
87
|
+
void Persist();
|
|
88
|
+
|
|
89
|
+
CompileCacheEntry* GetOrInsert(v8::Local<v8::String> code,
|
|
90
|
+
v8::Local<v8::String> filename,
|
|
91
|
+
CachedCodeType type);
|
|
92
|
+
void MaybeSave(CompileCacheEntry* entry,
|
|
93
|
+
v8::Local<v8::Function> func,
|
|
94
|
+
bool rejected);
|
|
95
|
+
void MaybeSave(CompileCacheEntry* entry,
|
|
96
|
+
v8::Local<v8::Module> mod,
|
|
97
|
+
bool rejected);
|
|
98
|
+
void MaybeSave(CompileCacheEntry* entry, std::string_view transpiled);
|
|
99
|
+
std::string_view cache_dir() { return compile_cache_dir_; }
|
|
100
|
+
bool read_only() const { return read_only_; }
|
|
101
|
+
|
|
102
|
+
private:
|
|
103
|
+
void ReadCacheFile(CompileCacheEntry* entry);
|
|
104
|
+
|
|
105
|
+
template <typename T>
|
|
106
|
+
void MaybeSaveImpl(CompileCacheEntry* entry,
|
|
107
|
+
v8::Local<T> func_or_mod,
|
|
108
|
+
bool rejected);
|
|
109
|
+
|
|
110
|
+
template <typename... Args>
|
|
111
|
+
inline void Debug(const char* format, Args&&... args) const;
|
|
112
|
+
|
|
113
|
+
static constexpr size_t kMagicNumberOffset = 0;
|
|
114
|
+
static constexpr size_t kCodeSizeOffset = 1;
|
|
115
|
+
static constexpr size_t kCacheSizeOffset = 2;
|
|
116
|
+
static constexpr size_t kCodeHashOffset = 3;
|
|
117
|
+
static constexpr size_t kCacheHashOffset = 4;
|
|
118
|
+
static constexpr size_t kHeaderCount = 5;
|
|
119
|
+
|
|
120
|
+
v8::Isolate* isolate_ = nullptr;
|
|
121
|
+
bool is_debug_ = false;
|
|
122
|
+
|
|
123
|
+
std::string compile_cache_dir_;
|
|
124
|
+
std::string normalized_compile_cache_dir_;
|
|
125
|
+
EnableOption portable_ = EnableOption::DEFAULT;
|
|
126
|
+
bool read_only_ = false;
|
|
127
|
+
std::unordered_map<uint32_t, std::unique_ptr<CompileCacheEntry>>
|
|
128
|
+
compiler_cache_store_;
|
|
129
|
+
};
|
|
130
|
+
} // namespace node
|
|
131
|
+
|
|
132
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
133
|
+
|
|
134
|
+
#endif // SRC_COMPILE_CACHE_H_
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#ifndef SRC_CONNECT_WRAP_H_
|
|
2
|
+
#define SRC_CONNECT_WRAP_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "req_wrap-inl.h"
|
|
7
|
+
#include "async_wrap.h"
|
|
8
|
+
|
|
9
|
+
namespace node {
|
|
10
|
+
|
|
11
|
+
class ConnectWrap : public ReqWrap<uv_connect_t> {
|
|
12
|
+
public:
|
|
13
|
+
ConnectWrap(Environment* env,
|
|
14
|
+
v8::Local<v8::Object> req_wrap_obj,
|
|
15
|
+
AsyncWrap::ProviderType provider);
|
|
16
|
+
|
|
17
|
+
SET_NO_MEMORY_INFO()
|
|
18
|
+
SET_MEMORY_INFO_NAME(ConnectWrap)
|
|
19
|
+
SET_SELF_SIZE(ConnectWrap)
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
} // namespace node
|
|
23
|
+
|
|
24
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
25
|
+
|
|
26
|
+
#endif // SRC_CONNECT_WRAP_H_
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#ifndef SRC_CONNECTION_WRAP_H_
|
|
2
|
+
#define SRC_CONNECTION_WRAP_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "stream_wrap.h"
|
|
7
|
+
|
|
8
|
+
namespace node {
|
|
9
|
+
|
|
10
|
+
class Environment;
|
|
11
|
+
|
|
12
|
+
template <typename WrapType, typename UVType>
|
|
13
|
+
class ConnectionWrap : public LibuvStreamWrap {
|
|
14
|
+
public:
|
|
15
|
+
static void OnConnection(uv_stream_t* handle, int status);
|
|
16
|
+
static void AfterConnect(uv_connect_t* req, int status);
|
|
17
|
+
|
|
18
|
+
protected:
|
|
19
|
+
ConnectionWrap(Environment* env,
|
|
20
|
+
v8::Local<v8::Object> object,
|
|
21
|
+
ProviderType provider);
|
|
22
|
+
|
|
23
|
+
UVType handle_;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
} // namespace node
|
|
27
|
+
|
|
28
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
29
|
+
|
|
30
|
+
#endif // SRC_CONNECTION_WRAP_H_
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#ifndef SRC_CPPGC_HELPERS_INL_H_
|
|
2
|
+
#define SRC_CPPGC_HELPERS_INL_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "cppgc_helpers.h"
|
|
7
|
+
#include "env-inl.h"
|
|
8
|
+
|
|
9
|
+
namespace node {
|
|
10
|
+
|
|
11
|
+
template <typename T>
|
|
12
|
+
void CppgcMixin::Wrap(T* ptr, Realm* realm, v8::Local<v8::Object> obj) {
|
|
13
|
+
CHECK_GE(obj->InternalFieldCount(), T::kInternalFieldCount);
|
|
14
|
+
ptr->realm_ = realm;
|
|
15
|
+
v8::Isolate* isolate = realm->isolate();
|
|
16
|
+
ptr->traced_reference_ = v8::TracedReference<v8::Object>(isolate, obj);
|
|
17
|
+
// Note that ptr must be of concrete type T in Wrap.
|
|
18
|
+
auto* wrappable = static_cast<v8::Object::Wrappable*>(ptr);
|
|
19
|
+
v8::Object::Wrap<v8::CppHeapPointerTag::kDefaultTag>(isolate, obj, wrappable);
|
|
20
|
+
// Keep the layout consistent with BaseObjects.
|
|
21
|
+
obj->SetAlignedPointerInInternalField(
|
|
22
|
+
kEmbedderType,
|
|
23
|
+
realm->isolate_data()->embedder_id_for_cppgc(),
|
|
24
|
+
EmbedderDataTag::kEmbedderType);
|
|
25
|
+
obj->SetAlignedPointerInInternalField(kSlot, ptr, EmbedderDataTag::kDefault);
|
|
26
|
+
realm->TrackCppgcWrapper(ptr);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
template <typename T>
|
|
30
|
+
void CppgcMixin::Wrap(T* ptr, Environment* env, v8::Local<v8::Object> obj) {
|
|
31
|
+
Wrap(ptr, env->principal_realm(), obj);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
template <typename T>
|
|
35
|
+
T* CppgcMixin::Unwrap(v8::Local<v8::Object> obj) {
|
|
36
|
+
// We are not using v8::Object::Unwrap currently because that requires
|
|
37
|
+
// access to isolate which the ASSIGN_OR_RETURN_UNWRAP macro that we'll shim
|
|
38
|
+
// with ASSIGN_OR_RETURN_UNWRAP_GC doesn't take, and we also want a
|
|
39
|
+
// signature consistent with BaseObject::Unwrap() to avoid churn. Since
|
|
40
|
+
// cppgc-managed objects share the same layout as BaseObjects, just unwrap
|
|
41
|
+
// from the pointer in the internal field, which should be valid as long as
|
|
42
|
+
// the object is still alive.
|
|
43
|
+
if (obj->InternalFieldCount() != T::kInternalFieldCount) {
|
|
44
|
+
return nullptr;
|
|
45
|
+
}
|
|
46
|
+
T* ptr = static_cast<T*>(obj->GetAlignedPointerFromInternalField(
|
|
47
|
+
T::kSlot, EmbedderDataTag::kDefault));
|
|
48
|
+
return ptr;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
v8::Local<v8::Object> CppgcMixin::object() const {
|
|
52
|
+
return traced_reference_.Get(realm_->isolate());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Environment* CppgcMixin::env() const {
|
|
56
|
+
return realm_->env();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
CppgcMixin::~CppgcMixin() {
|
|
60
|
+
if (realm_ != nullptr) {
|
|
61
|
+
realm_->set_should_purge_empty_cppgc_wrappers(true);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
} // namespace node
|
|
66
|
+
|
|
67
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
68
|
+
|
|
69
|
+
#endif // SRC_CPPGC_HELPERS_INL_H_
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#ifndef SRC_CPPGC_HELPERS_H_
|
|
2
|
+
#define SRC_CPPGC_HELPERS_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <type_traits> // std::remove_reference
|
|
7
|
+
#include "cppgc/garbage-collected.h"
|
|
8
|
+
#include "cppgc/name-provider.h"
|
|
9
|
+
#include "cppgc/persistent.h"
|
|
10
|
+
#include "memory_tracker.h"
|
|
11
|
+
#include "util.h"
|
|
12
|
+
#include "v8-cppgc.h"
|
|
13
|
+
#include "v8-sandbox.h"
|
|
14
|
+
#include "v8.h"
|
|
15
|
+
|
|
16
|
+
namespace node {
|
|
17
|
+
|
|
18
|
+
class Environment;
|
|
19
|
+
class Realm;
|
|
20
|
+
class CppgcWrapperListNode;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This is a helper mixin with a BaseObject-like interface to help
|
|
24
|
+
* implementing wrapper objects managed by V8's cppgc (Oilpan) library.
|
|
25
|
+
* cppgc-manged objects in Node.js internals should extend this mixin,
|
|
26
|
+
* while non-cppgc-managed objects typically extend BaseObject - the
|
|
27
|
+
* latter are being migrated to be cppgc-managed wherever it's beneficial
|
|
28
|
+
* and practical. Typically cppgc-managed objects are more efficient to
|
|
29
|
+
* keep track of (which lowers initialization cost) and work better
|
|
30
|
+
* with V8's GC scheduling.
|
|
31
|
+
*
|
|
32
|
+
* A cppgc-managed native wrapper should look something like this, note
|
|
33
|
+
* that per cppgc rules, CPPGC_MIXIN(MyWrap) must be at the left-most
|
|
34
|
+
* position in the hierarchy (which ensures cppgc::GarbageCollected
|
|
35
|
+
* is at the left-most position).
|
|
36
|
+
*
|
|
37
|
+
* class MyWrap final : CPPGC_MIXIN(MyWrap) {
|
|
38
|
+
* public:
|
|
39
|
+
* SET_CPPGC_NAME(MyWrap) // Sets the heap snapshot name to "Node / MyWrap"
|
|
40
|
+
* void Trace(cppgc::Visitor* visitor) const final {
|
|
41
|
+
* CppgcMixin::Trace(visitor);
|
|
42
|
+
* visitor->Trace(...); // Trace any additional owned traceable data
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* If the wrapper needs to perform cleanups when it's destroyed and that
|
|
47
|
+
* cleanup relies on a living Node.js `Realm`, it should implement a
|
|
48
|
+
* pattern like this:
|
|
49
|
+
*
|
|
50
|
+
* ~MyWrap() { this->Destroy(); }
|
|
51
|
+
* void Clean(Realm* env) override {
|
|
52
|
+
* // Do cleanup that relies on a living Environemnt.
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
55
|
+
class CppgcMixin : public cppgc::GarbageCollectedMixin, public MemoryRetainer {
|
|
56
|
+
public:
|
|
57
|
+
// To help various callbacks access wrapper objects with different memory
|
|
58
|
+
// management, cppgc-managed objects share the same layout as BaseObjects.
|
|
59
|
+
enum InternalFields { kEmbedderType = 0, kSlot, kInternalFieldCount };
|
|
60
|
+
|
|
61
|
+
// The initialization cannot be done in the mixin constructor but has to be
|
|
62
|
+
// invoked from the child class constructor, per cppgc::GarbageCollectedMixin
|
|
63
|
+
// rules.
|
|
64
|
+
template <typename T>
|
|
65
|
+
static inline void Wrap(T* ptr, Realm* realm, v8::Local<v8::Object> obj);
|
|
66
|
+
template <typename T>
|
|
67
|
+
static inline void Wrap(T* ptr, Environment* env, v8::Local<v8::Object> obj);
|
|
68
|
+
|
|
69
|
+
inline v8::Local<v8::Object> object() const;
|
|
70
|
+
inline Environment* env() const;
|
|
71
|
+
inline Realm* realm() const { return realm_; }
|
|
72
|
+
inline v8::Local<v8::Object> object(v8::Isolate* isolate) const {
|
|
73
|
+
return traced_reference_.Get(isolate);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
template <typename T>
|
|
77
|
+
static inline T* Unwrap(v8::Local<v8::Object> obj);
|
|
78
|
+
|
|
79
|
+
// Subclasses are expected to invoke CppgcMixin::Trace() in their own Trace()
|
|
80
|
+
// methods.
|
|
81
|
+
void Trace(cppgc::Visitor* visitor) const override {
|
|
82
|
+
visitor->Trace(traced_reference_);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// TODO(joyeecheung): use ObjectSizeTrait;
|
|
86
|
+
inline size_t SelfSize() const override { return sizeof(*this); }
|
|
87
|
+
inline bool IsCppgcWrapper() const override { return true; }
|
|
88
|
+
|
|
89
|
+
// This is run for all the remaining Cppgc wrappers tracked in the Realm
|
|
90
|
+
// during Realm shutdown. The destruction of the wrappers would happen later,
|
|
91
|
+
// when the final garbage collection is triggered when CppHeap is torn down as
|
|
92
|
+
// part of the Isolate teardown. If subclasses of CppgcMixin wish to perform
|
|
93
|
+
// cleanups that depend on the Realm during destruction, they should implment
|
|
94
|
+
// it in a Clean() override, and then call this->Finalize() from their
|
|
95
|
+
// destructor. Outside of Finalize(), subclasses should avoid calling
|
|
96
|
+
// into JavaScript or perform any operation that can trigger garbage
|
|
97
|
+
// collection during the destruction.
|
|
98
|
+
void Finalize() {
|
|
99
|
+
if (realm_ == nullptr) return;
|
|
100
|
+
this->Clean(realm_);
|
|
101
|
+
realm_ = nullptr;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The default implementation of Clean() is a no-op. If subclasses wish
|
|
105
|
+
// to perform cleanup that require a living Realm, they should
|
|
106
|
+
// should put the cleanups in a Clean() override, and call this->Finalize()
|
|
107
|
+
// in the destructor, instead of doing those cleanups directly in the
|
|
108
|
+
// destructor.
|
|
109
|
+
virtual void Clean(Realm* realm) {}
|
|
110
|
+
|
|
111
|
+
inline ~CppgcMixin();
|
|
112
|
+
|
|
113
|
+
friend class CppgcWrapperListNode;
|
|
114
|
+
|
|
115
|
+
private:
|
|
116
|
+
Realm* realm_ = nullptr;
|
|
117
|
+
v8::TracedReference<v8::Object> traced_reference_;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// If the class doesn't have additional owned traceable data, use this macro to
|
|
121
|
+
// save the implementation of a custom Trace() method.
|
|
122
|
+
#define DEFAULT_CPPGC_TRACE() \
|
|
123
|
+
void Trace(cppgc::Visitor* visitor) const final { \
|
|
124
|
+
CppgcMixin::Trace(visitor); \
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// This macro sets the node name in the heap snapshot with a "Node /" prefix.
|
|
128
|
+
// Classes that use this macro must extend cppgc::NameProvider.
|
|
129
|
+
#define SET_CPPGC_NAME(Klass) \
|
|
130
|
+
inline const char* GetHumanReadableName() const final { \
|
|
131
|
+
return "Node / " #Klass; \
|
|
132
|
+
} \
|
|
133
|
+
inline const char* MemoryInfoName() const override { return #Klass; }
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Similar to ASSIGN_OR_RETURN_UNWRAP() but works on cppgc-managed types
|
|
137
|
+
* inheriting CppgcMixin.
|
|
138
|
+
*/
|
|
139
|
+
#define ASSIGN_OR_RETURN_UNWRAP_CPPGC(ptr, obj, ...) \
|
|
140
|
+
do { \
|
|
141
|
+
*ptr = CppgcMixin::Unwrap< \
|
|
142
|
+
typename std::remove_reference<decltype(**ptr)>::type>(obj); \
|
|
143
|
+
if (*ptr == nullptr) return __VA_ARGS__; \
|
|
144
|
+
} while (0)
|
|
145
|
+
} // namespace node
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Helper macro the manage the cppgc-based wrapper hierarchy. This must
|
|
149
|
+
* be used at the left-most position - right after `:` in the class inheritance,
|
|
150
|
+
* like this:
|
|
151
|
+
* class Klass : CPPGC_MIXIN(Klass) ... {}
|
|
152
|
+
*
|
|
153
|
+
* This needs to disable linters because it will be at odds with
|
|
154
|
+
* clang-format.
|
|
155
|
+
*/
|
|
156
|
+
#define CPPGC_MIXIN(Klass) \
|
|
157
|
+
public /* NOLINT(whitespace/indent) */ \
|
|
158
|
+
v8::Object::Wrappable, public CppgcMixin
|
|
159
|
+
|
|
160
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
161
|
+
|
|
162
|
+
#endif // SRC_CPPGC_HELPERS_H_
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#ifndef SRC_CRYPTO_CRYPTO_AES_H_
|
|
2
|
+
#define SRC_CRYPTO_CRYPTO_AES_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "crypto/crypto_cipher.h"
|
|
7
|
+
#include "crypto/crypto_keys.h"
|
|
8
|
+
#include "crypto/crypto_util.h"
|
|
9
|
+
#include "env.h"
|
|
10
|
+
#include "v8.h"
|
|
11
|
+
|
|
12
|
+
namespace node::crypto {
|
|
13
|
+
constexpr unsigned kNoAuthTagLength = static_cast<unsigned>(-1);
|
|
14
|
+
|
|
15
|
+
#define VARIANTS_COMMON(V) \
|
|
16
|
+
V(CTR_128, AES_CTR_Cipher, ncrypto::Cipher::AES_128_CTR) \
|
|
17
|
+
V(CTR_192, AES_CTR_Cipher, ncrypto::Cipher::AES_192_CTR) \
|
|
18
|
+
V(CTR_256, AES_CTR_Cipher, ncrypto::Cipher::AES_256_CTR) \
|
|
19
|
+
V(CBC_128, AES_Cipher, ncrypto::Cipher::AES_128_CBC) \
|
|
20
|
+
V(CBC_192, AES_Cipher, ncrypto::Cipher::AES_192_CBC) \
|
|
21
|
+
V(CBC_256, AES_Cipher, ncrypto::Cipher::AES_256_CBC) \
|
|
22
|
+
V(GCM_128, AES_Cipher, ncrypto::Cipher::AES_128_GCM) \
|
|
23
|
+
V(GCM_192, AES_Cipher, ncrypto::Cipher::AES_192_GCM) \
|
|
24
|
+
V(GCM_256, AES_Cipher, ncrypto::Cipher::AES_256_GCM) \
|
|
25
|
+
VARIANTS_KW(V)
|
|
26
|
+
|
|
27
|
+
#ifdef OPENSSL_IS_BORINGSSL
|
|
28
|
+
// BoringSSL does not expose EVP_aes_*_wrap via the EVP_CIPHER registry.
|
|
29
|
+
// Route AES-KW through low-level AES_wrap_key / AES_unwrap_key instead.
|
|
30
|
+
#define VARIANTS_KW(V) \
|
|
31
|
+
V(KW_128, AES_KW_Cipher, static_cast<const EVP_CIPHER*>(nullptr)) \
|
|
32
|
+
V(KW_192, AES_KW_Cipher, static_cast<const EVP_CIPHER*>(nullptr)) \
|
|
33
|
+
V(KW_256, AES_KW_Cipher, static_cast<const EVP_CIPHER*>(nullptr))
|
|
34
|
+
#else
|
|
35
|
+
#define VARIANTS_KW(V) \
|
|
36
|
+
V(KW_128, AES_Cipher, ncrypto::Cipher::AES_128_KW) \
|
|
37
|
+
V(KW_192, AES_Cipher, ncrypto::Cipher::AES_192_KW) \
|
|
38
|
+
V(KW_256, AES_Cipher, ncrypto::Cipher::AES_256_KW)
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#if OPENSSL_WITH_AES_OCB
|
|
42
|
+
#define VARIANTS_OCB(V) \
|
|
43
|
+
V(OCB_128, AES_Cipher, ncrypto::Cipher::AES_128_OCB) \
|
|
44
|
+
V(OCB_192, AES_Cipher, ncrypto::Cipher::AES_192_OCB) \
|
|
45
|
+
V(OCB_256, AES_Cipher, ncrypto::Cipher::AES_256_OCB)
|
|
46
|
+
#else
|
|
47
|
+
#define VARIANTS_OCB(V)
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
#define VARIANTS(V) \
|
|
51
|
+
VARIANTS_COMMON(V) \
|
|
52
|
+
VARIANTS_OCB(V)
|
|
53
|
+
|
|
54
|
+
enum class AESKeyVariant {
|
|
55
|
+
#define V(name, _, __) name,
|
|
56
|
+
VARIANTS(V)
|
|
57
|
+
#undef V
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
struct AESCipherConfig final : public MemoryRetainer {
|
|
61
|
+
AESKeyVariant variant;
|
|
62
|
+
ncrypto::Cipher cipher;
|
|
63
|
+
size_t length;
|
|
64
|
+
ByteSource iv; // Used for both iv or counter
|
|
65
|
+
ByteSource additional_data;
|
|
66
|
+
|
|
67
|
+
AESCipherConfig() = default;
|
|
68
|
+
|
|
69
|
+
AESCipherConfig(AESCipherConfig&& other) noexcept;
|
|
70
|
+
|
|
71
|
+
AESCipherConfig& operator=(AESCipherConfig&& other) noexcept;
|
|
72
|
+
|
|
73
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
74
|
+
SET_MEMORY_INFO_NAME(AESCipherConfig)
|
|
75
|
+
SET_SELF_SIZE(AESCipherConfig)
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
struct AESCipherTraits final {
|
|
79
|
+
static constexpr const char* JobName = "AESCipherJob";
|
|
80
|
+
|
|
81
|
+
using AdditionalParameters = AESCipherConfig;
|
|
82
|
+
|
|
83
|
+
static v8::Maybe<void> AdditionalConfig(
|
|
84
|
+
CryptoJobMode mode,
|
|
85
|
+
const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
86
|
+
unsigned int offset,
|
|
87
|
+
WebCryptoCipherMode cipher_mode,
|
|
88
|
+
AESCipherConfig* config);
|
|
89
|
+
|
|
90
|
+
static WebCryptoCipherStatus DoCipher(Environment* env,
|
|
91
|
+
const KeyObjectData& key_data,
|
|
92
|
+
WebCryptoCipherMode cipher_mode,
|
|
93
|
+
const AESCipherConfig& params,
|
|
94
|
+
const ByteSource& in,
|
|
95
|
+
ByteSource* out);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
using AESCryptoJob = CipherJob<AESCipherTraits>;
|
|
99
|
+
|
|
100
|
+
namespace AES {
|
|
101
|
+
void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
102
|
+
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
103
|
+
} // namespace AES
|
|
104
|
+
} // namespace node::crypto
|
|
105
|
+
|
|
106
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
107
|
+
#endif // SRC_CRYPTO_CRYPTO_AES_H_
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#ifndef SRC_CRYPTO_CRYPTO_ARGON2_H_
|
|
2
|
+
#define SRC_CRYPTO_CRYPTO_ARGON2_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "crypto/crypto_keys.h"
|
|
7
|
+
#include "crypto/crypto_util.h"
|
|
8
|
+
|
|
9
|
+
namespace node::crypto {
|
|
10
|
+
#if OPENSSL_WITH_ARGON2
|
|
11
|
+
|
|
12
|
+
// Argon2 is a password-based key derivation algorithm
|
|
13
|
+
// defined in https://datatracker.ietf.org/doc/html/rfc9106
|
|
14
|
+
|
|
15
|
+
// It takes as input a password, a salt value, and a
|
|
16
|
+
// handful of additional parameters that control the
|
|
17
|
+
// cost of the operation. In this case, the higher
|
|
18
|
+
// the cost, the better the result. The length parameter
|
|
19
|
+
// defines the number of bytes that are generated.
|
|
20
|
+
|
|
21
|
+
// The salt must be as random as possible and should be
|
|
22
|
+
// at least 16 bytes in length.
|
|
23
|
+
|
|
24
|
+
struct Argon2Config final : public MemoryRetainer {
|
|
25
|
+
KeyObjectData key;
|
|
26
|
+
ByteSource pass;
|
|
27
|
+
ByteSource salt;
|
|
28
|
+
ByteSource secret;
|
|
29
|
+
ByteSource ad;
|
|
30
|
+
ncrypto::Argon2Type type;
|
|
31
|
+
uint32_t iter;
|
|
32
|
+
uint32_t lanes;
|
|
33
|
+
uint32_t memcost;
|
|
34
|
+
uint32_t version = 0x13;
|
|
35
|
+
uint32_t keylen;
|
|
36
|
+
|
|
37
|
+
Argon2Config() = default;
|
|
38
|
+
|
|
39
|
+
explicit Argon2Config(Argon2Config&& other) noexcept;
|
|
40
|
+
|
|
41
|
+
Argon2Config& operator=(Argon2Config&& other) noexcept;
|
|
42
|
+
|
|
43
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
44
|
+
SET_MEMORY_INFO_NAME(Argon2Config)
|
|
45
|
+
SET_SELF_SIZE(Argon2Config)
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
struct Argon2Traits final {
|
|
49
|
+
using AdditionalParameters = Argon2Config;
|
|
50
|
+
static constexpr const char* JobName = "Argon2Job";
|
|
51
|
+
static constexpr AsyncWrap::ProviderType Provider =
|
|
52
|
+
AsyncWrap::PROVIDER_ARGON2REQUEST;
|
|
53
|
+
|
|
54
|
+
static v8::Maybe<void> AdditionalConfig(
|
|
55
|
+
CryptoJobMode mode,
|
|
56
|
+
const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
57
|
+
unsigned int offset,
|
|
58
|
+
Argon2Config* config);
|
|
59
|
+
|
|
60
|
+
static bool DeriveBits(Environment* env,
|
|
61
|
+
const Argon2Config& config,
|
|
62
|
+
ByteSource* out,
|
|
63
|
+
CryptoJobMode mode,
|
|
64
|
+
CryptoErrorStore* errors);
|
|
65
|
+
|
|
66
|
+
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
|
67
|
+
const Argon2Config& config,
|
|
68
|
+
ByteSource* out);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
using Argon2Job = DeriveBitsJob<Argon2Traits>;
|
|
72
|
+
|
|
73
|
+
namespace Argon2 {
|
|
74
|
+
void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
75
|
+
void RegisterExternalReferences(ExternalReferenceRegistry* registry);
|
|
76
|
+
} // namespace Argon2
|
|
77
|
+
|
|
78
|
+
#else
|
|
79
|
+
// If there is no Argon2 support, Argon2Job becomes a non-op
|
|
80
|
+
struct Argon2Job {
|
|
81
|
+
static void Initialize(Environment* env, v8::Local<v8::Object> target) {}
|
|
82
|
+
};
|
|
83
|
+
#endif
|
|
84
|
+
|
|
85
|
+
} // namespace node::crypto
|
|
86
|
+
|
|
87
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
88
|
+
#endif // SRC_CRYPTO_CRYPTO_ARGON2_H_
|