@@ -3012,30 +3012,6 @@ static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
30123012 return result;
30133013}
30143014
3015- static ManagedEVPPKey GetPublicKeyFromJs (
3016- const FunctionCallbackInfo<Value>& args,
3017- unsigned int * offset,
3018- bool allow_key_object) {
3019- if (args[*offset]->IsString () || Buffer::HasInstance (args[*offset])) {
3020- Environment* env = Environment::GetCurrent (args);
3021- ByteSource key = ByteSource::FromStringOrBuffer (env, args[(*offset)++]);
3022- PublicKeyEncodingConfig config =
3023- GetPublicKeyEncodingFromJs (args, offset, kKeyContextInput );
3024- EVPKeyPointer pkey;
3025- ParsePublicKey (&pkey, config, key.get (), key.size ());
3026- if (!pkey)
3027- ThrowCryptoError (env, ERR_get_error (), " Failed to read public key" );
3028- return ManagedEVPPKey (pkey.release ());
3029- } else {
3030- CHECK (args[*offset]->IsObject () && allow_key_object);
3031- KeyObject* key;
3032- ASSIGN_OR_RETURN_UNWRAP (&key, args[*offset].As <Object>(), ManagedEVPPKey ());
3033- CHECK_EQ (key->GetKeyType (), kKeyTypePublic );
3034- (*offset) += 3 ;
3035- return key->GetAsymmetricKey ();
3036- }
3037- }
3038-
30393015static NonCopyableMaybe<PrivateKeyEncodingConfig> GetPrivateKeyEncodingFromJs (
30403016 const FunctionCallbackInfo<Value>& args,
30413017 unsigned int * offset,
@@ -3397,7 +3373,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
33973373 CHECK_EQ (args.Length (), 3 );
33983374
33993375 offset = 0 ;
3400- pkey = GetPublicKeyFromJs (args, &offset, false );
3376+ pkey = GetPublicOrPrivateKeyFromJs (args, &offset, false );
34013377 if (!pkey)
34023378 return ;
34033379 key->InitPublic (pkey);
@@ -4679,7 +4655,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
46794655 ASSIGN_OR_RETURN_UNWRAP (&verify, args.Holder ());
46804656
46814657 unsigned int offset = 0 ;
4682- ManagedEVPPKey pkey = GetPublicKeyFromJs (args, &offset, true );
4658+ ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs (args, &offset, true );
46834659
46844660 char * hbuf = Buffer::Data (args[offset]);
46854661 ssize_t hlen = Buffer::Length (args[offset]);
0 commit comments