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 <me@jonathanmoss.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • 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
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.