Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/crypto/crypto_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,23 @@ void Hash::OneShotDigest(const FunctionCallbackInfo<Value>& args) {
}

DataPointer output = ([&]() -> DataPointer {
Utf8Value utf8(isolate, args[3]);
ncrypto::Buffer<const unsigned char> buf;
if (args[3]->IsString()) {
buf = {
Utf8Value utf8(isolate, args[3]);
ncrypto::Buffer<const unsigned char> buf = {
.data = reinterpret_cast<const unsigned char*>(utf8.out()),
.len = utf8.length(),
};
} else {
ArrayBufferViewContents<unsigned char> input(args[3]);
buf = {
.data = reinterpret_cast<const unsigned char*>(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<unsigned char> input(args[3]);
ncrypto::Buffer<const unsigned char> buf = {
.data = reinterpret_cast<const unsigned char*>(input.data()),
.len = input.length(),
};
return is_xof ? ncrypto::xofHashDigest(buf, md, output_length)
: ncrypto::hashDigest(buf, md);
})();

if (!output) [[unlikely]] {
Expand Down
Loading