Skip to content
Open
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
20 changes: 13 additions & 7 deletions src/crypto/crypto_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace node {
using ncrypto::DataPointer;
using ncrypto::EVPMDCtxPointer;
using ncrypto::MarkPopErrorOnReturn;
using v8::ArrayBuffer;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand All @@ -43,8 +44,11 @@ using v8::Maybe;
using v8::MaybeLocal;
using v8::Name;
using v8::Nothing;
using v8::Null;
using v8::Object;
using v8::String;
using v8::Uint32;
using v8::Uint8Array;
using v8::Value;

namespace crypto {
Expand Down Expand Up @@ -195,12 +199,12 @@ void Hash::GetCachedAliases(const FunctionCallbackInfo<Value>& args) {
values.reserve(size);
for (auto& [alias, id] : env->alias_to_md_id_map) {
names.push_back(OneByteString(isolate, alias));
values.push_back(v8::Uint32::New(isolate, id));
values.push_back(Uint32::New(isolate, id));
}
#else
CHECK(env->alias_to_md_id_map.empty());
#endif
Local<Value> prototype = v8::Null(isolate);
Local<Value> prototype = Null(isolate);
Local<Object> result =
Object::New(isolate, prototype, names.data(), values.data(), size);
args.GetReturnValue().Set(result);
Expand Down Expand Up @@ -233,7 +237,7 @@ const EVP_MD* GetDigestImplementation(Environment* env,
if (algorithm_cache.As<Object>()
->Set(isolate->GetCurrentContext(),
algorithm,
v8::Int32::New(isolate, result.cache_id))
Int32::New(isolate, result.cache_id))
.IsNothing()) {
return nullptr;
}
Expand Down Expand Up @@ -333,11 +337,13 @@ void Hash::OneShotDigest(const FunctionCallbackInfo<Value>& args) {

if (output_length == 0) {
if (output_enc == BUFFER) {
Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 0);
args.GetReturnValue().Set(
Buffer::New(isolate, ab, 0, 0).ToLocalChecked());
Local<Uint8Array> u8;
if (Buffer::New(isolate, ArrayBuffer::New(isolate, 0), 0, 0)
.ToLocal(&u8)) {
args.GetReturnValue().Set(u8);
}
} else {
args.GetReturnValue().Set(v8::String::Empty(isolate));
args.GetReturnValue().Set(String::Empty(isolate));
}
return;
}
Expand Down
Loading