Skip to content

Commit 916a1d5

Browse files
tniessenrvagg
authored andcommitted
crypto: simplify Hmac::HmacUpdate
This makes HmacUpdate slightly simpler and introduces a CHECK instead of ignoring invalid input types. PR-URL: #22132 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent bc35f17 commit 916a1d5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/node_crypto.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -3237,15 +3237,14 @@ void Hmac::HmacUpdate(const FunctionCallbackInfo<Value>& args) {
32373237
ASSIGN_OR_RETURN_UNWRAP(&hmac, args.Holder());
32383238

32393239
// Only copy the data if we have to, because it's a string
3240-
bool r = true;
3240+
bool r = false;
32413241
if (args[0]->IsString()) {
32423242
StringBytes::InlineDecoder decoder;
3243-
if (!decoder.Decode(env, args[0].As<String>(), args[1], UTF8)) {
3244-
args.GetReturnValue().Set(false);
3245-
return;
3243+
if (decoder.Decode(env, args[0].As<String>(), args[1], UTF8)) {
3244+
r = hmac->HmacUpdate(decoder.out(), decoder.size());
32463245
}
3247-
r = hmac->HmacUpdate(decoder.out(), decoder.size());
3248-
} else if (args[0]->IsArrayBufferView()) {
3246+
} else {
3247+
CHECK(args[0]->IsArrayBufferView());
32493248
char* buf = Buffer::Data(args[0]);
32503249
size_t buflen = Buffer::Length(args[0]);
32513250
r = hmac->HmacUpdate(buf, buflen);

0 commit comments

Comments
 (0)