!6 优化napi代码

Merge pull request !6 from 胡一奇/master
This commit is contained in:
openharmony_ci 2023-05-22 06:32:25 +00:00 committed by Gitee
commit c1461fa7f7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 45 additions and 5 deletions

View File

@ -289,6 +289,7 @@ napi_value NapiX509Certificate::GetPublicKey(napi_env env, napi_callback_info in
NapiPubKey *pubKeyClass = new (std::nothrow) NapiPubKey(returnPubKey);
if (pubKeyClass == nullptr) {
napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Failed to create a pubkey class"));
LOGE("create for x509 cert's public key obj failed");
CfObjDestroy(returnPubKey);
return nullptr;
@ -935,7 +936,19 @@ void NapiX509Certificate::CreateX509CertComplete(napi_env env, napi_status statu
return;
}
napi_value instance = CreateX509Cert(env);
NapiX509Certificate *x509CertClass = new NapiX509Certificate(context->cert, context->object);
NapiX509Certificate *x509CertClass = new (std::nothrow) NapiX509Certificate(context->cert, context->object);
if (x509CertClass == nullptr) {
context->errCode = CF_ERR_MALLOC;
context->errMsg = "Failed to create x509Cert class";
LOGE("Failed to create x509Cert class");
CfObjDestroy(context->cert);
if (context->object != nullptr) {
context->object->destroy(&(context->object));
}
ReturnResult(env, context, nullptr);
FreeCryptoFwkCtx(context);
return;
}
napi_wrap(
env, instance, x509CertClass,
[](napi_env env, void *data, void *hint) {

View File

@ -236,7 +236,13 @@ static napi_value GenerateCrlEntryArray(napi_env env, CfArray *array)
CfBlob *blob = reinterpret_cast<CfBlob *>(array->data + i);
HcfX509CrlEntry *entry = reinterpret_cast<HcfX509CrlEntry *>(blob->data);
napi_value instance = NapiX509CrlEntry::CreateX509CrlEntry(env);
NapiX509CrlEntry *x509CrlEntryClass = new NapiX509CrlEntry(entry);
NapiX509CrlEntry *x509CrlEntryClass = new (std::nothrow) NapiX509CrlEntry(entry);
if (x509CrlEntryClass == nullptr) {
napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Failed to create a x509CrlEntry class"));
LOGE("Failed to create a x509CrlEntry class");
CfObjDestroy(entry);
return nullptr; /* the C++ objects wrapped will be automatically released by scope manager. */
}
napi_wrap(
env, instance, x509CrlEntryClass,
[](napi_env env, void *data, void *hint) {
@ -484,7 +490,13 @@ napi_value NapiX509Crl::GetRevokedCertificate(napi_env env, napi_callback_info i
return nullptr;
}
napi_value instance = NapiX509CrlEntry::CreateX509CrlEntry(env);
NapiX509CrlEntry *x509CrlEntryClass = new NapiX509CrlEntry(crlEntry);
NapiX509CrlEntry *x509CrlEntryClass = new (std::nothrow) NapiX509CrlEntry(crlEntry);
if (x509CrlEntryClass == nullptr) {
napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Failed to create a x509CrlEntry class"));
LOGE("Failed to create a x509CrlEntry class");
CfObjDestroy(crlEntry);
return nullptr;
}
napi_wrap(
env, instance, x509CrlEntryClass,
[](napi_env env, void *data, void *hint) {
@ -525,7 +537,13 @@ napi_value NapiX509Crl::GetRevokedCertificateWithCert(napi_env env, napi_callbac
}
napi_value instance = NapiX509CrlEntry::CreateX509CrlEntry(env);
NapiX509CrlEntry *x509CrlEntryClass = new NapiX509CrlEntry(crlEntry);
NapiX509CrlEntry *x509CrlEntryClass = new (std::nothrow) NapiX509CrlEntry(crlEntry);
if (x509CrlEntryClass == nullptr) {
napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Failed to create a x509CrlEntry class"));
LOGE("Failed to create a x509CrlEntry class");
CfObjDestroy(crlEntry);
return nullptr;
}
napi_wrap(
env, instance, x509CrlEntryClass,
[](napi_env env, void *data, void *hint) {
@ -920,7 +938,16 @@ void NapiX509Crl::CreateX509CrlComplete(napi_env env, napi_status status, void *
return;
}
napi_value instance = CreateX509Crl(env);
NapiX509Crl *x509CrlClass = new NapiX509Crl(context->crl);
NapiX509Crl *x509CrlClass = new (std::nothrow) NapiX509Crl(context->crl);
if (x509CrlClass == nullptr) {
context->errCode = CF_ERR_MALLOC;
context->errMsg = "Failed to create a x509Crl class";
LOGE("Failed to create a x509Crl class");
CfObjDestroy(context->crl);
ReturnResult(env, context, nullptr);
FreeCryptoFwkCtx(context);
return;
}
napi_wrap(
env, instance, x509CrlClass,
[](napi_env env, void *data, void *hint) {