mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
crypto: avoid copying buffers to UTF-8 strings in crypto.hash()
PR-URL: https://github.com/nodejs/node/pull/59067 Fixes: https://github.com/nodejs/node/issues/59057 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
324d9fc9d4
commit
135fca5b72
1 file changed
+11
-14
+11
-14
@@ -274,26 +274,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(),
|
||||
};
|
||||
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<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]] {
|
||||
|
||||
Reference in new issue
Block a user