@@ -2886,9 +2886,9 @@ ByteSource ByteSource::NullTerminatedCopy(Environment* env,
2886
2886
: FromString (env, value.As <String>(), true );
2887
2887
}
2888
2888
2889
- ByteSource ByteSource::FromSymmetricKeyObject (Local<Value> handle) {
2889
+ ByteSource ByteSource::FromSymmetricKeyObjectHandle (Local<Value> handle) {
2890
2890
CHECK (handle->IsObject ());
2891
- KeyObject * key = Unwrap<KeyObject >(handle.As <Object>());
2891
+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(handle.As <Object>());
2892
2892
CHECK_NOT_NULL (key);
2893
2893
return Foreign (key->GetSymmetricKey (), key->GetSymmetricKeySize ());
2894
2894
}
@@ -3034,7 +3034,7 @@ static ManagedEVPPKey GetPrivateKeyFromJs(
3034
3034
" Failed to read private key" );
3035
3035
} else {
3036
3036
CHECK (args[*offset]->IsObject () && allow_key_object);
3037
- KeyObject * key;
3037
+ KeyObjectHandle * key;
3038
3038
ASSIGN_OR_RETURN_UNWRAP (&key, args[*offset].As <Object>(), ManagedEVPPKey ());
3039
3039
CHECK_EQ (key->GetKeyType (), kKeyTypePrivate );
3040
3040
(*offset) += 4 ;
@@ -3094,7 +3094,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
3094
3094
" Failed to read asymmetric key" );
3095
3095
} else {
3096
3096
CHECK (args[*offset]->IsObject ());
3097
- KeyObject * key = Unwrap<KeyObject >(args[*offset].As <Object>());
3097
+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(args[*offset].As <Object>());
3098
3098
CHECK_NOT_NULL (key);
3099
3099
CHECK_NE (key->GetKeyType (), kKeyTypeSecret );
3100
3100
(*offset) += 4 ;
@@ -3205,10 +3205,11 @@ EVP_PKEY* ManagedEVPPKey::get() const {
3205
3205
return pkey_.get ();
3206
3206
}
3207
3207
3208
- Local<Function> KeyObject::Initialize (Environment* env, Local<Object> target) {
3208
+ Local<Function> KeyObjectHandle::Initialize (Environment* env,
3209
+ Local<Object> target) {
3209
3210
Local<FunctionTemplate> t = env->NewFunctionTemplate (New);
3210
3211
t->InstanceTemplate ()->SetInternalFieldCount (
3211
- KeyObject ::kInternalFieldCount );
3212
+ KeyObjectHandle ::kInternalFieldCount );
3212
3213
t->Inherit (BaseObject::GetConstructorTemplate (env));
3213
3214
3214
3215
env->SetProtoMethod (t, " init" , Init);
@@ -3220,25 +3221,25 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
3220
3221
3221
3222
auto function = t->GetFunction (env->context ()).ToLocalChecked ();
3222
3223
target->Set (env->context (),
3223
- FIXED_ONE_BYTE_STRING (env->isolate (), " KeyObject " ),
3224
+ FIXED_ONE_BYTE_STRING (env->isolate (), " KeyObjectHandle " ),
3224
3225
function).Check ();
3225
3226
3226
3227
return function;
3227
3228
}
3228
3229
3229
- MaybeLocal<Object> KeyObject ::Create (Environment* env,
3230
- KeyType key_type,
3231
- const ManagedEVPPKey& pkey) {
3230
+ MaybeLocal<Object> KeyObjectHandle ::Create (Environment* env,
3231
+ KeyType key_type,
3232
+ const ManagedEVPPKey& pkey) {
3232
3233
CHECK_NE (key_type, kKeyTypeSecret );
3233
3234
Local<Value> type = Integer::New (env->isolate (), key_type);
3234
3235
Local<Object> obj;
3235
- if (!env->crypto_key_object_constructor ()
3236
+ if (!env->crypto_key_object_handle_constructor ()
3236
3237
->NewInstance (env->context (), 1 , &type)
3237
3238
.ToLocal (&obj)) {
3238
3239
return MaybeLocal<Object>();
3239
3240
}
3240
3241
3241
- KeyObject * key = Unwrap<KeyObject >(obj);
3242
+ KeyObjectHandle * key = Unwrap<KeyObjectHandle >(obj);
3242
3243
CHECK_NOT_NULL (key);
3243
3244
if (key_type == kKeyTypePublic )
3244
3245
key->InitPublic (pkey);
@@ -3247,44 +3248,44 @@ MaybeLocal<Object> KeyObject::Create(Environment* env,
3247
3248
return obj;
3248
3249
}
3249
3250
3250
- ManagedEVPPKey KeyObject ::GetAsymmetricKey () const {
3251
+ ManagedEVPPKey KeyObjectHandle ::GetAsymmetricKey () const {
3251
3252
CHECK_NE (key_type_, kKeyTypeSecret );
3252
3253
return this ->asymmetric_key_ ;
3253
3254
}
3254
3255
3255
- const char * KeyObject ::GetSymmetricKey () const {
3256
+ const char * KeyObjectHandle ::GetSymmetricKey () const {
3256
3257
CHECK_EQ (key_type_, kKeyTypeSecret );
3257
3258
return this ->symmetric_key_ .get ();
3258
3259
}
3259
3260
3260
- size_t KeyObject ::GetSymmetricKeySize () const {
3261
+ size_t KeyObjectHandle ::GetSymmetricKeySize () const {
3261
3262
CHECK_EQ (key_type_, kKeyTypeSecret );
3262
3263
return this ->symmetric_key_len_ ;
3263
3264
}
3264
3265
3265
- void KeyObject ::New (const FunctionCallbackInfo<Value>& args) {
3266
+ void KeyObjectHandle ::New (const FunctionCallbackInfo<Value>& args) {
3266
3267
CHECK (args.IsConstructCall ());
3267
3268
CHECK (args[0 ]->IsInt32 ());
3268
3269
KeyType key_type = static_cast <KeyType>(args[0 ].As <Uint32>()->Value ());
3269
3270
Environment* env = Environment::GetCurrent (args);
3270
- new KeyObject (env, args.This (), key_type);
3271
+ new KeyObjectHandle (env, args.This (), key_type);
3271
3272
}
3272
3273
3273
- KeyType KeyObject ::GetKeyType () const {
3274
+ KeyType KeyObjectHandle ::GetKeyType () const {
3274
3275
return this ->key_type_ ;
3275
3276
}
3276
3277
3277
- KeyObject::KeyObject (Environment* env,
3278
- Local<Object> wrap,
3279
- KeyType key_type)
3278
+ KeyObjectHandle::KeyObjectHandle (Environment* env,
3279
+ Local<Object> wrap,
3280
+ KeyType key_type)
3280
3281
: BaseObject(env, wrap),
3281
3282
key_type_ (key_type),
3282
3283
symmetric_key_(nullptr , nullptr ) {
3283
3284
MakeWeak ();
3284
3285
}
3285
3286
3286
- void KeyObject ::Init (const FunctionCallbackInfo<Value>& args) {
3287
- KeyObject * key;
3287
+ void KeyObjectHandle ::Init (const FunctionCallbackInfo<Value>& args) {
3288
+ KeyObjectHandle * key;
3288
3289
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3289
3290
MarkPopErrorOnReturn mark_pop_error_on_return;
3290
3291
@@ -3320,7 +3321,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
3320
3321
}
3321
3322
}
3322
3323
3323
- void KeyObject ::InitSecret (Local<ArrayBufferView> abv) {
3324
+ void KeyObjectHandle ::InitSecret (Local<ArrayBufferView> abv) {
3324
3325
CHECK_EQ (this ->key_type_ , kKeyTypeSecret );
3325
3326
3326
3327
size_t key_len = abv->ByteLength ();
@@ -3333,19 +3334,19 @@ void KeyObject::InitSecret(Local<ArrayBufferView> abv) {
3333
3334
this ->symmetric_key_len_ = key_len;
3334
3335
}
3335
3336
3336
- void KeyObject ::InitPublic (const ManagedEVPPKey& pkey) {
3337
+ void KeyObjectHandle ::InitPublic (const ManagedEVPPKey& pkey) {
3337
3338
CHECK_EQ (this ->key_type_ , kKeyTypePublic );
3338
3339
CHECK (pkey);
3339
3340
this ->asymmetric_key_ = pkey;
3340
3341
}
3341
3342
3342
- void KeyObject ::InitPrivate (const ManagedEVPPKey& pkey) {
3343
+ void KeyObjectHandle ::InitPrivate (const ManagedEVPPKey& pkey) {
3343
3344
CHECK_EQ (this ->key_type_ , kKeyTypePrivate );
3344
3345
CHECK (pkey);
3345
3346
this ->asymmetric_key_ = pkey;
3346
3347
}
3347
3348
3348
- Local<Value> KeyObject ::GetAsymmetricKeyType () const {
3349
+ Local<Value> KeyObjectHandle ::GetAsymmetricKeyType () const {
3349
3350
CHECK_NE (this ->key_type_ , kKeyTypeSecret );
3350
3351
switch (EVP_PKEY_id (this ->asymmetric_key_ .get ())) {
3351
3352
case EVP_PKEY_RSA:
@@ -3371,21 +3372,23 @@ Local<Value> KeyObject::GetAsymmetricKeyType() const {
3371
3372
}
3372
3373
}
3373
3374
3374
- void KeyObject::GetAsymmetricKeyType (const FunctionCallbackInfo<Value>& args) {
3375
- KeyObject* key;
3375
+ void KeyObjectHandle::GetAsymmetricKeyType (
3376
+ const FunctionCallbackInfo<Value>& args) {
3377
+ KeyObjectHandle* key;
3376
3378
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3377
3379
3378
3380
args.GetReturnValue ().Set (key->GetAsymmetricKeyType ());
3379
3381
}
3380
3382
3381
- void KeyObject::GetSymmetricKeySize (const FunctionCallbackInfo<Value>& args) {
3382
- KeyObject* key;
3383
+ void KeyObjectHandle::GetSymmetricKeySize (
3384
+ const FunctionCallbackInfo<Value>& args) {
3385
+ KeyObjectHandle* key;
3383
3386
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3384
3387
args.GetReturnValue ().Set (static_cast <uint32_t >(key->GetSymmetricKeySize ()));
3385
3388
}
3386
3389
3387
- void KeyObject ::Export (const FunctionCallbackInfo<Value>& args) {
3388
- KeyObject * key;
3390
+ void KeyObjectHandle ::Export (const FunctionCallbackInfo<Value>& args) {
3391
+ KeyObjectHandle * key;
3389
3392
ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
3390
3393
3391
3394
MaybeLocal<Value> result;
@@ -3412,17 +3415,17 @@ void KeyObject::Export(const FunctionCallbackInfo<Value>& args) {
3412
3415
args.GetReturnValue ().Set (result.ToLocalChecked ());
3413
3416
}
3414
3417
3415
- Local<Value> KeyObject ::ExportSecretKey () const {
3418
+ Local<Value> KeyObjectHandle ::ExportSecretKey () const {
3416
3419
return Buffer::Copy (env (), symmetric_key_.get (), symmetric_key_len_)
3417
3420
.ToLocalChecked ();
3418
3421
}
3419
3422
3420
- MaybeLocal<Value> KeyObject ::ExportPublicKey (
3423
+ MaybeLocal<Value> KeyObjectHandle ::ExportPublicKey (
3421
3424
const PublicKeyEncodingConfig& config) const {
3422
3425
return WritePublicKey (env (), asymmetric_key_.get (), config);
3423
3426
}
3424
3427
3425
- MaybeLocal<Value> KeyObject ::ExportPrivateKey (
3428
+ MaybeLocal<Value> KeyObjectHandle ::ExportPrivateKey (
3426
3429
const PrivateKeyEncodingConfig& config) const {
3427
3430
return WritePrivateKey (env (), asymmetric_key_.get (), config);
3428
3431
}
@@ -3625,7 +3628,7 @@ static ByteSource GetSecretKeyBytes(Environment* env, Local<Value> value) {
3625
3628
// in JS to avoid creating an unprotected copy on the heap.
3626
3629
return value->IsString () || Buffer::HasInstance (value) ?
3627
3630
ByteSource::FromStringOrBuffer (env, value) :
3628
- ByteSource::FromSymmetricKeyObject (value);
3631
+ ByteSource::FromSymmetricKeyObjectHandle (value);
3629
3632
}
3630
3633
3631
3634
void CipherBase::InitIv (const FunctionCallbackInfo<Value>& args) {
@@ -6287,7 +6290,8 @@ class GenerateKeyPairJob : public CryptoJob {
6287
6290
if (public_key_encoding_.output_key_object_ ) {
6288
6291
// Note that this has the downside of containing sensitive data of the
6289
6292
// private key.
6290
- if (!KeyObject::Create (env (), kKeyTypePublic , pkey_).ToLocal (pubkey))
6293
+ if (!KeyObjectHandle::Create (env (), kKeyTypePublic , pkey_)
6294
+ .ToLocal (pubkey))
6291
6295
return false ;
6292
6296
} else {
6293
6297
if (!WritePublicKey (env (), pkey_.get (), public_key_encoding_)
@@ -6297,7 +6301,7 @@ class GenerateKeyPairJob : public CryptoJob {
6297
6301
6298
6302
// Now do the same for the private key.
6299
6303
if (private_key_encoding_.output_key_object_ ) {
6300
- if (!KeyObject ::Create (env (), kKeyTypePrivate , pkey_)
6304
+ if (!KeyObjectHandle ::Create (env (), kKeyTypePrivate , pkey_)
6301
6305
.ToLocal (privkey))
6302
6306
return false ;
6303
6307
} else {
@@ -6741,10 +6745,10 @@ void StatelessDiffieHellman(const FunctionCallbackInfo<Value>& args) {
6741
6745
Environment* env = Environment::GetCurrent (args);
6742
6746
6743
6747
CHECK (args[0 ]->IsObject () && args[1 ]->IsObject ());
6744
- KeyObject * our_key_object;
6748
+ KeyObjectHandle * our_key_object;
6745
6749
ASSIGN_OR_RETURN_UNWRAP (&our_key_object, args[0 ].As <Object>());
6746
6750
CHECK_EQ (our_key_object->GetKeyType (), kKeyTypePrivate );
6747
- KeyObject * their_key_object;
6751
+ KeyObjectHandle * their_key_object;
6748
6752
ASSIGN_OR_RETURN_UNWRAP (&their_key_object, args[1 ].As <Object>());
6749
6753
CHECK_NE (their_key_object->GetKeyType (), kKeyTypeSecret );
6750
6754
@@ -6895,7 +6899,8 @@ void Initialize(Local<Object> target,
6895
6899
6896
6900
Environment* env = Environment::GetCurrent (context);
6897
6901
SecureContext::Initialize (env, target);
6898
- env->set_crypto_key_object_constructor (KeyObject::Initialize (env, target));
6902
+ env->set_crypto_key_object_handle_constructor (
6903
+ KeyObjectHandle::Initialize (env, target));
6899
6904
CipherBase::Initialize (env, target);
6900
6905
DiffieHellman::Initialize (env, target);
6901
6906
ECDH::Initialize (env, target);
0 commit comments