3
3
4
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
5
6
- #include " base_object .h"
6
+ #include " cppgc_helpers .h"
7
7
#include " crypto/crypto_keys.h"
8
8
#include " crypto/crypto_util.h"
9
9
#include " env.h"
10
10
#include " memory_tracker.h"
11
11
#include " v8.h"
12
+ #include " cppgc/external.h"
12
13
13
14
namespace node {
14
15
namespace crypto {
15
- class Hash final : public BaseObject {
16
+
17
+ class ExternalEVPCtx final : public cppgc::External {
18
+ public:
19
+ virtual size_t GetSize () const override {
20
+ return ptr_ ? kSizeOf_EVP_MD_CTX : 0 ;
21
+ }
22
+ virtual const char * GetHumanReadableName () const override { return " EVP_MD_CTX" ; }
23
+ virtual void Trace (cppgc::Visitor* v) const override {}
24
+
25
+ EVP_MD_CTX* get () const { return ptr_.get (); }
26
+ void reset (EVP_MD_CTX* ptr = nullptr ) { ptr_.reset (ptr); }
27
+ explicit operator bool () const { return !!ptr_; }
28
+
29
+ private:
30
+ EVPMDCtxPointer ptr_{};
31
+ };
32
+
33
+ class Hash final : public cppgc::GarbageCollected<Hash>,
34
+ public cppgc::NameProvider,
35
+ public CppgcMixin {
16
36
public:
17
37
static void Initialize (Environment* env, v8::Local<v8::Object> target);
18
38
static void RegisterExternalReferences (ExternalReferenceRegistry* registry);
19
-
20
- void MemoryInfo (MemoryTracker* tracker) const override ;
21
- SET_MEMORY_INFO_NAME (Hash)
22
- SET_SELF_SIZE (Hash)
39
+ const char * GetHumanReadableName () const final { return " Node / Hash" ; }
40
+ void Trace (cppgc::Visitor* visitor) const final ;
23
41
24
42
bool HashInit (const EVP_MD* md, v8::Maybe<unsigned int > xof_md_len);
25
43
bool HashUpdate (const char * data, size_t len);
@@ -28,15 +46,15 @@ class Hash final : public BaseObject {
28
46
static void GetCachedAliases (const v8::FunctionCallbackInfo<v8::Value>& args);
29
47
static void OneShotDigest (const v8::FunctionCallbackInfo<v8::Value>& args);
30
48
49
+ Hash (Environment* env, v8::Local<v8::Object> wrap);
50
+
31
51
protected:
32
52
static void New (const v8::FunctionCallbackInfo<v8::Value>& args);
33
53
static void HashUpdate (const v8::FunctionCallbackInfo<v8::Value>& args);
34
54
static void HashDigest (const v8::FunctionCallbackInfo<v8::Value>& args);
35
55
36
- Hash (Environment* env, v8::Local<v8::Object> wrap);
37
-
38
56
private:
39
- EVPMDCtxPointer mdctx_{};
57
+ ExternalEVPCtx mdctx_{};
40
58
unsigned int md_len_ = 0 ;
41
59
ByteSource digest_;
42
60
};
0 commit comments