@@ -907,6 +907,8 @@ v8::Local<v8::Function> KeyObjectHandle::Initialize(Environment* env) {
907907 isolate, templ, " getSymmetricKeySize" , GetSymmetricKeySize);
908908 SetProtoMethodNoSideEffect (
909909 isolate, templ, " getAsymmetricKeyType" , GetAsymmetricKeyType);
910+ SetProtoMethodNoSideEffect (
911+ isolate, templ, " checkKeyData" , CheckKeyData);
910912 SetProtoMethod (isolate, templ, " export" , Export);
911913 SetProtoMethod (isolate, templ, " exportJwk" , ExportJWK);
912914 SetProtoMethod (isolate, templ, " initECRaw" , InitECRaw);
@@ -926,6 +928,7 @@ void KeyObjectHandle::RegisterExternalReferences(
926928 registry->Register (Init);
927929 registry->Register (GetSymmetricKeySize);
928930 registry->Register (GetAsymmetricKeyType);
931+ registry->Register (CheckKeyData);
929932 registry->Register (Export);
930933 registry->Register (ExportJWK);
931934 registry->Register (InitECRaw);
@@ -1237,6 +1240,46 @@ void KeyObjectHandle::GetAsymmetricKeyType(
12371240 args.GetReturnValue ().Set (key->GetAsymmetricKeyType ());
12381241}
12391242
1243+ int KeyObjectHandle::CheckKeyData () const {
1244+ MarkPopErrorOnReturn mark_pop_error_on_return;
1245+
1246+ const ManagedEVPPKey& key = data_->GetAsymmetricKey ();
1247+ switch (EVP_PKEY_id (key.get ())) {
1248+ case EVP_PKEY_EC: {
1249+ switch (data_->GetKeyType ()) {
1250+ case kKeyTypePublic :
1251+ #if OPENSSL_VERSION_MAJOR >= 3
1252+ return EVP_PKEY_public_check_quick (
1253+ EVP_PKEY_CTX_new (key.get (), nullptr ));
1254+ #else
1255+ return EVP_PKEY_public_check (
1256+ EVP_PKEY_CTX_new (key.get (), nullptr ));
1257+ #endif
1258+ case kKeyTypePrivate :
1259+ #if OPENSSL_VERSION_MAJOR >= 3
1260+ return EVP_PKEY_pairwise_check (
1261+ EVP_PKEY_CTX_new (key.get (), nullptr ));
1262+ #else
1263+ return EVP_PKEY_check (
1264+ EVP_PKEY_CTX_new (key.get (), nullptr ));
1265+ #endif
1266+ default :
1267+ UNREACHABLE ();
1268+ }
1269+ }
1270+ default :
1271+ UNREACHABLE ();
1272+ }
1273+ }
1274+
1275+ void KeyObjectHandle::CheckKeyData (
1276+ const FunctionCallbackInfo<Value>& args) {
1277+ KeyObjectHandle* key;
1278+ ASSIGN_OR_RETURN_UNWRAP (&key, args.Holder ());
1279+
1280+ args.GetReturnValue ().Set (key->CheckKeyData ());
1281+ }
1282+
12401283void KeyObjectHandle::GetSymmetricKeySize (
12411284 const FunctionCallbackInfo<Value>& args) {
12421285 KeyObjectHandle* key;
0 commit comments