-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
wip: crypto: use cppgc to manage Hash #51017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern is likely to become fairly common assuming we get more use of the new mixins... likely a good idea to separate this unwrapping of |
||
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.This()); | ||
} else { | ||
ctx = CppgcMixin::Unwrap<T>(args.This()); | ||
if (ctx == nullptr) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what scenario can ctx be nullptr? |
||
} | ||
|
||
if (args[0]->IsString()) { | ||
StringBytes::InlineDecoder decoder; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
require('../common'); | ||
const { validateByRetainingPath } = require('../common/heap'); | ||
const { createHash } = require('crypto'); | ||
const assert = require('assert'); | ||
|
||
// In case the bootstrap process creates any Hash objects, capture a snapshot first | ||
// and save the initial length. | ||
const originalNodes = validateByRetainingPath('Node / Hash', [ | ||
{ edge_name: 'mdctx' }, | ||
], true); | ||
|
||
const count = 5; | ||
const arr = []; | ||
for (let i = 0; i < count; ++i) { | ||
arr.push(createHash('sha1')); | ||
} | ||
|
||
const nodesWithCtx = validateByRetainingPath('Node / Hash', [ | ||
{ edge_name: 'mdctx', node_name: 'Node / EVP_MD_CTX' }, | ||
]); | ||
|
||
assert.strictEqual(nodesWithCtx.length - originalNodes.length, count); | ||
|
||
for (let i = 0; i < count; ++i) { | ||
arr[i].update('test').digest('hex'); | ||
} | ||
|
||
const nodesWithDigest = validateByRetainingPath('Node / Hash', [ | ||
{ edge_name: 'md', node_name: 'Node / ByteSource' }, | ||
]); | ||
|
||
assert.strictEqual(nodesWithDigest.length - originalNodes.length, count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a comment to here why we don't call new Hash but prefer the recommended change to here.