@@ -2925,9 +2925,9 @@ ByteSource ByteSource::NullTerminatedCopy(Environment* env,
2925
2925
: FromString (env, value.As <String>(), true );
2926
2926
}
2927
2927
2928
- ByteSource ByteSource::FromSymmetricKeyObject (Local<Value> handle) {
2928
+ ByteSource ByteSource::FromSymmetricKeyObjectHandle (Local<Value> handle) {
2929
2929
CHECK (handle->IsObject ());
2930
- KeyObject * key = Unwrap<KeyObject >(handle.As <Object>());
2930
+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(handle.As <Object>());
2931
2931
CHECK_NOT_NULL (key);
2932
2932
return Foreign (key->GetSymmetricKey (), key->GetSymmetricKeySize ());
2933
2933
}
@@ -3073,7 +3073,7 @@ static ManagedEVPPKey GetPrivateKeyFromJs(
3073
3073
" Failed to read private key" );
3074
3074
} else {
3075
3075
CHECK (args[*offset]->IsObject () && allow_key_object);
3076
- KeyObject * key;
3076
+ KeyObjectHandle * key;
3077
3077
ASSIGN_OR_RETURN_UNWRAP (&key, args[*offset].As <Object>(), ManagedEVPPKey ());
3078
3078
CHECK_EQ (key->GetKeyType (), kKeyTypePrivate );
3079
3079
(*offset) += 4 ;
@@ -3133,7 +3133,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
3133
3133
" Failed to read asymmetric key" );
3134
3134
} else {
3135
3135
CHECK (args[*offset]->IsObject ());
3136
- KeyObject * key = Unwrap<KeyObject >(args[*offset].As <Object>());
3136
+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(args[*offset].As <Object>());
3137
3137
CHECK_NOT_NULL (key);
3138
3138
CHECK_NE (key->GetKeyType (), kKeyTypeSecret );
3139
3139
(*offset) += 4 ;
@@ -3243,10 +3243,11 @@ EVP_PKEY* ManagedEVPPKey::get() const {
3243
3243
return pkey_.get ();
3244
3244
}
3245
3245
3246
- Local<Function> KeyObject::Initialize (Environment* env, Local<Object> target) {
3246
+ Local<Function> KeyObjectHandle::Initialize (Environment* env,
3247
+ Local<Object> target) {
3247
3248
Local<FunctionTemplate> t = env->NewFunctionTemplate (New);
3248
3249
t->InstanceTemplate ()->SetInternalFieldCount (
3249
- KeyObject ::kInternalFieldCount );
3250
+ KeyObjectHandle ::kInternalFieldCount );
3250
3251
t->Inherit (BaseObject::GetConstructorTemplate (env));
3251
3252
3252
3253
env->SetProtoMethod (t, " init" , Init);
@@ -3258,25 +3259,25 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
3258
3259
3259
3260
auto function = t->GetFunction (env->context ()).ToLocalChecked ();
3260
3261
target->Set (env->context (),
3261
- FIXED_ONE_BYTE_STRING (env->isolate (), " KeyObject " ),
3262
+ FIXED_ONE_BYTE_STRING (env->isolate (), " KeyObjectHandle " ),
3262
3263
function).Check ();
3263
3264
3264
3265
return function;
3265
3266
}
3266
3267
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) {
3270
3271
CHECK_NE (key_type, kKeyTypeSecret );
3271
3272
Local<Value> type = Integer::New (env->isolate (), key_type);
3272
3273
Local<Object> obj;
3273
- if (!env->crypto_key_object_constructor ()
3274
+ if (!env->crypto_key_object_handle_constructor ()
3274
3275
->NewInstance (env->context (), 1 , &type)
3275
3276
.ToLocal (&obj)) {
3276
3277
return MaybeLocal<Object>();
3277
3278
}
3278
3279
3279
- KeyObject * key = Unwrap<KeyObject >(obj);
3280
+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(obj);
3280
3281
CHECK_NOT_NULL (key);
3281
3282
if (key_type == kKeyTypePublic )
3282
3283
key->InitPublic (pkey);
@@ -3285,44 +3286,44 @@ MaybeLocal<Object> KeyObject::Create(Environment* env,
3285
3286
return obj;
3286
3287
}
3287
3288
3288
- ManagedEVPPKey KeyObject ::GetAsymmetricKey () const {
3289
+ ManagedEVPPKey KeyObjectHandle ::GetAsymmetricKey () const {
3289
3290
CHECK_NE (key_type_, kKeyTypeSecret );
3290
3291
return this ->asymmetric_key_ ;
3291
3292
}
3292
3293
3293
- const char * KeyObject ::GetSymmetricKey () const {
3294
+ const char * KeyObjectHandle ::GetSymmetricKey () const {
3294
3295
CHECK_EQ (key_type_, kKeyTypeSecret );
3295
3296
return this ->symmetric_key_ .get ();
3296
3297
}
3297
3298
3298
- size_t KeyObject ::GetSymmetricKeySize () const {
3299
+ size_t KeyObjectHandle ::GetSymmetricKeySize () const {
3299
3300
CHECK_EQ (key_type_, kKeyTypeSecret );
3300
3301
return this ->symmetric_key_len_ ;
3301
3302
}
3302
3303
3303
- void KeyObject ::New (const FunctionCallbackInfo<Value>& args) {
3304
+ void KeyObjectHandle ::New (const FunctionCallbackInfo<Value>& args) {
3304
3305
CHECK (args.IsConstructCall ());
3305
3306
CHECK (args[0 ]->IsInt32 ());
3306
3307
KeyType key_type = static_cast <KeyType>(args[0 ].As <Uint32>()->Value ());
3307
3308
Environment* env = Environment::GetCurrent (args);
3308
- new KeyObject (env, args.This (), key_type);
3309
+ new KeyObjectHandle (env, args.This (), key_type);
3309
3310
}
3310
3311
3311
- KeyType KeyObject ::GetKeyType () const {
3312
+ KeyType KeyObjectHandle ::GetKeyType () const {
3312
3313
return this ->key_type_ ;
3313
3314
}
3314
3315
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)
3318
3319
: BaseObject(env, wrap),
3319
3320
key_type_ (key_type),
3320
3321
symmetric_key_(nullptr , nullptr ) {
3321
3322
MakeWeak ();
3322
3323
}
3323
3324
3324
- void KeyObject ::Init (const FunctionCallbackInfo<Value>& args) {
3325
- KeyObject * key;
3325
+ void KeyObjectHandle ::Init (const FunctionCallbackInfo<Value>& args) {
3326
+ KeyObjectHandle * key;
3326
3327
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3327
3328
MarkPopErrorOnReturn mark_pop_error_on_return;
3328
3329
@@ -3358,7 +3359,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
3358
3359
}
3359
3360
}
3360
3361
3361
- void KeyObject ::InitSecret (Local<ArrayBufferView> abv) {
3362
+ void KeyObjectHandle ::InitSecret (Local<ArrayBufferView> abv) {
3362
3363
CHECK_EQ (this ->key_type_ , kKeyTypeSecret );
3363
3364
3364
3365
size_t key_len = abv->ByteLength ();
@@ -3371,19 +3372,19 @@ void KeyObject::InitSecret(Local<ArrayBufferView> abv) {
3371
3372
this ->symmetric_key_len_ = key_len;
3372
3373
}
3373
3374
3374
- void KeyObject ::InitPublic (const ManagedEVPPKey& pkey) {
3375
+ void KeyObjectHandle ::InitPublic (const ManagedEVPPKey& pkey) {
3375
3376
CHECK_EQ (this ->key_type_ , kKeyTypePublic );
3376
3377
CHECK (pkey);
3377
3378
this ->asymmetric_key_ = pkey;
3378
3379
}
3379
3380
3380
- void KeyObject ::InitPrivate (const ManagedEVPPKey& pkey) {
3381
+ void KeyObjectHandle ::InitPrivate (const ManagedEVPPKey& pkey) {
3381
3382
CHECK_EQ (this ->key_type_ , kKeyTypePrivate );
3382
3383
CHECK (pkey);
3383
3384
this ->asymmetric_key_ = pkey;
3384
3385
}
3385
3386
3386
- Local<Value> KeyObject ::GetAsymmetricKeyType () const {
3387
+ Local<Value> KeyObjectHandle ::GetAsymmetricKeyType () const {
3387
3388
CHECK_NE (this ->key_type_ , kKeyTypeSecret );
3388
3389
switch (EVP_PKEY_id (this ->asymmetric_key_ .get ())) {
3389
3390
case EVP_PKEY_RSA:
@@ -3409,21 +3410,23 @@ Local<Value> KeyObject::GetAsymmetricKeyType() const {
3409
3410
}
3410
3411
}
3411
3412
3412
- void KeyObject::GetAsymmetricKeyType (const FunctionCallbackInfo<Value>& args) {
3413
- KeyObject* key;
3413
+ void KeyObjectHandle::GetAsymmetricKeyType (
3414
+ const FunctionCallbackInfo<Value>& args) {
3415
+ KeyObjectHandle* key;
3414
3416
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3415
3417
3416
3418
args.GetReturnValue ().Set (key->GetAsymmetricKeyType ());
3417
3419
}
3418
3420
3419
- void KeyObject::GetSymmetricKeySize (const FunctionCallbackInfo<Value>& args) {
3420
- KeyObject* key;
3421
+ void KeyObjectHandle::GetSymmetricKeySize (
3422
+ const FunctionCallbackInfo<Value>& args) {
3423
+ KeyObjectHandle* key;
3421
3424
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3422
3425
args.GetReturnValue ().Set (static_cast <uint32_t >(key->GetSymmetricKeySize ()));
3423
3426
}
3424
3427
3425
- void KeyObject ::Export (const FunctionCallbackInfo<Value>& args) {
3426
- KeyObject * key;
3428
+ void KeyObjectHandle ::Export (const FunctionCallbackInfo<Value>& args) {
3429
+ KeyObjectHandle * key;
3427
3430
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3428
3431
3429
3432
MaybeLocal<Value> result;
@@ -3450,17 +3453,17 @@ void KeyObject::Export(const FunctionCallbackInfo<Value>& args) {
3450
3453
args.GetReturnValue ().Set (result.ToLocalChecked ());
3451
3454
}
3452
3455
3453
- Local<Value> KeyObject ::ExportSecretKey () const {
3456
+ Local<Value> KeyObjectHandle ::ExportSecretKey () const {
3454
3457
return Buffer::Copy (env (), symmetric_key_.get (), symmetric_key_len_)
3455
3458
.ToLocalChecked ();
3456
3459
}
3457
3460
3458
- MaybeLocal<Value> KeyObject ::ExportPublicKey (
3461
+ MaybeLocal<Value> KeyObjectHandle ::ExportPublicKey (
3459
3462
const PublicKeyEncodingConfig& config) const {
3460
3463
return WritePublicKey (env (), asymmetric_key_.get (), config);
3461
3464
}
3462
3465
3463
- MaybeLocal<Value> KeyObject ::ExportPrivateKey (
3466
+ MaybeLocal<Value> KeyObjectHandle ::ExportPrivateKey (
3464
3467
const PrivateKeyEncodingConfig& config) const {
3465
3468
return WritePrivateKey (env (), asymmetric_key_.get (), config);
3466
3469
}
@@ -3663,7 +3666,7 @@ static ByteSource GetSecretKeyBytes(Environment* env, Local<Value> value) {
3663
3666
// in JS to avoid creating an unprotected copy on the heap.
3664
3667
return value->IsString () || Buffer::HasInstance (value) ?
3665
3668
ByteSource::FromStringOrBuffer (env, value) :
3666
- ByteSource::FromSymmetricKeyObject (value);
3669
+ ByteSource::FromSymmetricKeyObjectHandle (value);
3667
3670
}
3668
3671
3669
3672
void CipherBase::InitIv (const FunctionCallbackInfo<Value>& args) {
@@ -6277,7 +6280,8 @@ class GenerateKeyPairJob : public CryptoJob {
6277
6280
if (public_key_encoding_.output_key_object_ ) {
6278
6281
// Note that this has the downside of containing sensitive data of the
6279
6282
// private key.
6280
- if (!KeyObject::Create (env (), kKeyTypePublic , pkey_).ToLocal (pubkey))
6283
+ if (!KeyObjectHandle::Create (env (), kKeyTypePublic , pkey_)
6284
+ .ToLocal (pubkey))
6281
6285
return false ;
6282
6286
} else {
6283
6287
if (!WritePublicKey (env (), pkey_.get (), public_key_encoding_)
@@ -6287,7 +6291,7 @@ class GenerateKeyPairJob : public CryptoJob {
6287
6291
6288
6292
// Now do the same for the private key.
6289
6293
if (private_key_encoding_.output_key_object_ ) {
6290
- if (!KeyObject ::Create (env (), kKeyTypePrivate , pkey_)
6294
+ if (!KeyObjectHandle ::Create (env (), kKeyTypePrivate , pkey_)
6291
6295
.ToLocal (privkey))
6292
6296
return false ;
6293
6297
} else {
@@ -6731,10 +6735,10 @@ void StatelessDiffieHellman(const FunctionCallbackInfo<Value>& args) {
6731
6735
Environment* env = Environment::GetCurrent (args);
6732
6736
6733
6737
CHECK (args[0 ]->IsObject () && args[1 ]->IsObject ());
6734
- KeyObject * our_key_object;
6738
+ KeyObjectHandle * our_key_object;
6735
6739
ASSIGN_OR_RETURN_UNWRAP (&our_key_object, args[0 ].As <Object>());
6736
6740
CHECK_EQ (our_key_object->GetKeyType (), kKeyTypePrivate );
6737
- KeyObject * their_key_object;
6741
+ KeyObjectHandle * their_key_object;
6738
6742
ASSIGN_OR_RETURN_UNWRAP (&their_key_object, args[1 ].As <Object>());
6739
6743
CHECK_NE (their_key_object->GetKeyType (), kKeyTypeSecret );
6740
6744
@@ -6865,7 +6869,8 @@ void Initialize(Local<Object> target,
6865
6869
6866
6870
Environment* env = Environment::GetCurrent (context);
6867
6871
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));
6869
6874
CipherBase::Initialize (env, target);
6870
6875
DiffieHellman::Initialize (env, target);
6871
6876
ECDH::Initialize (env, target);
0 commit comments