Skip to content
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

crypto: simplify Hmac::HmacUpdate #22132

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 5 additions & 6 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3252,15 +3252,14 @@ void Hmac::HmacUpdate(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&hmac, args.Holder());

// Only copy the data if we have to, because it's a string
bool r = true;
bool r = false;
if (args[0]->IsString()) {
StringBytes::InlineDecoder decoder;
if (!decoder.Decode(env, args[0].As<String>(), args[1], UTF8)) {
args.GetReturnValue().Set(false);
return;
if (decoder.Decode(env, args[0].As<String>(), args[1], UTF8)) {
r = hmac->HmacUpdate(decoder.out(), decoder.size());
}
r = hmac->HmacUpdate(decoder.out(), decoder.size());
} else if (args[0]->IsArrayBufferView()) {
} else {
CHECK(args[0]->IsArrayBufferView());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work as expected? We weren't exactly crashing at an illegal argument before. It must be fine if it's type-checked in JS-land (in which case, do we even need it?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is being type-checked in JS, but in case someone calls the binding directly or finds a way to avoid JS type-checking, this is here for safety.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

char* buf = Buffer::Data(args[0]);
size_t buflen = Buffer::Length(args[0]);
r = hmac->HmacUpdate(buf, buflen);
Expand Down