| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3245,8 +3245,11 @@ size_t KeyObjectData::GetSymmetricKeySize() const { | |||
| 3245 | 3245 | return symmetric_key_len_; | |
| 3246 | 3246 | } | |
| 3247 | 3247 | ||
| 3248 | - Local<Function> KeyObjectHandle::Initialize(Environment* env, | ||
| 3249 | - Local<Object> target) { | ||
| 3248 | + Local<Function> KeyObjectHandle::Initialize(Environment* env) { | ||
| 3249 | + Local<Function> templ = env->crypto_key_object_handle_constructor(); | ||
| 3250 | + if (!templ.IsEmpty()) { | ||
| 3251 | + return templ; | ||
| 3252 | + } | ||
| 3250 | 3253 | Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | |
| 3251 | 3254 | t->InstanceTemplate()->SetInternalFieldCount( | |
| 3252 | 3255 | KeyObjectHandle::kInternalFieldCount); | |
@@ -3260,20 +3263,16 @@ Local<Function> KeyObjectHandle::Initialize(Environment* env, | |||
| 3260 | 3263 | env->SetProtoMethod(t, "export", Export); | |
| 3261 | 3264 | ||
| 3262 | 3265 | auto function = t->GetFunction(env->context()).ToLocalChecked(); | |
| 3263 | - target->Set(env->context(), | ||
| 3264 | - FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"), | ||
| 3265 | - function).Check(); | ||
| 3266 | - | ||
| 3267 | - return function; | ||
| 3266 | + env->set_crypto_key_object_handle_constructor(function); | ||
| 3267 | + return KeyObjectHandle::Initialize(env); | ||
| 3268 | 3268 | } | |
| 3269 | 3269 | ||
| 3270 | 3270 | MaybeLocal<Object> KeyObjectHandle::Create( | |
| 3271 | 3271 | Environment* env, | |
| 3272 | 3272 | std::shared_ptr<KeyObjectData> data) { | |
| 3273 | 3273 | Local<Object> obj; | |
| 3274 | - if (!env->crypto_key_object_handle_constructor() | ||
| 3275 | - ->NewInstance(env->context(), 0, nullptr) | ||
| 3276 | - .ToLocal(&obj)) { | ||
| 3274 | + Local<Function> fctun = KeyObjectHandle::Initialize(env); | ||
| 3275 | + if (!fctun->NewInstance(env->context(), 0, nullptr).ToLocal(&obj)) { | ||
| 3277 | 3276 | return MaybeLocal<Object>(); | |
| 3278 | 3277 | } | |
| 3279 | 3278 | ||
@@ -3446,6 +3445,11 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize( | |||
| 3446 | 3445 | ||
| 3447 | 3446 | Local<Value> handle = KeyObjectHandle::Create(env, data_).ToLocalChecked(); | |
| 3448 | 3447 | Local<Function> key_ctor; | |
| 3448 | + Local<Value> arg = FIXED_ONE_BYTE_STRING(env->isolate(), | ||
| 3449 | + "internal/crypto/keys"); | ||
| 3450 | + if (env->native_module_require()-> | ||
| 3451 | + Call(context, Null(env->isolate()), 1, &arg).IsEmpty()) | ||
| 3452 | + return {}; | ||
| 3449 | 3453 | switch (data_->GetKeyType()) { | |
| 3450 | 3454 | case kKeyTypeSecret: | |
| 3451 | 3455 | key_ctor = env->crypto_key_object_secret_constructor(); | |
@@ -6976,8 +6980,9 @@ void Initialize(Local<Object> target, | |||
| 6976 | 6980 | ||
| 6977 | 6981 | Environment* env = Environment::GetCurrent(context); | |
| 6978 | 6982 | SecureContext::Initialize(env, target); | |
| 6979 | - env->set_crypto_key_object_handle_constructor( | ||
| 6980 | - KeyObjectHandle::Initialize(env, target)); | ||
| 6983 | + target->Set(env->context(), | ||
| 6984 | + FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"), | ||
| 6985 | + KeyObjectHandle::Initialize(env)).Check(); | ||
| 6981 | 6986 | env->SetMethod(target, "createNativeKeyObjectClass", | |
| 6982 | 6987 | CreateNativeKeyObjectClass); | |
| 6983 | 6988 | CipherBase::Initialize(env, target); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -446,8 +446,7 @@ class KeyObjectData { | |||
| 446 | 446 | ||
| 447 | 447 | class KeyObjectHandle : public BaseObject { | |
| 448 | 448 | public: | |
| 449 | - static v8::Local<v8::Function> Initialize(Environment* env, | ||
| 450 | - v8::Local<v8::Object> target); | ||
| 449 | + static v8::Local<v8::Function> Initialize(Environment* env); | ||
| 451 | 450 | ||
| 452 | 451 | static v8::MaybeLocal<v8::Object> Create(Environment* env, | |
| 453 | 452 | std::shared_ptr<KeyObjectData> data); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + if (!common.hasCrypto) | ||
| 4 | + common.skip('missing crypto'); | ||
| 5 | + | ||
| 6 | + // Issue https://github.com/nodejs/node/issues/35263 | ||
| 7 | + /* Description: test for checking keyobject passed to worker thread | ||
| 8 | + does not crash */ | ||
| 9 | + const { createSecretKey } = require('crypto'); | ||
| 10 | + | ||
| 11 | + const { Worker, isMainThread, workerData } = require('worker_threads'); | ||
| 12 | + | ||
| 13 | + if (isMainThread) { | ||
| 14 | + const key = createSecretKey(Buffer.from('hello')); | ||
| 15 | + new Worker(__filename, { workerData: key }); | ||
| 16 | + } else { | ||
| 17 | + console.log(workerData); | ||
| 18 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments