Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9197882

Browse filesBrowse files
tniessenaddaleax
authored andcommitted
src: rename internal key handles to KeyObjectHandle
PR-URL: #33360 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent dafa380 commit 9197882
Copy full SHA for 9197882

File tree

Expand file treeCollapse file tree

4 files changed

+56
-48
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+56
-48
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/keys.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/keys.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
} = primordials;
77

88
const {
9-
KeyObject: KeyObjectHandle,
9+
KeyObjectHandle,
1010
kKeyTypeSecret,
1111
kKeyTypePublic,
1212
kKeyTypePrivate,
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ constexpr size_t kFsStatsBufferLength =
451451
V(async_hooks_promise_resolve_function, v8::Function) \
452452
V(buffer_prototype_object, v8::Object) \
453453
V(crypto_key_object_constructor, v8::Function) \
454+
V(crypto_key_object_handle_constructor, v8::Function) \
454455
V(domexception_function, v8::Function) \
455456
V(enhance_fatal_stack_after_inspector, v8::Function) \
456457
V(enhance_fatal_stack_before_inspector, v8::Function) \
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+47-42Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,9 +2886,9 @@ ByteSource ByteSource::NullTerminatedCopy(Environment* env,
28862886
: FromString(env, value.As<String>(), true);
28872887
}
28882888

2889-
ByteSource ByteSource::FromSymmetricKeyObject(Local<Value> handle) {
2889+
ByteSource ByteSource::FromSymmetricKeyObjectHandle(Local<Value> handle) {
28902890
CHECK(handle->IsObject());
2891-
KeyObject* key = Unwrap<KeyObject>(handle.As<Object>());
2891+
KeyObjectHandle* key = Unwrap<KeyObjectHandle>(handle.As<Object>());
28922892
CHECK_NOT_NULL(key);
28932893
return Foreign(key->GetSymmetricKey(), key->GetSymmetricKeySize());
28942894
}
@@ -3034,7 +3034,7 @@ static ManagedEVPPKey GetPrivateKeyFromJs(
30343034
"Failed to read private key");
30353035
} else {
30363036
CHECK(args[*offset]->IsObject() && allow_key_object);
3037-
KeyObject* key;
3037+
KeyObjectHandle* key;
30383038
ASSIGN_OR_RETURN_UNWRAP(&key, args[*offset].As<Object>(), ManagedEVPPKey());
30393039
CHECK_EQ(key->GetKeyType(), kKeyTypePrivate);
30403040
(*offset) += 4;
@@ -3094,7 +3094,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
30943094
"Failed to read asymmetric key");
30953095
} else {
30963096
CHECK(args[*offset]->IsObject());
3097-
KeyObject* key = Unwrap<KeyObject>(args[*offset].As<Object>());
3097+
KeyObjectHandle* key = Unwrap<KeyObjectHandle>(args[*offset].As<Object>());
30983098
CHECK_NOT_NULL(key);
30993099
CHECK_NE(key->GetKeyType(), kKeyTypeSecret);
31003100
(*offset) += 4;
@@ -3205,10 +3205,11 @@ EVP_PKEY* ManagedEVPPKey::get() const {
32053205
return pkey_.get();
32063206
}
32073207

3208-
Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
3208+
Local<Function> KeyObjectHandle::Initialize(Environment* env,
3209+
Local<Object> target) {
32093210
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
32103211
t->InstanceTemplate()->SetInternalFieldCount(
3211-
KeyObject::kInternalFieldCount);
3212+
KeyObjectHandle::kInternalFieldCount);
32123213
t->Inherit(BaseObject::GetConstructorTemplate(env));
32133214

32143215
env->SetProtoMethod(t, "init", Init);
@@ -3220,25 +3221,25 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
32203221

32213222
auto function = t->GetFunction(env->context()).ToLocalChecked();
32223223
target->Set(env->context(),
3223-
FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObject"),
3224+
FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"),
32243225
function).Check();
32253226

32263227
return function;
32273228
}
32283229

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) {
32323233
CHECK_NE(key_type, kKeyTypeSecret);
32333234
Local<Value> type = Integer::New(env->isolate(), key_type);
32343235
Local<Object> obj;
3235-
if (!env->crypto_key_object_constructor()
3236+
if (!env->crypto_key_object_handle_constructor()
32363237
->NewInstance(env->context(), 1, &type)
32373238
.ToLocal(&obj)) {
32383239
return MaybeLocal<Object>();
32393240
}
32403241

3241-
KeyObject* key = Unwrap<KeyObject>(obj);
3242+
KeyObjectHandle* key = Unwrap<KeyObjectHandle>(obj);
32423243
CHECK_NOT_NULL(key);
32433244
if (key_type == kKeyTypePublic)
32443245
key->InitPublic(pkey);
@@ -3247,44 +3248,44 @@ MaybeLocal<Object> KeyObject::Create(Environment* env,
32473248
return obj;
32483249
}
32493250

3250-
ManagedEVPPKey KeyObject::GetAsymmetricKey() const {
3251+
ManagedEVPPKey KeyObjectHandle::GetAsymmetricKey() const {
32513252
CHECK_NE(key_type_, kKeyTypeSecret);
32523253
return this->asymmetric_key_;
32533254
}
32543255

3255-
const char* KeyObject::GetSymmetricKey() const {
3256+
const char* KeyObjectHandle::GetSymmetricKey() const {
32563257
CHECK_EQ(key_type_, kKeyTypeSecret);
32573258
return this->symmetric_key_.get();
32583259
}
32593260

3260-
size_t KeyObject::GetSymmetricKeySize() const {
3261+
size_t KeyObjectHandle::GetSymmetricKeySize() const {
32613262
CHECK_EQ(key_type_, kKeyTypeSecret);
32623263
return this->symmetric_key_len_;
32633264
}
32643265

3265-
void KeyObject::New(const FunctionCallbackInfo<Value>& args) {
3266+
void KeyObjectHandle::New(const FunctionCallbackInfo<Value>& args) {
32663267
CHECK(args.IsConstructCall());
32673268
CHECK(args[0]->IsInt32());
32683269
KeyType key_type = static_cast<KeyType>(args[0].As<Uint32>()->Value());
32693270
Environment* env = Environment::GetCurrent(args);
3270-
new KeyObject(env, args.This(), key_type);
3271+
new KeyObjectHandle(env, args.This(), key_type);
32713272
}
32723273

3273-
KeyType KeyObject::GetKeyType() const {
3274+
KeyType KeyObjectHandle::GetKeyType() const {
32743275
return this->key_type_;
32753276
}
32763277

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)
32803281
: BaseObject(env, wrap),
32813282
key_type_(key_type),
32823283
symmetric_key_(nullptr, nullptr) {
32833284
MakeWeak();
32843285
}
32853286

3286-
void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
3287-
KeyObject* key;
3287+
void KeyObjectHandle::Init(const FunctionCallbackInfo<Value>& args) {
3288+
KeyObjectHandle* key;
32883289
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
32893290
MarkPopErrorOnReturn mark_pop_error_on_return;
32903291

@@ -3320,7 +3321,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
33203321
}
33213322
}
33223323

3323-
void KeyObject::InitSecret(Local<ArrayBufferView> abv) {
3324+
void KeyObjectHandle::InitSecret(Local<ArrayBufferView> abv) {
33243325
CHECK_EQ(this->key_type_, kKeyTypeSecret);
33253326

33263327
size_t key_len = abv->ByteLength();
@@ -3333,19 +3334,19 @@ void KeyObject::InitSecret(Local<ArrayBufferView> abv) {
33333334
this->symmetric_key_len_ = key_len;
33343335
}
33353336

3336-
void KeyObject::InitPublic(const ManagedEVPPKey& pkey) {
3337+
void KeyObjectHandle::InitPublic(const ManagedEVPPKey& pkey) {
33373338
CHECK_EQ(this->key_type_, kKeyTypePublic);
33383339
CHECK(pkey);
33393340
this->asymmetric_key_ = pkey;
33403341
}
33413342

3342-
void KeyObject::InitPrivate(const ManagedEVPPKey& pkey) {
3343+
void KeyObjectHandle::InitPrivate(const ManagedEVPPKey& pkey) {
33433344
CHECK_EQ(this->key_type_, kKeyTypePrivate);
33443345
CHECK(pkey);
33453346
this->asymmetric_key_ = pkey;
33463347
}
33473348

3348-
Local<Value> KeyObject::GetAsymmetricKeyType() const {
3349+
Local<Value> KeyObjectHandle::GetAsymmetricKeyType() const {
33493350
CHECK_NE(this->key_type_, kKeyTypeSecret);
33503351
switch (EVP_PKEY_id(this->asymmetric_key_.get())) {
33513352
case EVP_PKEY_RSA:
@@ -3371,21 +3372,23 @@ Local<Value> KeyObject::GetAsymmetricKeyType() const {
33713372
}
33723373
}
33733374

3374-
void KeyObject::GetAsymmetricKeyType(const FunctionCallbackInfo<Value>& args) {
3375-
KeyObject* key;
3375+
void KeyObjectHandle::GetAsymmetricKeyType(
3376+
const FunctionCallbackInfo<Value>& args) {
3377+
KeyObjectHandle* key;
33763378
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
33773379

33783380
args.GetReturnValue().Set(key->GetAsymmetricKeyType());
33793381
}
33803382

3381-
void KeyObject::GetSymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
3382-
KeyObject* key;
3383+
void KeyObjectHandle::GetSymmetricKeySize(
3384+
const FunctionCallbackInfo<Value>& args) {
3385+
KeyObjectHandle* key;
33833386
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
33843387
args.GetReturnValue().Set(static_cast<uint32_t>(key->GetSymmetricKeySize()));
33853388
}
33863389

3387-
void KeyObject::Export(const FunctionCallbackInfo<Value>& args) {
3388-
KeyObject* key;
3390+
void KeyObjectHandle::Export(const FunctionCallbackInfo<Value>& args) {
3391+
KeyObjectHandle* key;
33893392
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
33903393

33913394
MaybeLocal<Value> result;
@@ -3412,17 +3415,17 @@ void KeyObject::Export(const FunctionCallbackInfo<Value>& args) {
34123415
args.GetReturnValue().Set(result.ToLocalChecked());
34133416
}
34143417

3415-
Local<Value> KeyObject::ExportSecretKey() const {
3418+
Local<Value> KeyObjectHandle::ExportSecretKey() const {
34163419
return Buffer::Copy(env(), symmetric_key_.get(), symmetric_key_len_)
34173420
.ToLocalChecked();
34183421
}
34193422

3420-
MaybeLocal<Value> KeyObject::ExportPublicKey(
3423+
MaybeLocal<Value> KeyObjectHandle::ExportPublicKey(
34213424
const PublicKeyEncodingConfig& config) const {
34223425
return WritePublicKey(env(), asymmetric_key_.get(), config);
34233426
}
34243427

3425-
MaybeLocal<Value> KeyObject::ExportPrivateKey(
3428+
MaybeLocal<Value> KeyObjectHandle::ExportPrivateKey(
34263429
const PrivateKeyEncodingConfig& config) const {
34273430
return WritePrivateKey(env(), asymmetric_key_.get(), config);
34283431
}
@@ -3625,7 +3628,7 @@ static ByteSource GetSecretKeyBytes(Environment* env, Local<Value> value) {
36253628
// in JS to avoid creating an unprotected copy on the heap.
36263629
return value->IsString() || Buffer::HasInstance(value) ?
36273630
ByteSource::FromStringOrBuffer(env, value) :
3628-
ByteSource::FromSymmetricKeyObject(value);
3631+
ByteSource::FromSymmetricKeyObjectHandle(value);
36293632
}
36303633

36313634
void CipherBase::InitIv(const FunctionCallbackInfo<Value>& args) {
@@ -6287,7 +6290,8 @@ class GenerateKeyPairJob : public CryptoJob {
62876290
if (public_key_encoding_.output_key_object_) {
62886291
// Note that this has the downside of containing sensitive data of the
62896292
// private key.
6290-
if (!KeyObject::Create(env(), kKeyTypePublic, pkey_).ToLocal(pubkey))
6293+
if (!KeyObjectHandle::Create(env(), kKeyTypePublic, pkey_)
6294+
.ToLocal(pubkey))
62916295
return false;
62926296
} else {
62936297
if (!WritePublicKey(env(), pkey_.get(), public_key_encoding_)
@@ -6297,7 +6301,7 @@ class GenerateKeyPairJob : public CryptoJob {
62976301

62986302
// Now do the same for the private key.
62996303
if (private_key_encoding_.output_key_object_) {
6300-
if (!KeyObject::Create(env(), kKeyTypePrivate, pkey_)
6304+
if (!KeyObjectHandle::Create(env(), kKeyTypePrivate, pkey_)
63016305
.ToLocal(privkey))
63026306
return false;
63036307
} else {
@@ -6741,10 +6745,10 @@ void StatelessDiffieHellman(const FunctionCallbackInfo<Value>& args) {
67416745
Environment* env = Environment::GetCurrent(args);
67426746

67436747
CHECK(args[0]->IsObject() && args[1]->IsObject());
6744-
KeyObject* our_key_object;
6748+
KeyObjectHandle* our_key_object;
67456749
ASSIGN_OR_RETURN_UNWRAP(&our_key_object, args[0].As<Object>());
67466750
CHECK_EQ(our_key_object->GetKeyType(), kKeyTypePrivate);
6747-
KeyObject* their_key_object;
6751+
KeyObjectHandle* their_key_object;
67486752
ASSIGN_OR_RETURN_UNWRAP(&their_key_object, args[1].As<Object>());
67496753
CHECK_NE(their_key_object->GetKeyType(), kKeyTypeSecret);
67506754

@@ -6895,7 +6899,8 @@ void Initialize(Local<Object> target,
68956899

68966900
Environment* env = Environment::GetCurrent(context);
68976901
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));
68996904
CipherBase::Initialize(env, target);
69006905
DiffieHellman::Initialize(env, target);
69016906
ECDH::Initialize(env, target);
Collapse file

‎src/node_crypto.h‎

Copy file name to clipboardExpand all lines: src/node_crypto.h
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class ByteSource {
342342
static ByteSource NullTerminatedCopy(Environment* env,
343343
v8::Local<v8::Value> value);
344344

345-
static ByteSource FromSymmetricKeyObject(v8::Local<v8::Value> handle);
345+
static ByteSource FromSymmetricKeyObjectHandle(v8::Local<v8::Value> handle);
346346

347347
ByteSource(const ByteSource&) = delete;
348348
ByteSource& operator=(const ByteSource&) = delete;
@@ -407,7 +407,7 @@ class ManagedEVPPKey {
407407
EVPKeyPointer pkey_;
408408
};
409409

410-
class KeyObject : public BaseObject {
410+
class KeyObjectHandle : public BaseObject {
411411
public:
412412
static v8::Local<v8::Function> Initialize(Environment* env,
413413
v8::Local<v8::Object> target);
@@ -418,8 +418,8 @@ class KeyObject : public BaseObject {
418418

419419
// TODO(tniessen): track the memory used by OpenSSL types
420420
SET_NO_MEMORY_INFO()
421-
SET_MEMORY_INFO_NAME(KeyObject)
422-
SET_SELF_SIZE(KeyObject)
421+
SET_MEMORY_INFO_NAME(KeyObjectHandle)
422+
SET_SELF_SIZE(KeyObjectHandle)
423423

424424
KeyType GetKeyType() const;
425425

@@ -451,7 +451,9 @@ class KeyObject : public BaseObject {
451451
v8::MaybeLocal<v8::Value> ExportPrivateKey(
452452
const PrivateKeyEncodingConfig& config) const;
453453

454-
KeyObject(Environment* env, v8::Local<v8::Object> wrap, KeyType key_type);
454+
KeyObjectHandle(Environment* env,
455+
v8::Local<v8::Object> wrap,
456+
KeyType key_type);
455457

456458
private:
457459
const KeyType key_type_;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.