1 /*
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "napi_cert_crl_collection.h"
17
18 #include "cf_log.h"
19 #include "cf_memory.h"
20 #include "cf_object_base.h"
21 #include "cf_result.h"
22 #include "config.h"
23 #include "napi/native_api.h"
24 #include "napi/native_common.h"
25 #include "napi_common.h"
26 #include "napi_cert_defines.h"
27 #include "napi_cert_utils.h"
28 #include "napi_pub_key.h"
29 #include "napi_x509_certificate.h"
30 #include "napi_x509_crl.h"
31 #include "napi_x509_cert_match_parameters.h"
32 #include "napi_x509_crl_match_parameters.h"
33 #include "napi_cert_crl_common.h"
34 #include "securec.h"
35 #include "utils.h"
36
37 namespace OHOS {
38 namespace CertFramework {
39 thread_local napi_ref NapiCertCRLCollection::classRef_ = nullptr;
40
41 struct CfCertCRLColCtx {
42 AsyncType asyncType = ASYNC_TYPE_CALLBACK;
43 napi_value promise = nullptr;
44 napi_ref callback = nullptr;
45 napi_deferred deferred = nullptr;
46 napi_async_work asyncWork = nullptr;
47 napi_ref cfCertCRLCollectionRef = nullptr;
48 napi_ref certMatchParamsRef = nullptr;
49 napi_ref crlMatchParamsRef = nullptr;
50 CfResult errCode = CF_SUCCESS;
51 const char *errMsg = nullptr;
52
53 NapiCertCRLCollection *certCRLColClass = nullptr;
54 HcfX509CertMatchParams *certMatchParam = nullptr;
55 HcfX509CrlMatchParams *crlMatchParam = nullptr;
56 HcfX509CertificateArray retCerts { nullptr, 0 };
57 HcfX509CrlArray retCrls { nullptr, 0 };
58 };
59
FreeCryptoFwkCtx(napi_env env,CfCertCRLColCtx * & context)60 static void FreeCryptoFwkCtx(napi_env env, CfCertCRLColCtx *&context)
61 {
62 if (context == nullptr) {
63 return;
64 }
65
66 if (context->asyncWork != nullptr) {
67 napi_delete_async_work(env, context->asyncWork);
68 }
69
70 if (context->callback != nullptr) {
71 napi_delete_reference(env, context->callback);
72 }
73
74 if (context->cfCertCRLCollectionRef != nullptr) {
75 napi_delete_reference(env, context->cfCertCRLCollectionRef);
76 context->cfCertCRLCollectionRef = nullptr;
77 }
78 if (context->certMatchParamsRef != nullptr) {
79 napi_delete_reference(env, context->certMatchParamsRef);
80 context->certMatchParamsRef = nullptr;
81 }
82 if (context->crlMatchParamsRef != nullptr) {
83 napi_delete_reference(env, context->crlMatchParamsRef);
84 context->crlMatchParamsRef = nullptr;
85 }
86
87 if (context->certMatchParam != nullptr) {
88 FreeX509CertMatchParams(context->certMatchParam);
89 }
90 if (context->crlMatchParam != nullptr) {
91 FreeX509CrlMatchParams(context->crlMatchParam);
92 }
93 CF_FREE_PTR(context->retCerts.data);
94 context->retCerts.count = 0;
95 CF_FREE_PTR(context->retCrls.data);
96 context->retCrls.count = 0;
97
98 CF_FREE_PTR(context);
99 }
100
ReturnCallbackResult(napi_env env,CfCertCRLColCtx * context,napi_value result)101 static void ReturnCallbackResult(napi_env env, CfCertCRLColCtx *context, napi_value result)
102 {
103 napi_value businessError = nullptr;
104 if (context->errCode != CF_SUCCESS) {
105 businessError = CertGenerateBusinessError(env, context->errCode, context->errMsg);
106 }
107 napi_value params[ARGS_SIZE_TWO] = { businessError, result };
108
109 napi_value func = nullptr;
110 napi_get_reference_value(env, context->callback, &func);
111
112 napi_value recv = nullptr;
113 napi_value callFuncRet = nullptr;
114 napi_get_undefined(env, &recv);
115 napi_call_function(env, recv, func, ARGS_SIZE_TWO, params, &callFuncRet);
116 }
117
ReturnPromiseResult(napi_env env,CfCertCRLColCtx * context,napi_value result)118 static void ReturnPromiseResult(napi_env env, CfCertCRLColCtx *context, napi_value result)
119 {
120 if (context->errCode == CF_SUCCESS) {
121 napi_resolve_deferred(env, context->deferred, result);
122 } else {
123 napi_reject_deferred(env, context->deferred, CertGenerateBusinessError(env, context->errCode, context->errMsg));
124 }
125 }
126
ReturnResult(napi_env env,CfCertCRLColCtx * context,napi_value result)127 static void ReturnResult(napi_env env, CfCertCRLColCtx *context, napi_value result)
128 {
129 if (context->asyncType == ASYNC_TYPE_CALLBACK) {
130 ReturnCallbackResult(env, context, result);
131 } else {
132 ReturnPromiseResult(env, context, result);
133 }
134 }
135
CreateCallbackAndPromise(napi_env env,CfCertCRLColCtx * context,size_t argc,size_t maxCount,napi_value callbackValue)136 static bool CreateCallbackAndPromise(
137 napi_env env, CfCertCRLColCtx *context, size_t argc, size_t maxCount, napi_value callbackValue)
138 {
139 context->asyncType = GetAsyncType(env, argc, maxCount, callbackValue);
140 if (context->asyncType == ASYNC_TYPE_CALLBACK) {
141 if (!CertGetCallbackFromJSParams(env, callbackValue, &context->callback)) {
142 LOGE("CerCRLColletion: get callback failed!");
143 return false;
144 }
145 } else {
146 if (napi_create_promise(env, &context->deferred, &context->promise) != napi_ok) {
147 return false;
148 }
149 }
150 return true;
151 }
152
NapiCertCRLCollection(HcfCertCrlCollection * collection)153 NapiCertCRLCollection::NapiCertCRLCollection(HcfCertCrlCollection *collection)
154 {
155 certCrlCollection_ = collection;
156 }
157
~NapiCertCRLCollection()158 NapiCertCRLCollection::~NapiCertCRLCollection()
159 {
160 CfObjDestroy(this->certCrlCollection_);
161 }
162
SelectCRLsRet(napi_env env,const HcfX509CrlArray * crls)163 napi_value NapiCertCRLCollection::SelectCRLsRet(napi_env env, const HcfX509CrlArray *crls)
164 {
165 napi_value instance;
166 napi_create_array(env, &instance);
167 if (instance == nullptr) {
168 LOGE("create return array failed!");
169 return nullptr;
170 }
171 if (crls == nullptr) {
172 LOGI("return emtpy erray!");
173 return instance;
174 }
175 int j = 0;
176 for (uint32_t i = 0; i < crls->count; ++i) {
177 HcfX509Crl *crl = crls->data[i];
178 NapiX509Crl *x509Crl = new (std::nothrow) NapiX509Crl(crl);
179 if (x509Crl == nullptr) {
180 LOGE("new x509Crl failed!");
181 continue;
182 }
183 napi_value element = NapiX509Crl::CreateX509Crl(env, "createX509CRL");
184 napi_wrap(
185 env, element, x509Crl,
186 [](napi_env env, void *data, void *hint) {
187 NapiX509Crl *crl = static_cast<NapiX509Crl *>(data);
188 delete crl;
189 return;
190 },
191 nullptr, nullptr);
192 napi_set_element(env, instance, j++, element);
193 crls->data[i] = nullptr;
194 }
195 return instance;
196 }
197
SelectCertsExecute(napi_env env,void * data)198 static void SelectCertsExecute(napi_env env, void *data)
199 {
200 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
201 NapiCertCRLCollection *certCrlCol = context->certCRLColClass;
202 HcfCertCrlCollection *collection = certCrlCol->GetCertCrlCollection();
203 CfResult res = collection->selectCerts(collection, context->certMatchParam, &context->retCerts);
204 if (res != CF_SUCCESS) {
205 LOGE("selectCerts failed!");
206 context->errCode = res;
207 context->errMsg = "selectCerts failed!";
208 }
209 }
210
SelectCertsComplete(napi_env env,napi_status status,void * data)211 static void SelectCertsComplete(napi_env env, napi_status status, void *data)
212 {
213 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
214 if (context->errCode != CF_SUCCESS) {
215 ReturnResult(env, context, nullptr);
216 FreeCryptoFwkCtx(env, context);
217 return;
218 }
219 napi_value instance = ConvertCertArrToNapiValue(env, &context->retCerts);
220 ReturnResult(env, context, instance);
221 for (uint32_t i = 0; i < context->retCerts.count; ++i) {
222 CfObjDestroy(context->retCerts.data[i]);
223 }
224 FreeCryptoFwkCtx(env, context);
225 }
226
NapiSelectCerts(napi_env env,napi_callback_info info)227 static napi_value NapiSelectCerts(napi_env env, napi_callback_info info)
228 {
229 napi_value thisVar = nullptr;
230 napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
231 if (thisVar == nullptr) {
232 LOGE("thisVar is nullptr");
233 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "thisVar is nullptr."));
234 return nullptr;
235 }
236 NapiCertCRLCollection *certCrlCol = nullptr;
237 napi_unwrap(env, thisVar, reinterpret_cast<void **>(&certCrlCol));
238 if (certCrlCol == nullptr) {
239 LOGE("certCrlCol is nullptr!");
240 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "certCrlCol is nullptr."));
241 return nullptr;
242 }
243 return certCrlCol->SelectCerts(env, info);
244 }
245
GetCertMatchParams(napi_env env,napi_value arg,CfCertCRLColCtx * context)246 static bool GetCertMatchParams(napi_env env, napi_value arg, CfCertCRLColCtx *context)
247 {
248 HcfX509CertMatchParams *param = static_cast<HcfX509CertMatchParams *>(CfMalloc(sizeof(HcfX509CertMatchParams), 0));
249 if (param == nullptr) {
250 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Malloc matchParams failed"));
251 LOGE("malloc matchParams failed!");
252 return false;
253 }
254 if (!BuildX509CertMatchParams(env, arg, param)) {
255 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Build X509 cert match params failed"));
256 LOGE("build X509 cert match params failed!");
257 FreeX509CertMatchParams(param);
258 return false;
259 }
260 context->certMatchParam = param;
261 return true;
262 }
263
SelectCerts(napi_env env,napi_callback_info info)264 napi_value NapiCertCRLCollection::SelectCerts(napi_env env, napi_callback_info info)
265 {
266 size_t argc = ARGS_SIZE_TWO;
267 napi_value argv[ARGS_SIZE_TWO] = { nullptr };
268 napi_value thisVar = nullptr;
269 napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr);
270
271 if (!CertCheckArgsCount(env, argc, ARGS_SIZE_TWO, false)) {
272 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "CertCheckArgsCount failed."));
273 LOGE("CertCheckArgsCount is not 2!");
274 return nullptr;
275 }
276
277 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(CfMalloc(sizeof(CfCertCRLColCtx), 0));
278 if (context == nullptr) {
279 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "malloc context failed"));
280 LOGE("malloc context failed!");
281 return nullptr;
282 }
283 context->certCRLColClass = this;
284
285 if (!GetCertMatchParams(env, argv[PARAM0], context)) {
286 CfFree(context);
287 return nullptr;
288 }
289
290 if (napi_create_reference(env, thisVar, 1, &context->cfCertCRLCollectionRef) != napi_ok) {
291 LOGE("create reference failed!");
292 FreeCryptoFwkCtx(env, context);
293 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create reference failed"));
294 return nullptr;
295 }
296 if (napi_create_reference(env, argv[PARAM0], 1, &context->certMatchParamsRef) != napi_ok) {
297 LOGE("create param ref failed!");
298 FreeCryptoFwkCtx(env, context);
299 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create param ref failed"));
300 return nullptr;
301 }
302 if (!CreateCallbackAndPromise(env, context, argc, ARGS_SIZE_TWO, argv[PARAM1])) {
303 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "CreateCallbackAndPromise failed"));
304 LOGE("CreateCallbackAndPromise failed!");
305 FreeCryptoFwkCtx(env, context);
306 return nullptr;
307 }
308 napi_create_async_work(env, nullptr, CertGetResourceName(env, "SelectCerts"), SelectCertsExecute,
309 SelectCertsComplete, static_cast<void *>(context), &context->asyncWork);
310
311 napi_queue_async_work(env, context->asyncWork);
312 if (context->asyncType == ASYNC_TYPE_PROMISE) {
313 return context->promise;
314 }
315
316 return CertNapiGetNull(env);
317 }
318
NapiSelectCRLs(napi_env env,napi_callback_info info)319 static napi_value NapiSelectCRLs(napi_env env, napi_callback_info info)
320 {
321 napi_value thisVar = nullptr;
322 napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
323 if (thisVar == nullptr) {
324 LOGE("thisVar is nullptr");
325 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "thisVar is nullptr."));
326 return nullptr;
327 }
328 NapiCertCRLCollection *certCrlCol = nullptr;
329 napi_unwrap(env, thisVar, reinterpret_cast<void **>(&certCrlCol));
330 if (certCrlCol == nullptr) {
331 LOGE("certCrlCol is nullptr!");
332 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "certCrlCol is nullptr."));
333 return nullptr;
334 }
335 return certCrlCol->SelectCRLs(env, info);
336 }
337
SelectCRLExecute(napi_env env,void * data)338 static void SelectCRLExecute(napi_env env, void *data)
339 {
340 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
341 NapiCertCRLCollection *certCrlCol = context->certCRLColClass;
342 HcfCertCrlCollection *collection = certCrlCol->GetCertCrlCollection();
343 CfResult res = collection->selectCRLs(collection, context->crlMatchParam, &context->retCrls);
344 if (res != CF_SUCCESS) {
345 LOGE("selectCrls failed!");
346 context->errCode = res;
347 context->errMsg = "selectCrls failed!";
348 }
349 }
350
SelectCRLComplete(napi_env env,napi_status status,void * data)351 static void SelectCRLComplete(napi_env env, napi_status status, void *data)
352 {
353 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
354 if (context->errCode != CF_SUCCESS) {
355 ReturnResult(env, context, nullptr);
356 FreeCryptoFwkCtx(env, context);
357 return;
358 }
359 NapiCertCRLCollection *certCrlCol = context->certCRLColClass;
360 napi_value instance = certCrlCol->SelectCRLsRet(env, &context->retCrls);
361 for (uint32_t i = 0; i < context->retCrls.count; ++i) {
362 CfObjDestroy(context->retCrls.data[i]);
363 }
364 ReturnResult(env, context, instance);
365 FreeCryptoFwkCtx(env, context);
366 }
367
GetCrlMatchParam(napi_env env,napi_value arg,CfCertCRLColCtx * context)368 static bool GetCrlMatchParam(napi_env env, napi_value arg, CfCertCRLColCtx *context)
369 {
370 HcfX509CrlMatchParams *param = static_cast<HcfX509CrlMatchParams *>(CfMalloc(sizeof(HcfX509CrlMatchParams), 0));
371 if (param == nullptr) {
372 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Malloc matchParams failed"));
373 LOGE("malloc matchParams failed!");
374 return false;
375 }
376 if (!BuildX509CrlMatchParams(env, arg, param)) {
377 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Build X509 crl match params failed"));
378 LOGE("build X509 crl match params failed!");
379 FreeX509CrlMatchParams(param);
380 return false;
381 }
382 context->crlMatchParam = param;
383
384 return true;
385 }
386
SelectCRLs(napi_env env,napi_callback_info info)387 napi_value NapiCertCRLCollection::SelectCRLs(napi_env env, napi_callback_info info)
388 {
389 size_t argc = ARGS_SIZE_TWO;
390 napi_value argv[ARGS_SIZE_TWO] = { nullptr };
391 napi_value thisVar = nullptr;
392 napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr);
393 if (thisVar == nullptr) {
394 LOGE("thisVar is nullptr");
395 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "thisVar is nullptr."));
396 return nullptr;
397 }
398 if (!CertCheckArgsCount(env, argc, ARGS_SIZE_TWO, false)) {
399 return nullptr;
400 }
401
402 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(CfMalloc(sizeof(CfCertCRLColCtx), 0));
403 if (context == nullptr) {
404 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "malloc context failed"));
405 LOGE("malloc context failed!");
406 return nullptr;
407 }
408 context->certCRLColClass = this;
409
410 if (!GetCrlMatchParam(env, argv[PARAM0], context)) {
411 CfFree(context);
412 return nullptr;
413 }
414
415 if (napi_create_reference(env, thisVar, 1, &context->cfCertCRLCollectionRef) != napi_ok) {
416 LOGE("create reference failed!");
417 FreeCryptoFwkCtx(env, context);
418 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create reference failed"));
419 return nullptr;
420 }
421 if (napi_create_reference(env, argv[PARAM0], 1, &context->crlMatchParamsRef) != napi_ok) {
422 LOGE("create param ref failed!");
423 FreeCryptoFwkCtx(env, context);
424 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create param ref failed"));
425 return nullptr;
426 }
427 if (!CreateCallbackAndPromise(env, context, argc, ARGS_SIZE_TWO, argv[PARAM1])) {
428 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "CreateCallbackAndPromise failed"));
429 LOGE("BuildX509CrlMatchParamss failed!");
430 FreeCryptoFwkCtx(env, context);
431 return nullptr;
432 }
433
434 napi_create_async_work(env, nullptr, CertGetResourceName(env, "SelectCRLs"), SelectCRLExecute, SelectCRLComplete,
435 static_cast<void *>(context), &context->asyncWork);
436
437 napi_queue_async_work(env, context->asyncWork);
438 if (context->asyncType == ASYNC_TYPE_PROMISE) {
439 return context->promise;
440 }
441
442 return CertNapiGetNull(env);
443 }
444
CertCRLColConstructor(napi_env env,napi_callback_info info)445 static napi_value CertCRLColConstructor(napi_env env, napi_callback_info info)
446 {
447 napi_value thisVar = nullptr;
448 napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
449 return thisVar;
450 }
451
ParseCreateCertCRLColJSParams(napi_env env,napi_callback_info info,HcfCertCrlCollection * & out)452 static CfResult ParseCreateCertCRLColJSParams(napi_env env, napi_callback_info info, HcfCertCrlCollection *&out)
453 {
454 size_t argc = ARGS_SIZE_TWO;
455 napi_value argv[ARGS_SIZE_TWO] = { nullptr };
456 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
457 HcfX509CertificateArray certs = { nullptr, 0 };
458 if (argc > PARAM0 && !GetArrayCertFromNapiValue(env, argv[PARAM0], &certs)) {
459 LOGE("get array cert from data failed!");
460 return CF_INVALID_PARAMS;
461 }
462 HcfX509CrlArray crls = { nullptr, 0 };
463 if (argc > PARAM1 && !GetArrayCRLFromNapiValue(env, argv[PARAM1], &crls)) {
464 LOGE("get array crl from data failed!");
465 CF_FREE_PTR(certs.data);
466 return CF_INVALID_PARAMS;
467 }
468
469 HcfCertCrlCollection *collection = nullptr;
470 CfResult res = HcfCertCrlCollectionCreate(&certs, &crls, &collection);
471 if (res != CF_SUCCESS) {
472 LOGE("get array crl from data failed!");
473 CF_FREE_PTR(certs.data);
474 CF_FREE_PTR(crls.data);
475 return res;
476 }
477 CF_FREE_PTR(certs.data);
478 CF_FREE_PTR(crls.data);
479 out = collection;
480 return CF_SUCCESS;
481 }
482
NapiCreateCertCRLCollection(napi_env env,napi_callback_info info)483 static napi_value NapiCreateCertCRLCollection(napi_env env, napi_callback_info info)
484 {
485 HcfCertCrlCollection *collection = nullptr;
486 CfResult res = ParseCreateCertCRLColJSParams(env, info, collection);
487 if (res != CF_SUCCESS) {
488 LOGE("Failed to parse JS params for create certcrlcollection object");
489 napi_throw(env, CertGenerateBusinessError(env, res, "parse param failed."));
490 return nullptr;
491 }
492 NapiCertCRLCollection *napiObject = new (std::nothrow) NapiCertCRLCollection(collection);
493 if (napiObject == nullptr) {
494 LOGE("Failed to create napi certcrlcolletion class");
495 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "malloc napiObject failed."));
496 CfObjDestroy(collection);
497 return nullptr;
498 }
499
500 napi_value instance = NapiCertCRLCollection::CreateCertCRLCollection(env);
501 napi_wrap(
502 env, instance, napiObject,
503 [](napi_env env, void *data, void *hint) {
504 NapiCertCRLCollection *objClass = static_cast<NapiCertCRLCollection *>(data);
505 delete objClass;
506 return;
507 },
508 nullptr, nullptr);
509
510 return instance;
511 }
512
DefineCertCRLCollectionJSClass(napi_env env,napi_value exports)513 void NapiCertCRLCollection::DefineCertCRLCollectionJSClass(napi_env env, napi_value exports)
514 {
515 napi_property_descriptor desc[] = {
516 DECLARE_NAPI_FUNCTION("createCertCRLCollection", NapiCreateCertCRLCollection),
517 };
518 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
519
520 napi_property_descriptor certCrlColDesc[] = {
521 DECLARE_NAPI_FUNCTION("selectCerts", NapiSelectCerts),
522 DECLARE_NAPI_FUNCTION("selectCRLs", NapiSelectCRLs),
523 };
524 napi_value constructor = nullptr;
525 napi_define_class(env, "CertCrlCollection", NAPI_AUTO_LENGTH, CertCRLColConstructor, nullptr,
526 sizeof(certCrlColDesc) / sizeof(certCrlColDesc[0]), certCrlColDesc, &constructor);
527
528 napi_create_reference(env, constructor, 1, &classRef_);
529 }
530
CreateCertCRLCollection(napi_env env)531 napi_value NapiCertCRLCollection::CreateCertCRLCollection(napi_env env)
532 {
533 napi_value constructor = nullptr;
534 napi_value instance = nullptr;
535 napi_get_reference_value(env, classRef_, &constructor);
536 napi_new_instance(env, constructor, 0, nullptr, &instance);
537 return instance;
538 }
539 } // namespace CertFramework
540 } // namespace OHOS
541