-
Notifications
You must be signed in to change notification settings - Fork 3k
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
node:crypto
: native Hmac
and Hash
#17920
Conversation
Updated 9:34 PM PT - Mar 6th, 2025
❌ @dylan-conway, your commit fbe992d has 2 failures in
🧪 try this PR locally: bunx bun-pr 17920 |
node:crypto
: native Hmac
node:crypto
: native Hmac
and Hash
8fb4cbe
to
9714b50
Compare
@@ -2337,6 +2337,111 @@ pub const Crypto = struct { | |||
pub usingnamespace JSC.Codegen.JSCryptoHasher; | |||
usingnamespace bun.New(@This()); | |||
|
|||
// For using only CryptoHasherZig in c++ | |||
pub const Extern = struct { |
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.
non-blocking note: when zig structs do not contain fields, it is convention to name them snake case lowercase since it is just a namespace.
|
||
case WebCore::BufferEncodingType::ucs2: | ||
case WebCore::BufferEncodingType::utf16le: { | ||
memcpy(data.data(), bytes.data(), bytes.size()); |
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.
thinking
it would be interesting if all our memcpy calls had ASSERT(data.size() >= bytes.size())
hmac->m_ctx.reset(); | ||
} | ||
|
||
// TODO(dylan-conway): We shouldn't set finalized if coming from _flush |
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.
im not sure if this todo is blocking
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.
Updated the comment. It's true we shouldn't set finalized if the caller is _flush, but the field isn't javascript facing and turns out it works the same due to m_ctx.reset() above this.
void finishCreation(JSC::VM& vm, JSC::JSObject* prototype) | ||
{ | ||
Base::finishCreation(vm, 2, "Hmac"_s, PropertyAdditionMode::WithStructureTransition); | ||
// putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, JSC::PropertyAdditionMode::WithStructureTransition); |
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.
is that right
What does this PR do?
Moves
Hmac
andHash
to c++ using ncryptoHow did you verify your code works?
Added
test-crypto-hmac.js
,test-crypto-hash.js
, andtest-crypto-hash-stream-pipe.js