Skip to content

Commit

Permalink
crypto: simplify GetPublicOrPrivateKeyFromJs
Browse files Browse the repository at this point in the history
PR-URL: nodejs#26454
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Masashi Hirano <[email protected]>
  • Loading branch information
tniessen authored and BridgeAR committed Mar 12, 2019
1 parent 8c087d2 commit ab1327f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3123,8 +3123,7 @@ static ManagedEVPPKey GetPrivateKeyFromJs(

static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
const FunctionCallbackInfo<Value>& 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)++]);
Expand Down Expand Up @@ -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<KeyObject>(args[*offset].As<Object>());
CHECK(key);
CHECK_NE(key->GetKeyType(), kKeyTypeSecret);
Expand Down Expand Up @@ -3389,7 +3388,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(args.Length(), 3);

offset = 0;
pkey = GetPublicOrPrivateKeyFromJs(args, &offset, false);
pkey = GetPublicOrPrivateKeyFromJs(args, &offset);
if (!pkey)
return;
key->InitPublic(pkey);
Expand Down Expand Up @@ -4662,7 +4661,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& 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;

Expand Down Expand Up @@ -4725,7 +4724,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

unsigned int offset = 0;
ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs(args, &offset, true);
ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs(args, &offset);
if (!pkey)
return;

Expand Down

0 comments on commit ab1327f

Please sign in to comment.