wip: crypto: use cppgc to manage Hash by joyeecheung · Pull Request #51017 · nodejs/node · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/crypto/crypto_hash.cc
17 changes: 9 additions & 8 deletions src/crypto/crypto_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "base_object.h"
#include "cppgc_helpers.h"
#include "crypto/crypto_keys.h"
#include "crypto/crypto_util.h"
#include "env.h"
Expand All @@ -12,29 +12,30 @@

namespace node {
namespace crypto {
class Hash final : public BaseObject {

class Hash final : CPPGC_MIXIN(Hash) {
public:
SET_CPPGC_NAME(Hash)
void Trace(cppgc::Visitor* visitor) const final;
void MemoryInfo(MemoryTracker* tracker) const override;

static void Initialize(Environment* env, v8::Local<v8::Object> target);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

void MemoryInfo(MemoryTracker* tracker) const override;
SET_MEMORY_INFO_NAME(Hash)
SET_SELF_SIZE(Hash)

bool HashInit(const EVP_MD* md, v8::Maybe<unsigned int> xof_md_len);
bool HashUpdate(const char* data, size_t len);

static void GetHashes(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetCachedAliases(const v8::FunctionCallbackInfo<v8::Value>& args);
static void OneShotDigest(const v8::FunctionCallbackInfo<v8::Value>& args);

Hash(Environment* env, v8::Local<v8::Object> wrap);

protected:
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void HashUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void HashDigest(const v8::FunctionCallbackInfo<v8::Value>& args);

Hash(Environment* env, v8::Local<v8::Object> wrap);

private:
ncrypto::EVPMDCtxPointer mdctx_{};
unsigned int md_len_ = 0;
Expand Down
8 changes: 7 additions & 1 deletion src/crypto/crypto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "async_wrap.h"
#include "cppgc_helpers.h"
#include "env.h"
#include "node_errors.h"
#include "node_external_reference.h"
Expand Down Expand Up @@ -57,7 +58,12 @@ void Decode(const v8::FunctionCallbackInfo<v8::Value>& args,
void (*callback)(T*, const v8::FunctionCallbackInfo<v8::Value>&,
const char*, size_t)) {
T* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.This());
if constexpr (std::is_base_of_v<BaseObject, T>) {
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.This());
} else {
ctx = CppgcMixin::Unwrap<T>(args.This());
if (ctx == nullptr) return;
}

if (args[0]->IsString()) {
StringBytes::InlineDecoder decoder;
Expand Down
33 changes: 33 additions & 0 deletions test/pummel/test-heapdump-hash.js