From 3839ff0b7ab36ffe971a6a3c808c3eb539119cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 5 Aug 2018 00:24:07 +0200 Subject: [PATCH] crypto: simplify Hmac::HmacUpdate This makes HmacUpdate slightly simpler and introduces a CHECK instead of ignoring invalid input types. PR-URL: https://github.com/nodejs/node/pull/22132 Reviewed-By: Jon Moss Reviewed-By: Luigi Pinca Reviewed-By: Ujjwal Sharma Reviewed-By: Colin Ihrig --- src/node_crypto.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index bda70ab54d529b..735a470d2c5499 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3237,15 +3237,14 @@ void Hmac::HmacUpdate(const FunctionCallbackInfo& 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(), args[1], UTF8)) { - args.GetReturnValue().Set(false); - return; + if (decoder.Decode(env, args[0].As(), 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);