diff --git a/src/crypto/crypto_hash.cc b/src/crypto/crypto_hash.cc index ee8633d3119..83636d022ec 100644 --- a/src/crypto/crypto_hash.cc +++ b/src/crypto/crypto_hash.cc @@ -274,26 +274,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(), - }; + return is_xof ? ncrypto::xofHashDigest(buf, md, output_length) + : ncrypto::hashDigest(buf, md); } - if (is_xof) { - return ncrypto::xofHashDigest(buf, md, output_length); - } - - 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]] {