From ab1327f91426af893fc9de51c6f88ac2da8b5d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 5 Mar 2019 17:55:14 +0100 Subject: [PATCH] crypto: simplify GetPublicOrPrivateKeyFromJs PR-URL: https://github.com/nodejs/node/pull/26454 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Masashi Hirano --- src/node_crypto.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index d73dbe46f7cc8f..f172990a7d32db 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3123,8 +3123,7 @@ static ManagedEVPPKey GetPrivateKeyFromJs( static ManagedEVPPKey GetPublicOrPrivateKeyFromJs( const FunctionCallbackInfo& args, - unsigned int* offset, - bool allow_key_object) { + unsigned int* offset) { if (args[*offset]->IsString() || Buffer::HasInstance(args[*offset])) { Environment* env = Environment::GetCurrent(args); ByteSource data = ByteSource::FromStringOrBuffer(env, args[(*offset)++]); @@ -3172,7 +3171,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs( ThrowCryptoError(env, ERR_get_error(), "Failed to read asymmetric key"); return ManagedEVPPKey(pkey.release()); } else { - CHECK(args[*offset]->IsObject() && allow_key_object); + CHECK(args[*offset]->IsObject()); KeyObject* key = Unwrap(args[*offset].As()); CHECK(key); CHECK_NE(key->GetKeyType(), kKeyTypeSecret); @@ -3389,7 +3388,7 @@ void KeyObject::Init(const FunctionCallbackInfo& args) { CHECK_EQ(args.Length(), 3); offset = 0; - pkey = GetPublicOrPrivateKeyFromJs(args, &offset, false); + pkey = GetPublicOrPrivateKeyFromJs(args, &offset); if (!pkey) return; key->InitPublic(pkey); @@ -4662,7 +4661,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&verify, args.Holder()); unsigned int offset = 0; - ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs(args, &offset, true); + ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs(args, &offset); if (!pkey) return; @@ -4725,7 +4724,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); unsigned int offset = 0; - ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs(args, &offset, true); + ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs(args, &offset); if (!pkey) return;