Skip to content

Commit 3839ff0

Browse files
tniessentargos
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent f68b165 commit 3839ff0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

‎src/node_crypto.cc‎

Lines changed: 5 additions & 6 deletions
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-
} elseif(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)