diff --git a/src/crypto/crypto_keygen.h b/src/crypto/crypto_keygen.h index 01407de83c7b14..b0743efb38ddce 100644 --- a/src/crypto/crypto_keygen.h +++ b/src/crypto/crypto_keygen.h @@ -186,16 +186,12 @@ struct KeyPairGenTraits final { AdditionalParameters* params, v8::Local* result) { v8::Local keys[2]; - if (ManagedEVPPKey::ToEncodedPublicKey( - env, - std::move(params->key), - params->public_key_encoding, - &keys[0]).IsNothing() || - ManagedEVPPKey::ToEncodedPrivateKey( - env, - std::move(params->key), - params->private_key_encoding, - &keys[1]).IsNothing()) { + if (params->key + .ToEncodedPublicKey(env, params->public_key_encoding, &keys[0]) + .IsNothing() || + params->key + .ToEncodedPrivateKey(env, params->private_key_encoding, &keys[1]) + .IsNothing()) { return v8::Nothing(); } *result = v8::Array::New(env->isolate(), keys, arraysize(keys)); diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index 00543cd380980c..7ef924d88fdca0 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -633,44 +633,42 @@ Maybe ExportJWKInner(Environment* env, Maybe ManagedEVPPKey::ToEncodedPublicKey( Environment* env, - ManagedEVPPKey key, const PublicKeyEncodingConfig& config, Local* out) { - if (!key) return Nothing(); + if (!*this) return Nothing(); if (config.output_key_object_) { // Note that this has the downside of containing sensitive data of the // private key. std::shared_ptr data = - KeyObjectData::CreateAsymmetric(kKeyTypePublic, std::move(key)); + KeyObjectData::CreateAsymmetric(kKeyTypePublic, *this); return Tristate(KeyObjectHandle::Create(env, data).ToLocal(out)); } else if (config.format_ == kKeyFormatJWK) { std::shared_ptr data = - KeyObjectData::CreateAsymmetric(kKeyTypePublic, std::move(key)); + KeyObjectData::CreateAsymmetric(kKeyTypePublic, *this); *out = Object::New(env->isolate()); return ExportJWKInner(env, data, *out, false); } - return Tristate(WritePublicKey(env, key.get(), config).ToLocal(out)); + return Tristate(WritePublicKey(env, get(), config).ToLocal(out)); } Maybe ManagedEVPPKey::ToEncodedPrivateKey( Environment* env, - ManagedEVPPKey key, const PrivateKeyEncodingConfig& config, Local* out) { - if (!key) return Nothing(); + if (!*this) return Nothing(); if (config.output_key_object_) { std::shared_ptr data = - KeyObjectData::CreateAsymmetric(kKeyTypePrivate, std::move(key)); + KeyObjectData::CreateAsymmetric(kKeyTypePrivate, *this); return Tristate(KeyObjectHandle::Create(env, data).ToLocal(out)); } else if (config.format_ == kKeyFormatJWK) { std::shared_ptr data = - KeyObjectData::CreateAsymmetric(kKeyTypePrivate, std::move(key)); + KeyObjectData::CreateAsymmetric(kKeyTypePrivate, *this); *out = Object::New(env->isolate()); return ExportJWKInner(env, data, *out, false); } - return Tristate(WritePrivateKey(env, key.get(), config).ToLocal(out)); + return Tristate(WritePrivateKey(env, get(), config).ToLocal(out)); } NonCopyableMaybe diff --git a/src/crypto/crypto_keys.h b/src/crypto/crypto_keys.h index d06565d8ad74a3..3889f3f321da45 100644 --- a/src/crypto/crypto_keys.h +++ b/src/crypto/crypto_keys.h @@ -112,17 +112,13 @@ class ManagedEVPPKey : public MemoryRetainer { unsigned int* offset, bool allow_key_object); - static v8::Maybe ToEncodedPublicKey( - Environment* env, - ManagedEVPPKey key, - const PublicKeyEncodingConfig& config, - v8::Local* out); + v8::Maybe ToEncodedPublicKey(Environment* env, + const PublicKeyEncodingConfig& config, + v8::Local* out); - static v8::Maybe ToEncodedPrivateKey( - Environment* env, - ManagedEVPPKey key, - const PrivateKeyEncodingConfig& config, - v8::Local* out); + v8::Maybe ToEncodedPrivateKey(Environment* env, + const PrivateKeyEncodingConfig& config, + v8::Local* out); private: size_t size_of_private_key() const;