diff options
-rw-r--r-- | src/node_crypto.cc | 35 | ||||
-rw-r--r-- | src/node_crypto.h | 6 |
2 files changed, 21 insertions, 20 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 270f74153a..be6f22a1ac 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3329,15 +3329,18 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) { return function; } -Local<Object> KeyObject::Create(Environment* env, - KeyType key_type, - const ManagedEVPPKey& pkey) { +MaybeLocal<Object> KeyObject::Create(Environment* env, + KeyType key_type, + const ManagedEVPPKey& pkey) { CHECK_NE(key_type, kKeyTypeSecret); Local<Value> type = Integer::New(env->isolate(), key_type); - Local<Object> obj = - env->crypto_key_object_constructor()->NewInstance(env->context(), - 1, &type) - .ToLocalChecked(); + Local<Object> obj; + if (!env->crypto_key_object_constructor() + ->NewInstance(env->context(), 1, &type) + .ToLocal(&obj)) { + return MaybeLocal<Object>(); + } + KeyObject* key = Unwrap<KeyObject>(obj); CHECK(key); if (key_type == kKeyTypePublic) @@ -5825,24 +5828,22 @@ class GenerateKeyPairJob : public CryptoJob { if (public_key_encoding_.output_key_object_) { // Note that this has the downside of containing sensitive data of the // private key. - *pubkey = KeyObject::Create(env, kKeyTypePublic, pkey_); + if (!KeyObject::Create(env, kKeyTypePublic, pkey_).ToLocal(pubkey)) + return false; } else { - MaybeLocal<Value> maybe_pubkey = - WritePublicKey(env, pkey_.get(), public_key_encoding_); - if (maybe_pubkey.IsEmpty()) + if (!WritePublicKey(env, pkey_.get(), public_key_encoding_) + .ToLocal(pubkey)) return false; - *pubkey = maybe_pubkey.ToLocalChecked(); } // Now do the same for the private key. if (private_key_encoding_.output_key_object_) { - *privkey = KeyObject::Create(env, kKeyTypePrivate, pkey_); + if (!KeyObject::Create(env, kKeyTypePrivate, pkey_).ToLocal(privkey)) + return false; } else { - MaybeLocal<Value> maybe_privkey = - WritePrivateKey(env, pkey_.get(), private_key_encoding_); - if (maybe_privkey.IsEmpty()) + if (!WritePrivateKey(env, pkey_.get(), private_key_encoding_) + .ToLocal(privkey)) return false; - *privkey = maybe_privkey.ToLocalChecked(); } return true; diff --git a/src/node_crypto.h b/src/node_crypto.h index 32b6188259..7c346a6c14 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -442,9 +442,9 @@ class KeyObject : public BaseObject { static v8::Local<v8::Function> Initialize(Environment* env, v8::Local<v8::Object> target); - static v8::Local<v8::Object> Create(Environment* env, - KeyType type, - const ManagedEVPPKey& pkey); + static v8::MaybeLocal<v8::Object> Create(Environment* env, + KeyType type, + const ManagedEVPPKey& pkey); // TODO(tniessen): track the memory used by OpenSSL types SET_NO_MEMORY_INFO() |