Skip to content

Commit

Permalink
crypto: simplify Hmac::HmacUpdate
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tniessen authored and rvagg committed Aug 15, 2018
1 parent bc35f17 commit 916a1d5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3237,15 +3237,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());
char* buf = Buffer::Data(args[0]);
size_t buflen = Buffer::Length(args[0]);
r = hmac->HmacUpdate(buf, buflen);
Expand Down

0 comments on commit 916a1d5

Please sign in to comment.