Skip to content

Commit 6f77af5

Browse files
committed
Revert "crypto: add KeyObject.asymmetricKeySize"
This reverts commit 4895927. PR-URL: #26636 Fixes: #26631 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent fe8972a commit 6f77af5

File tree

6 files changed

+0
-39
lines changed

6 files changed

+0
-39
lines changed

Diff for: doc/api/crypto.md

-9
Original file line numberDiff line numberDiff line change
@@ -1121,15 +1121,6 @@ exposes different functions.
11211121
Most applications should consider using the new `KeyObject` API instead of
11221122
passing keys as strings or `Buffer`s due to improved security features.
11231123

1124-
### keyObject.asymmetricKeySize
1125-
<!-- YAML
1126-
added: REPLACEME
1127-
-->
1128-
* {number}
1129-
1130-
For asymmetric keys, this property represents the size of the embedded key in
1131-
bytes. This property is `undefined` for symmetric keys.
1132-
11331124
### keyObject.asymmetricKeyType
11341125
<!-- YAML
11351126
added: v11.6.0

Diff for: lib/internal/crypto/keys.js

-6
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,9 @@ class SecretKeyObject extends KeyObject {
7373
}
7474
}
7575

76-
const kAsymmetricKeySize = Symbol('kAsymmetricKeySize');
7776
const kAsymmetricKeyType = Symbol('kAsymmetricKeyType');
7877

7978
class AsymmetricKeyObject extends KeyObject {
80-
get asymmetricKeySize() {
81-
return this[kAsymmetricKeySize] ||
82-
(this[kAsymmetricKeySize] = this[kHandle].getAsymmetricKeySize());
83-
}
84-
8579
get asymmetricKeyType() {
8680
return this[kAsymmetricKeyType] ||
8781
(this[kAsymmetricKeyType] = this[kHandle].getAsymmetricKeyType());

Diff for: src/node_crypto.cc

-13
Original file line numberDiff line numberDiff line change
@@ -3329,8 +3329,6 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
33293329
t->InstanceTemplate()->SetInternalFieldCount(1);
33303330

33313331
env->SetProtoMethod(t, "init", Init);
3332-
env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeySize",
3333-
GetAsymmetricKeySize);
33343332
env->SetProtoMethodNoSideEffect(t, "getSymmetricKeySize",
33353333
GetSymmetricKeySize);
33363334
env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeyType",
@@ -3376,11 +3374,6 @@ const char* KeyObject::GetSymmetricKey() const {
33763374
return this->symmetric_key_.get();
33773375
}
33783376

3379-
size_t KeyObject::GetAsymmetricKeySize() const {
3380-
CHECK_NE(key_type_, kKeyTypeSecret);
3381-
return EVP_PKEY_size(this->asymmetric_key_.get());
3382-
}
3383-
33843377
size_t KeyObject::GetSymmetricKeySize() const {
33853378
CHECK_EQ(key_type_, kKeyTypeSecret);
33863379
return this->symmetric_key_len_;
@@ -3484,12 +3477,6 @@ void KeyObject::GetAsymmetricKeyType(const FunctionCallbackInfo<Value>& args) {
34843477
args.GetReturnValue().Set(key->GetAsymmetricKeyType());
34853478
}
34863479

3487-
void KeyObject::GetAsymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
3488-
KeyObject* key;
3489-
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
3490-
args.GetReturnValue().Set(static_cast<uint32_t>(key->GetAsymmetricKeySize()));
3491-
}
3492-
34933480
void KeyObject::GetSymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
34943481
KeyObject* key;
34953482
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());

Diff for: src/node_crypto.h

-4
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ class KeyObject : public BaseObject {
456456
// only be used to implement cryptograohic operations requiring the key.
457457
ManagedEVPPKey GetAsymmetricKey() const;
458458
const char* GetSymmetricKey() const;
459-
size_t GetAsymmetricKeySize() const;
460459
size_t GetSymmetricKeySize() const;
461460

462461
protected:
@@ -471,9 +470,6 @@ class KeyObject : public BaseObject {
471470
const v8::FunctionCallbackInfo<v8::Value>& args);
472471
v8::Local<v8::String> GetAsymmetricKeyType() const;
473472

474-
static void GetAsymmetricKeySize(
475-
const v8::FunctionCallbackInfo<v8::Value>& args);
476-
477473
static void GetSymmetricKeySize(
478474
const v8::FunctionCallbackInfo<v8::Value>& args);
479475

Diff for: test/parallel/test-crypto-key-objects.js

-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
3838
const key = createSecretKey(keybuf);
3939
assert.strictEqual(key.type, 'secret');
4040
assert.strictEqual(key.symmetricKeySize, 32);
41-
assert.strictEqual(key.asymmetricKeySize, undefined);
4241
assert.strictEqual(key.asymmetricKeyType, undefined);
4342

4443
const exportedKey = key.export();
@@ -92,13 +91,11 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
9291
const publicKey = createPublicKey(publicPem);
9392
assert.strictEqual(publicKey.type, 'public');
9493
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
95-
assert.strictEqual(publicKey.asymmetricKeySize, 128);
9694
assert.strictEqual(publicKey.symmetricKeySize, undefined);
9795

9896
const privateKey = createPrivateKey(privatePem);
9997
assert.strictEqual(privateKey.type, 'private');
10098
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
101-
assert.strictEqual(privateKey.asymmetricKeySize, 128);
10299
assert.strictEqual(privateKey.symmetricKeySize, undefined);
103100

104101
// It should be possible to derive a public key from a private key.

Diff for: test/parallel/test-crypto-keygen.js

-4
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
108108
assert.strictEqual(typeof publicKey, 'object');
109109
assert.strictEqual(publicKey.type, 'public');
110110
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
111-
assert.strictEqual(publicKey.asymmetricKeySize, 64);
112111

113112
assert.strictEqual(typeof privateKey, 'object');
114113
assert.strictEqual(privateKey.type, 'private');
115114
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
116-
assert.strictEqual(publicKey.asymmetricKeySize, 64);
117115
}
118116

119117
{
@@ -455,7 +453,6 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
455453
assert.strictEqual(typeof publicKey, 'object');
456454
assert.strictEqual(publicKey.type, 'public');
457455
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
458-
assert.strictEqual(publicKey.asymmetricKeySize, 128);
459456

460457
// The private key should still be a string.
461458
assert.strictEqual(typeof privateKey, 'string');
@@ -480,7 +477,6 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
480477
assert.strictEqual(typeof privateKey, 'object');
481478
assert.strictEqual(privateKey.type, 'private');
482479
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
483-
assert.strictEqual(privateKey.asymmetricKeySize, 128);
484480

485481
testEncryptDecrypt(publicKey, privateKey);
486482
testSignVerify(publicKey, privateKey);

0 commit comments

Comments
 (0)