Revert "crypto: add KeyObject.asymmetricKeySize"
This reverts commit 4895927a0a4372e0699f84657e0a299393a3d281. PR-URL: https://github.com/nodejs/node/pull/26636 Fixes: https://github.com/nodejs/node/issues/26631 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
fe8972a4ff
commit
6f77af541e
@ -1121,15 +1121,6 @@ exposes different functions.
|
||||
Most applications should consider using the new `KeyObject` API instead of
|
||||
passing keys as strings or `Buffer`s due to improved security features.
|
||||
|
||||
### keyObject.asymmetricKeySize
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
* {number}
|
||||
|
||||
For asymmetric keys, this property represents the size of the embedded key in
|
||||
bytes. This property is `undefined` for symmetric keys.
|
||||
|
||||
### keyObject.asymmetricKeyType
|
||||
<!-- YAML
|
||||
added: v11.6.0
|
||||
|
@ -73,15 +73,9 @@ class SecretKeyObject extends KeyObject {
|
||||
}
|
||||
}
|
||||
|
||||
const kAsymmetricKeySize = Symbol('kAsymmetricKeySize');
|
||||
const kAsymmetricKeyType = Symbol('kAsymmetricKeyType');
|
||||
|
||||
class AsymmetricKeyObject extends KeyObject {
|
||||
get asymmetricKeySize() {
|
||||
return this[kAsymmetricKeySize] ||
|
||||
(this[kAsymmetricKeySize] = this[kHandle].getAsymmetricKeySize());
|
||||
}
|
||||
|
||||
get asymmetricKeyType() {
|
||||
return this[kAsymmetricKeyType] ||
|
||||
(this[kAsymmetricKeyType] = this[kHandle].getAsymmetricKeyType());
|
||||
|
@ -3329,8 +3329,6 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
|
||||
t->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
|
||||
env->SetProtoMethod(t, "init", Init);
|
||||
env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeySize",
|
||||
GetAsymmetricKeySize);
|
||||
env->SetProtoMethodNoSideEffect(t, "getSymmetricKeySize",
|
||||
GetSymmetricKeySize);
|
||||
env->SetProtoMethodNoSideEffect(t, "getAsymmetricKeyType",
|
||||
@ -3376,11 +3374,6 @@ const char* KeyObject::GetSymmetricKey() const {
|
||||
return this->symmetric_key_.get();
|
||||
}
|
||||
|
||||
size_t KeyObject::GetAsymmetricKeySize() const {
|
||||
CHECK_NE(key_type_, kKeyTypeSecret);
|
||||
return EVP_PKEY_size(this->asymmetric_key_.get());
|
||||
}
|
||||
|
||||
size_t KeyObject::GetSymmetricKeySize() const {
|
||||
CHECK_EQ(key_type_, kKeyTypeSecret);
|
||||
return this->symmetric_key_len_;
|
||||
@ -3484,12 +3477,6 @@ void KeyObject::GetAsymmetricKeyType(const FunctionCallbackInfo<Value>& args) {
|
||||
args.GetReturnValue().Set(key->GetAsymmetricKeyType());
|
||||
}
|
||||
|
||||
void KeyObject::GetAsymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
|
||||
KeyObject* key;
|
||||
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
|
||||
args.GetReturnValue().Set(static_cast<uint32_t>(key->GetAsymmetricKeySize()));
|
||||
}
|
||||
|
||||
void KeyObject::GetSymmetricKeySize(const FunctionCallbackInfo<Value>& args) {
|
||||
KeyObject* key;
|
||||
ASSIGN_OR_RETURN_UNWRAP(&key, args.Holder());
|
||||
|
@ -456,7 +456,6 @@ class KeyObject : public BaseObject {
|
||||
// only be used to implement cryptograohic operations requiring the key.
|
||||
ManagedEVPPKey GetAsymmetricKey() const;
|
||||
const char* GetSymmetricKey() const;
|
||||
size_t GetAsymmetricKeySize() const;
|
||||
size_t GetSymmetricKeySize() const;
|
||||
|
||||
protected:
|
||||
@ -471,9 +470,6 @@ class KeyObject : public BaseObject {
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
v8::Local<v8::String> GetAsymmetricKeyType() const;
|
||||
|
||||
static void GetAsymmetricKeySize(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
|
||||
static void GetSymmetricKeySize(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
|
||||
|
@ -38,7 +38,6 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
|
||||
const key = createSecretKey(keybuf);
|
||||
assert.strictEqual(key.type, 'secret');
|
||||
assert.strictEqual(key.symmetricKeySize, 32);
|
||||
assert.strictEqual(key.asymmetricKeySize, undefined);
|
||||
assert.strictEqual(key.asymmetricKeyType, undefined);
|
||||
|
||||
const exportedKey = key.export();
|
||||
@ -92,13 +91,11 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
|
||||
const publicKey = createPublicKey(publicPem);
|
||||
assert.strictEqual(publicKey.type, 'public');
|
||||
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
|
||||
assert.strictEqual(publicKey.asymmetricKeySize, 128);
|
||||
assert.strictEqual(publicKey.symmetricKeySize, undefined);
|
||||
|
||||
const privateKey = createPrivateKey(privatePem);
|
||||
assert.strictEqual(privateKey.type, 'private');
|
||||
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
|
||||
assert.strictEqual(privateKey.asymmetricKeySize, 128);
|
||||
assert.strictEqual(privateKey.symmetricKeySize, undefined);
|
||||
|
||||
// It should be possible to derive a public key from a private key.
|
||||
|
@ -108,12 +108,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
|
||||
assert.strictEqual(typeof publicKey, 'object');
|
||||
assert.strictEqual(publicKey.type, 'public');
|
||||
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
|
||||
assert.strictEqual(publicKey.asymmetricKeySize, 64);
|
||||
|
||||
assert.strictEqual(typeof privateKey, 'object');
|
||||
assert.strictEqual(privateKey.type, 'private');
|
||||
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
|
||||
assert.strictEqual(publicKey.asymmetricKeySize, 64);
|
||||
}
|
||||
|
||||
{
|
||||
@ -455,7 +453,6 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
|
||||
assert.strictEqual(typeof publicKey, 'object');
|
||||
assert.strictEqual(publicKey.type, 'public');
|
||||
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
|
||||
assert.strictEqual(publicKey.asymmetricKeySize, 128);
|
||||
|
||||
// The private key should still be a string.
|
||||
assert.strictEqual(typeof privateKey, 'string');
|
||||
@ -480,7 +477,6 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
|
||||
assert.strictEqual(typeof privateKey, 'object');
|
||||
assert.strictEqual(privateKey.type, 'private');
|
||||
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
|
||||
assert.strictEqual(privateKey.asymmetricKeySize, 128);
|
||||
|
||||
testEncryptDecrypt(publicKey, privateKey);
|
||||
testSignVerify(publicKey, privateKey);
|
||||
|
Loading…
x
Reference in New Issue
Block a user