diff --git a/src/crypto/crypto_hash.cc b/src/crypto/crypto_hash.cc index d56cedf626999b..f05d216f3429a3 100644 --- a/src/crypto/crypto_hash.cc +++ b/src/crypto/crypto_hash.cc @@ -275,26 +275,23 @@ void Hash::OneShotDigest(const FunctionCallbackInfo& args) { } DataPointer output = ([&]() -> DataPointer { - Utf8Value utf8(isolate, args[3]); - ncrypto::Buffer buf; if (args[3]->IsString()) { - buf = { + Utf8Value utf8(isolate, args[3]); + ncrypto::Buffer buf = { .data = reinterpret_cast(utf8.out()), .len = utf8.length(), }; - } else { - ArrayBufferViewContents input(args[3]); - buf = { - .data = reinterpret_cast(input.data()), - .len = input.length(), - }; - } - - if (is_xof) { - return ncrypto::xofHashDigest(buf, md, output_length); + return is_xof ? ncrypto::xofHashDigest(buf, md, output_length) + : ncrypto::hashDigest(buf, md); } - return ncrypto::hashDigest(buf, md); + ArrayBufferViewContents input(args[3]); + ncrypto::Buffer buf = { + .data = reinterpret_cast(input.data()), + .len = input.length(), + }; + return is_xof ? ncrypto::xofHashDigest(buf, md, output_length) + : ncrypto::hashDigest(buf, md); })(); if (!output) [[unlikely]] {