@@ -2925,9 +2925,9 @@ ByteSource ByteSource::NullTerminatedCopy(Environment* env,
29252925 : FromString (env, value.As <String>(), true );
29262926}
29272927
2928- ByteSource ByteSource::FromSymmetricKeyObject (Local<Value> handle) {
2928+ ByteSource ByteSource::FromSymmetricKeyObjectHandle (Local<Value> handle) {
29292929 CHECK (handle->IsObject ());
2930- KeyObject * key = Unwrap<KeyObject >(handle.As <Object>());
2930+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(handle.As <Object>());
29312931 CHECK_NOT_NULL (key);
29322932 return Foreign (key->GetSymmetricKey (), key->GetSymmetricKeySize ());
29332933}
@@ -3073,7 +3073,7 @@ static ManagedEVPPKey GetPrivateKeyFromJs(
30733073 " Failed to read private key" );
30743074 } else {
30753075 CHECK (args[*offset]->IsObject () && allow_key_object);
3076- KeyObject * key;
3076+ KeyObjectHandle * key;
30773077 ASSIGN_OR_RETURN_UNWRAP (&key, args[*offset].As <Object>(), ManagedEVPPKey ());
30783078 CHECK_EQ (key->GetKeyType (), kKeyTypePrivate );
30793079 (*offset) += 4 ;
@@ -3133,7 +3133,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
31333133 " Failed to read asymmetric key" );
31343134 } else {
31353135 CHECK (args[*offset]->IsObject ());
3136- KeyObject * key = Unwrap<KeyObject >(args[*offset].As <Object>());
3136+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(args[*offset].As <Object>());
31373137 CHECK_NOT_NULL (key);
31383138 CHECK_NE (key->GetKeyType (), kKeyTypeSecret );
31393139 (*offset) += 4 ;
@@ -3243,10 +3243,11 @@ EVP_PKEY* ManagedEVPPKey::get() const {
32433243 return pkey_.get ();
32443244}
32453245
3246- Local<Function> KeyObject::Initialize (Environment* env, Local<Object> target) {
3246+ Local<Function> KeyObjectHandle::Initialize (Environment* env,
3247+ Local<Object> target) {
32473248 Local<FunctionTemplate> t = env->NewFunctionTemplate (New);
32483249 t->InstanceTemplate ()->SetInternalFieldCount (
3249- KeyObject ::kInternalFieldCount );
3250+ KeyObjectHandle ::kInternalFieldCount );
32503251 t->Inherit (BaseObject::GetConstructorTemplate (env));
32513252
32523253 env->SetProtoMethod (t, " init" , Init);
@@ -3258,25 +3259,25 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
32583259
32593260 auto function = t->GetFunction (env->context ()).ToLocalChecked ();
32603261 target->Set (env->context (),
3261- FIXED_ONE_BYTE_STRING (env->isolate (), " KeyObject " ),
3262+ FIXED_ONE_BYTE_STRING (env->isolate (), " KeyObjectHandle " ),
32623263 function).Check ();
32633264
32643265 return function;
32653266}
32663267
3267- MaybeLocal<Object> KeyObject ::Create (Environment* env,
3268- KeyType key_type,
3269- const ManagedEVPPKey& pkey) {
3268+ MaybeLocal<Object> KeyObjectHandle ::Create (Environment* env,
3269+ KeyType key_type,
3270+ const ManagedEVPPKey& pkey) {
32703271 CHECK_NE (key_type, kKeyTypeSecret );
32713272 Local<Value> type = Integer::New (env->isolate (), key_type);
32723273 Local<Object> obj;
3273- if (!env->crypto_key_object_constructor ()
3274+ if (!env->crypto_key_object_handle_constructor ()
32743275 ->NewInstance (env->context (), 1 , &type)
32753276 .ToLocal (&obj)) {
32763277 return MaybeLocal<Object>();
32773278 }
32783279
3279- KeyObject * key = Unwrap<KeyObject >(obj);
3280+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(obj);
32803281 CHECK_NOT_NULL (key);
32813282 if (key_type == kKeyTypePublic )
32823283 key->InitPublic (pkey);
@@ -3285,44 +3286,44 @@ MaybeLocal<Object> KeyObject::Create(Environment* env,
32853286 return obj;
32863287}
32873288
3288- ManagedEVPPKey KeyObject ::GetAsymmetricKey () const {
3289+ ManagedEVPPKey KeyObjectHandle ::GetAsymmetricKey () const {
32893290 CHECK_NE (key_type_, kKeyTypeSecret );
32903291 return this ->asymmetric_key_ ;
32913292}
32923293
3293- const char * KeyObject ::GetSymmetricKey () const {
3294+ const char * KeyObjectHandle ::GetSymmetricKey () const {
32943295 CHECK_EQ (key_type_, kKeyTypeSecret );
32953296 return this ->symmetric_key_ .get ();
32963297}
32973298
3298- size_t KeyObject ::GetSymmetricKeySize () const {
3299+ size_t KeyObjectHandle ::GetSymmetricKeySize () const {
32993300 CHECK_EQ (key_type_, kKeyTypeSecret );
33003301 return this ->symmetric_key_len_ ;
33013302}
33023303
3303- void KeyObject ::New (const FunctionCallbackInfo<Value>& args) {
3304+ void KeyObjectHandle ::New (const FunctionCallbackInfo<Value>& args) {
33043305 CHECK (args.IsConstructCall ());
33053306 CHECK (args[0 ]->IsInt32 ());
33063307 KeyType key_type = static_cast <KeyType>(args[0 ].As <Uint32>()->Value ());
33073308 Environment* env = Environment::GetCurrent (args);
3308- new KeyObject (env, args.This (), key_type);
3309+ new KeyObjectHandle (env, args.This (), key_type);
33093310}
33103311
3311- KeyType KeyObject ::GetKeyType () const {
3312+ KeyType KeyObjectHandle ::GetKeyType () const {
33123313 return this ->key_type_ ;
33133314}
33143315
3315- KeyObject::KeyObject (Environment* env,
3316- Local<Object> wrap,
3317- KeyType key_type)
3316+ KeyObjectHandle::KeyObjectHandle (Environment* env,
3317+ Local<Object> wrap,
3318+ KeyType key_type)
33183319 : BaseObject(env, wrap),
33193320 key_type_ (key_type),
33203321 symmetric_key_(nullptr , nullptr ) {
33213322 MakeWeak ();
33223323}
33233324
3324- void KeyObject ::Init (const FunctionCallbackInfo<Value>& args) {
3325- KeyObject * key;
3325+ void KeyObjectHandle ::Init (const FunctionCallbackInfo<Value>& args) {
3326+ KeyObjectHandle * key;
33263327 ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
33273328 MarkPopErrorOnReturn mark_pop_error_on_return;
33283329
@@ -3358,7 +3359,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
33583359 }
33593360}
33603361
3361- void KeyObject ::InitSecret (Local<ArrayBufferView> abv) {
3362+ void KeyObjectHandle ::InitSecret (Local<ArrayBufferView> abv) {
33623363 CHECK_EQ (this ->key_type_ , kKeyTypeSecret );
33633364
33643365 size_t key_len = abv->ByteLength ();
@@ -3371,19 +3372,19 @@ void KeyObject::InitSecret(Local<ArrayBufferView> abv) {
33713372 this ->symmetric_key_len_ = key_len;
33723373}
33733374
3374- void KeyObject ::InitPublic (const ManagedEVPPKey& pkey) {
3375+ void KeyObjectHandle ::InitPublic (const ManagedEVPPKey& pkey) {
33753376 CHECK_EQ (this ->key_type_ , kKeyTypePublic );
33763377 CHECK (pkey);
33773378 this ->asymmetric_key_ = pkey;
33783379}
33793380
3380- void KeyObject ::InitPrivate (const ManagedEVPPKey& pkey) {
3381+ void KeyObjectHandle ::InitPrivate (const ManagedEVPPKey& pkey) {
33813382 CHECK_EQ (this ->key_type_ , kKeyTypePrivate );
33823383 CHECK (pkey);
33833384 this ->asymmetric_key_ = pkey;
33843385}
33853386
3386- Local<Value> KeyObject ::GetAsymmetricKeyType () const {
3387+ Local<Value> KeyObjectHandle ::GetAsymmetricKeyType () const {
33873388 CHECK_NE (this ->key_type_ , kKeyTypeSecret );
33883389 switch (EVP_PKEY_id (this ->asymmetric_key_ .get ())) {
33893390 case EVP_PKEY_RSA:
@@ -3409,21 +3410,23 @@ Local<Value> KeyObject::GetAsymmetricKeyType() const {
34093410 }
34103411}
34113412
3412- void KeyObject::GetAsymmetricKeyType (const FunctionCallbackInfo<Value>& args) {
3413- KeyObject* key;
3413+ void KeyObjectHandle::GetAsymmetricKeyType (
3414+ const FunctionCallbackInfo<Value>& args) {
3415+ KeyObjectHandle* key;
34143416 ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
34153417
34163418 args.GetReturnValue ().Set (key->GetAsymmetricKeyType ());
34173419}
34183420
3419- void KeyObject::GetSymmetricKeySize (const FunctionCallbackInfo<Value>& args) {
3420- KeyObject* key;
3421+ void KeyObjectHandle::GetSymmetricKeySize (
3422+ const FunctionCallbackInfo<Value>& args) {
3423+ KeyObjectHandle* key;
34213424 ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
34223425 args.GetReturnValue ().Set (static_cast <uint32_t >(key->GetSymmetricKeySize ()));
34233426}
34243427
3425- void KeyObject ::Export (const FunctionCallbackInfo<Value>& args) {
3426- KeyObject * key;
3428+ void KeyObjectHandle ::Export (const FunctionCallbackInfo<Value>& args) {
3429+ KeyObjectHandle * key;
34273430 ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
34283431
34293432 MaybeLocal<Value> result;
@@ -3450,17 +3453,17 @@ void KeyObject::Export(const FunctionCallbackInfo<Value>& args) {
34503453 args.GetReturnValue ().Set (result.ToLocalChecked ());
34513454}
34523455
3453- Local<Value> KeyObject ::ExportSecretKey () const {
3456+ Local<Value> KeyObjectHandle ::ExportSecretKey () const {
34543457 return Buffer::Copy (env (), symmetric_key_.get (), symmetric_key_len_)
34553458 .ToLocalChecked ();
34563459}
34573460
3458- MaybeLocal<Value> KeyObject ::ExportPublicKey (
3461+ MaybeLocal<Value> KeyObjectHandle ::ExportPublicKey (
34593462 const PublicKeyEncodingConfig& config) const {
34603463 return WritePublicKey (env (), asymmetric_key_.get (), config);
34613464}
34623465
3463- MaybeLocal<Value> KeyObject ::ExportPrivateKey (
3466+ MaybeLocal<Value> KeyObjectHandle ::ExportPrivateKey (
34643467 const PrivateKeyEncodingConfig& config) const {
34653468 return WritePrivateKey (env (), asymmetric_key_.get (), config);
34663469}
@@ -3663,7 +3666,7 @@ static ByteSource GetSecretKeyBytes(Environment* env, Local<Value> value) {
36633666 // in JS to avoid creating an unprotected copy on the heap.
36643667 return value->IsString () || Buffer::HasInstance (value) ?
36653668 ByteSource::FromStringOrBuffer (env, value) :
3666- ByteSource::FromSymmetricKeyObject (value);
3669+ ByteSource::FromSymmetricKeyObjectHandle (value);
36673670}
36683671
36693672void CipherBase::InitIv (const FunctionCallbackInfo<Value>& args) {
@@ -6277,7 +6280,8 @@ class GenerateKeyPairJob : public CryptoJob {
62776280 if (public_key_encoding_.output_key_object_ ) {
62786281 // Note that this has the downside of containing sensitive data of the
62796282 // private key.
6280- if (!KeyObject::Create (env (), kKeyTypePublic , pkey_).ToLocal (pubkey))
6283+ if (!KeyObjectHandle::Create (env (), kKeyTypePublic , pkey_)
6284+ .ToLocal (pubkey))
62816285 return false ;
62826286 } else {
62836287 if (!WritePublicKey (env (), pkey_.get (), public_key_encoding_)
@@ -6287,7 +6291,7 @@ class GenerateKeyPairJob : public CryptoJob {
62876291
62886292 // Now do the same for the private key.
62896293 if (private_key_encoding_.output_key_object_ ) {
6290- if (!KeyObject ::Create (env (), kKeyTypePrivate , pkey_)
6294+ if (!KeyObjectHandle ::Create (env (), kKeyTypePrivate , pkey_)
62916295 .ToLocal (privkey))
62926296 return false ;
62936297 } else {
@@ -6731,10 +6735,10 @@ void StatelessDiffieHellman(const FunctionCallbackInfo<Value>& args) {
67316735 Environment* env = Environment::GetCurrent (args);
67326736
67336737 CHECK (args[0 ]->IsObject () && args[1 ]->IsObject ());
6734- KeyObject * our_key_object;
6738+ KeyObjectHandle * our_key_object;
67356739 ASSIGN_OR_RETURN_UNWRAP (&our_key_object, args[0 ].As <Object>());
67366740 CHECK_EQ (our_key_object->GetKeyType (), kKeyTypePrivate );
6737- KeyObject * their_key_object;
6741+ KeyObjectHandle * their_key_object;
67386742 ASSIGN_OR_RETURN_UNWRAP (&their_key_object, args[1 ].As <Object>());
67396743 CHECK_NE (their_key_object->GetKeyType (), kKeyTypeSecret );
67406744
@@ -6865,7 +6869,8 @@ void Initialize(Local<Object> target,
68656869
68666870 Environment* env = Environment::GetCurrent (context);
68676871 SecureContext::Initialize (env, target);
6868- env->set_crypto_key_object_constructor (KeyObject::Initialize (env, target));
6872+ env->set_crypto_key_object_handle_constructor (
6873+ KeyObjectHandle::Initialize (env, target));
68696874 CipherBase::Initialize (env, target);
68706875 DiffieHellman::Initialize (env, target);
68716876 ECDH::Initialize (env, target);
0 commit comments