| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3265,8 +3265,11 @@ size_t KeyObjectData::GetSymmetricKeySize() const { | |||
| 3265 | 3265 | return symmetric_key_len_; | |
| 3266 | 3266 | } | |
| 3267 | 3267 | ||
| 3268 | - Local<Function> KeyObjectHandle::Initialize(Environment* env, | ||
| 3269 | - Local<Object> target) { | ||
| 3268 | + Local<Function> KeyObjectHandle::Initialize(Environment* env) { | ||
| 3269 | + Local<Function> templ = env->crypto_key_object_handle_constructor(); | ||
| 3270 | + if (!templ.IsEmpty()) { | ||
| 3271 | + return templ; | ||
| 3272 | + } | ||
| 3270 | 3273 | Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | |
| 3271 | 3274 | t->InstanceTemplate()->SetInternalFieldCount( | |
| 3272 | 3275 | KeyObjectHandle::kInternalFieldCount); | |
@@ -3280,20 +3283,16 @@ Local<Function> KeyObjectHandle::Initialize(Environment* env, | |||
| 3280 | 3283 | env->SetProtoMethod(t, "export", Export); | |
| 3281 | 3284 | ||
| 3282 | 3285 | auto function = t->GetFunction(env->context()).ToLocalChecked(); | |
| 3283 | - target->Set(env->context(), | ||
| 3284 | - FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"), | ||
| 3285 | - function).Check(); | ||
| 3286 | - | ||
| 3287 | - return function; | ||
| 3286 | + env->set_crypto_key_object_handle_constructor(function); | ||
| 3287 | + return KeyObjectHandle::Initialize(env); | ||
| 3288 | 3288 | } | |
| 3289 | 3289 | ||
| 3290 | 3290 | MaybeLocal<Object> KeyObjectHandle::Create( | |
| 3291 | 3291 | Environment* env, | |
| 3292 | 3292 | std::shared_ptr<KeyObjectData> data) { | |
| 3293 | 3293 | Local<Object> obj; | |
| 3294 | - if (!env->crypto_key_object_handle_constructor() | ||
| 3295 | - ->NewInstance(env->context(), 0, nullptr) | ||
| 3296 | - .ToLocal(&obj)) { | ||
| 3294 | + Local<Function> fctun = KeyObjectHandle::Initialize(env); | ||
| 3295 | + if (!fctun->NewInstance(env->context(), 0, nullptr).ToLocal(&obj)) { | ||
| 3297 | 3296 | return MaybeLocal<Object>(); | |
| 3298 | 3297 | } | |
| 3299 | 3298 | ||
@@ -3466,6 +3465,11 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize( | |||
| 3466 | 3465 | ||
| 3467 | 3466 | Local<Value> handle = KeyObjectHandle::Create(env, data_).ToLocalChecked(); | |
| 3468 | 3467 | Local<Function> key_ctor; | |
| 3468 | + Local<Value> arg = FIXED_ONE_BYTE_STRING(env->isolate(), | ||
| 3469 | + "internal/crypto/keys"); | ||
| 3470 | + if (env->native_module_require()-> | ||
| 3471 | + Call(context, Null(env->isolate()), 1, &arg).IsEmpty()) | ||
| 3472 | + return {}; | ||
| 3469 | 3473 | switch (data_->GetKeyType()) { | |
| 3470 | 3474 | case kKeyTypeSecret: | |
| 3471 | 3475 | key_ctor = env->crypto_key_object_secret_constructor(); | |
@@ -6950,8 +6954,9 @@ void Initialize(Local<Object> target, | |||
| 6950 | 6954 | ||
| 6951 | 6955 | Environment* env = Environment::GetCurrent(context); | |
| 6952 | 6956 | SecureContext::Initialize(env, target); | |
| 6953 | - env->set_crypto_key_object_handle_constructor( | ||
| 6954 | - KeyObjectHandle::Initialize(env, target)); | ||
| 6957 | + target->Set(env->context(), | ||
| 6958 | + FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"), | ||
| 6959 | + KeyObjectHandle::Initialize(env)).Check(); | ||
| 6955 | 6960 | env->SetMethod(target, "createNativeKeyObjectClass", | |
| 6956 | 6961 | CreateNativeKeyObjectClass); | |
| 6957 | 6962 | CipherBase::Initialize(env, target); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -447,8 +447,7 @@ class KeyObjectData { | |||
| 447 | 447 | ||
| 448 | 448 | class KeyObjectHandle : public BaseObject { | |
| 449 | 449 | public: | |
| 450 | - static v8::Local<v8::Function> Initialize(Environment* env, | ||
| 451 | - v8::Local<v8::Object> target); | ||
| 450 | + static v8::Local<v8::Function> Initialize(Environment* env); | ||
| 452 | 451 | ||
| 453 | 452 | static v8::MaybeLocal<v8::Object> Create(Environment* env, | |
| 454 | 453 | 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