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 context->certMatchParam = nullptr;
90 }
91 if (context->crlMatchParam != nullptr) {
92 FreeX509CrlMatchParams(context->crlMatchParam);
93 }
94 CF_FREE_PTR(context->retCerts.data);
95 context->retCerts.count = 0;
96 CF_FREE_PTR(context->retCrls.data);
97 context->retCrls.count = 0;
98
99 CF_FREE_PTR(context);
100 }
101
ReturnCallbackResult(napi_env env,CfCertCRLColCtx * context,napi_value result)102 static void ReturnCallbackResult(napi_env env, CfCertCRLColCtx *context, napi_value result)
103 {
104 napi_value businessError = nullptr;
105 if (context->errCode != CF_SUCCESS) {
106 businessError = CertGenerateBusinessError(env, context->errCode, context->errMsg);
107 }
108 napi_value params[ARGS_SIZE_TWO] = { businessError, result };
109
110 napi_value func = nullptr;
111 napi_get_reference_value(env, context->callback, &func);
112
113 napi_value recv = nullptr;
114 napi_value callFuncRet = nullptr;
115 napi_get_undefined(env, &recv);
116 napi_call_function(env, recv, func, ARGS_SIZE_TWO, params, &callFuncRet);
117 }
118
ReturnPromiseResult(napi_env env,CfCertCRLColCtx * context,napi_value result)119 static void ReturnPromiseResult(napi_env env, CfCertCRLColCtx *context, napi_value result)
120 {
121 if (context->errCode == CF_SUCCESS) {
122 napi_resolve_deferred(env, context->deferred, result);
123 } else {
124 napi_reject_deferred(env, context->deferred, CertGenerateBusinessError(env, context->errCode, context->errMsg));
125 }
126 }
127
ReturnResult(napi_env env,CfCertCRLColCtx * context,napi_value result)128 static void ReturnResult(napi_env env, CfCertCRLColCtx *context, napi_value result)
129 {
130 if (context->asyncType == ASYNC_TYPE_CALLBACK) {
131 ReturnCallbackResult(env, context, result);
132 } else {
133 ReturnPromiseResult(env, context, result);
134 }
135 }
136
CreateCallbackAndPromise(napi_env env,CfCertCRLColCtx * context,size_t argc,size_t maxCount,napi_value callbackValue)137 static bool CreateCallbackAndPromise(
138 napi_env env, CfCertCRLColCtx *context, size_t argc, size_t maxCount, napi_value callbackValue)
139 {
140 context->asyncType = GetAsyncType(env, argc, maxCount, callbackValue);
141 if (context->asyncType == ASYNC_TYPE_CALLBACK) {
142 if (!CertGetCallbackFromJSParams(env, callbackValue, &context->callback)) {
143 LOGE("CerCRLColletion: get callback failed!");
144 return false;
145 }
146 } else {
147 if (napi_create_promise(env, &context->deferred, &context->promise) != napi_ok) {
148 return false;
149 }
150 }
151 return true;
152 }
153
NapiCertCRLCollection(HcfCertCrlCollection * collection)154 NapiCertCRLCollection::NapiCertCRLCollection(HcfCertCrlCollection *collection)
155 {
156 certCrlCollection_ = collection;
157 }
158
~NapiCertCRLCollection()159 NapiCertCRLCollection::~NapiCertCRLCollection()
160 {
161 CfObjDestroy(this->certCrlCollection_);
162 }
163
SelectCRLsRet(napi_env env,const HcfX509CrlArray * crls)164 napi_value NapiCertCRLCollection::SelectCRLsRet(napi_env env, const HcfX509CrlArray *crls)
165 {
166 napi_value instance;
167 napi_create_array(env, &instance);
168 if (instance == nullptr) {
169 LOGE("create return array failed!");
170 return nullptr;
171 }
172 if (crls == nullptr) {
173 LOGI("return empty array!");
174 return instance;
175 }
176 int j = 0;
177 for (uint32_t i = 0; i < crls->count; ++i) {
178 HcfX509Crl *crl = crls->data[i];
179 NapiX509Crl *x509Crl = new (std::nothrow) NapiX509Crl(crl);
180 if (x509Crl == nullptr) {
181 LOGE("new x509Crl failed!");
182 continue;
183 }
184 napi_value element = NapiX509Crl::CreateX509Crl(env, "createX509CRL");
185 napi_status status = napi_wrap(
186 env, element, x509Crl,
187 [](napi_env env, void *data, void *hint) {
188 NapiX509Crl *crl = static_cast<NapiX509Crl *>(data);
189 delete crl;
190 return;
191 },
192 nullptr, nullptr);
193 if (status != napi_ok) {
194 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_NAPI, "failed to wrap obj!"));
195 LOGE("failed to wrap obj!");
196 delete x509Crl;
197 crls->data[i] = nullptr;
198 return nullptr;
199 }
200 napi_set_element(env, instance, j++, element);
201 crls->data[i] = nullptr;
202 }
203 return instance;
204 }
205
SelectCertsExecute(napi_env env,void * data)206 static void SelectCertsExecute(napi_env env, void *data)
207 {
208 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
209 NapiCertCRLCollection *certCrlCol = context->certCRLColClass;
210 HcfCertCrlCollection *collection = certCrlCol->GetCertCrlCollection();
211 CfResult res = collection->selectCerts(collection, context->certMatchParam, &context->retCerts);
212 if (res != CF_SUCCESS) {
213 LOGE("selectCerts failed!");
214 context->errCode = res;
215 context->errMsg = "selectCerts failed!";
216 }
217 }
218
SelectCertsComplete(napi_env env,napi_status status,void * data)219 static void SelectCertsComplete(napi_env env, napi_status status, void *data)
220 {
221 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
222 if (context->errCode != CF_SUCCESS) {
223 ReturnResult(env, context, nullptr);
224 FreeCryptoFwkCtx(env, context);
225 return;
226 }
227 napi_value instance = ConvertCertArrToNapiValue(env, &context->retCerts);
228 ReturnResult(env, context, instance);
229 for (uint32_t i = 0; i < context->retCerts.count; ++i) {
230 CfObjDestroy(context->retCerts.data[i]);
231 }
232 FreeCryptoFwkCtx(env, context);
233 }
234
NapiSelectCerts(napi_env env,napi_callback_info info)235 static napi_value NapiSelectCerts(napi_env env, napi_callback_info info)
236 {
237 napi_value thisVar = nullptr;
238 napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
239 if (thisVar == nullptr) {
240 LOGE("thisVar is nullptr");
241 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "thisVar is nullptr."));
242 return nullptr;
243 }
244 NapiCertCRLCollection *certCrlCol = nullptr;
245 napi_unwrap(env, thisVar, reinterpret_cast<void **>(&certCrlCol));
246 if (certCrlCol == nullptr) {
247 LOGE("certCrlCol is nullptr!");
248 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "certCrlCol is nullptr."));
249 return nullptr;
250 }
251 return certCrlCol->SelectCerts(env, info);
252 }
253
GetCertMatchParams(napi_env env,napi_value arg,CfCertCRLColCtx * context)254 static bool GetCertMatchParams(napi_env env, napi_value arg, CfCertCRLColCtx *context)
255 {
256 HcfX509CertMatchParams *param = static_cast<HcfX509CertMatchParams *>(CfMalloc(sizeof(HcfX509CertMatchParams), 0));
257 if (param == nullptr) {
258 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Malloc matchParams failed"));
259 LOGE("malloc matchParams failed!");
260 return false;
261 }
262 if (!BuildX509CertMatchParams(env, arg, param)) {
263 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Build X509 cert match params failed"));
264 LOGE("build X509 cert match params failed!");
265 FreeX509CertMatchParams(param);
266 param = nullptr;
267 return false;
268 }
269 context->certMatchParam = param;
270 return true;
271 }
272
SelectCerts(napi_env env,napi_callback_info info)273 napi_value NapiCertCRLCollection::SelectCerts(napi_env env, napi_callback_info info)
274 {
275 size_t argc = ARGS_SIZE_TWO;
276 napi_value argv[ARGS_SIZE_TWO] = { nullptr };
277 napi_value thisVar = nullptr;
278 napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr);
279
280 if (!CertCheckArgsCount(env, argc, ARGS_SIZE_TWO, false)) {
281 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "CertCheckArgsCount failed."));
282 LOGE("CertCheckArgsCount is not 2!");
283 return nullptr;
284 }
285
286 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(CfMalloc(sizeof(CfCertCRLColCtx), 0));
287 if (context == nullptr) {
288 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "malloc context failed"));
289 LOGE("malloc context failed!");
290 return nullptr;
291 }
292 context->certCRLColClass = this;
293
294 if (!GetCertMatchParams(env, argv[PARAM0], context)) {
295 CfFree(context);
296 context = nullptr;
297 return nullptr;
298 }
299
300 if (napi_create_reference(env, thisVar, 1, &context->cfCertCRLCollectionRef) != napi_ok) {
301 LOGE("create reference failed!");
302 FreeCryptoFwkCtx(env, context);
303 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create reference failed"));
304 return nullptr;
305 }
306 if (napi_create_reference(env, argv[PARAM0], 1, &context->certMatchParamsRef) != napi_ok) {
307 LOGE("create param ref failed!");
308 FreeCryptoFwkCtx(env, context);
309 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create param ref failed"));
310 return nullptr;
311 }
312 if (!CreateCallbackAndPromise(env, context, argc, ARGS_SIZE_TWO, argv[PARAM1])) {
313 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "CreateCallbackAndPromise failed"));
314 LOGE("CreateCallbackAndPromise failed!");
315 FreeCryptoFwkCtx(env, context);
316 return nullptr;
317 }
318 napi_create_async_work(env, nullptr, CertGetResourceName(env, "SelectCerts"), SelectCertsExecute,
319 SelectCertsComplete, static_cast<void *>(context), &context->asyncWork);
320
321 napi_queue_async_work(env, context->asyncWork);
322 if (context->asyncType == ASYNC_TYPE_PROMISE) {
323 return context->promise;
324 }
325
326 return CertNapiGetNull(env);
327 }
328
NapiSelectCRLs(napi_env env,napi_callback_info info)329 static napi_value NapiSelectCRLs(napi_env env, napi_callback_info info)
330 {
331 napi_value thisVar = nullptr;
332 napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
333 if (thisVar == nullptr) {
334 LOGE("thisVar is nullptr");
335 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "thisVar is nullptr."));
336 return nullptr;
337 }
338 NapiCertCRLCollection *certCrlCol = nullptr;
339 napi_unwrap(env, thisVar, reinterpret_cast<void **>(&certCrlCol));
340 if (certCrlCol == nullptr) {
341 LOGE("certCrlCol is nullptr!");
342 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "certCrlCol is nullptr."));
343 return nullptr;
344 }
345 return certCrlCol->SelectCRLs(env, info);
346 }
347
SelectCRLExecute(napi_env env,void * data)348 static void SelectCRLExecute(napi_env env, void *data)
349 {
350 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
351 NapiCertCRLCollection *certCrlCol = context->certCRLColClass;
352 HcfCertCrlCollection *collection = certCrlCol->GetCertCrlCollection();
353 CfResult res = collection->selectCRLs(collection, context->crlMatchParam, &context->retCrls);
354 if (res != CF_SUCCESS) {
355 LOGE("selectCrls failed!");
356 context->errCode = res;
357 context->errMsg = "selectCrls failed!";
358 }
359 }
360
SelectCRLComplete(napi_env env,napi_status status,void * data)361 static void SelectCRLComplete(napi_env env, napi_status status, void *data)
362 {
363 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(data);
364 if (context->errCode != CF_SUCCESS) {
365 ReturnResult(env, context, nullptr);
366 FreeCryptoFwkCtx(env, context);
367 return;
368 }
369 NapiCertCRLCollection *certCrlCol = context->certCRLColClass;
370 napi_value instance = certCrlCol->SelectCRLsRet(env, &context->retCrls);
371 for (uint32_t i = 0; i < context->retCrls.count; ++i) {
372 CfObjDestroy(context->retCrls.data[i]);
373 }
374 ReturnResult(env, context, instance);
375 FreeCryptoFwkCtx(env, context);
376 }
377
GetCrlMatchParam(napi_env env,napi_value arg,CfCertCRLColCtx * context)378 static bool GetCrlMatchParam(napi_env env, napi_value arg, CfCertCRLColCtx *context)
379 {
380 HcfX509CrlMatchParams *param = static_cast<HcfX509CrlMatchParams *>(CfMalloc(sizeof(HcfX509CrlMatchParams), 0));
381 if (param == nullptr) {
382 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "Malloc matchParams failed"));
383 LOGE("malloc matchParams failed!");
384 return false;
385 }
386 if (!BuildX509CrlMatchParams(env, arg, param)) {
387 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Build X509 crl match params failed"));
388 LOGE("build X509 crl match params failed!");
389 FreeX509CrlMatchParams(param);
390 return false;
391 }
392 context->crlMatchParam = param;
393
394 return true;
395 }
396
SelectCRLs(napi_env env,napi_callback_info info)397 napi_value NapiCertCRLCollection::SelectCRLs(napi_env env, napi_callback_info info)
398 {
399 size_t argc = ARGS_SIZE_TWO;
400 napi_value argv[ARGS_SIZE_TWO] = { nullptr };
401 napi_value thisVar = nullptr;
402 napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr);
403 if (thisVar == nullptr) {
404 LOGE("thisVar is nullptr");
405 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "thisVar is nullptr."));
406 return nullptr;
407 }
408 if (!CertCheckArgsCount(env, argc, ARGS_SIZE_TWO, false)) {
409 return nullptr;
410 }
411
412 CfCertCRLColCtx *context = static_cast<CfCertCRLColCtx *>(CfMalloc(sizeof(CfCertCRLColCtx), 0));
413 if (context == nullptr) {
414 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "malloc context failed"));
415 LOGE("malloc context failed!");
416 return nullptr;
417 }
418 context->certCRLColClass = this;
419
420 if (!GetCrlMatchParam(env, argv[PARAM0], context)) {
421 CF_FREE_PTR(context);
422 return nullptr;
423 }
424
425 if (napi_create_reference(env, thisVar, 1, &context->cfCertCRLCollectionRef) != napi_ok) {
426 LOGE("create reference failed!");
427 FreeCryptoFwkCtx(env, context);
428 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create reference failed"));
429 return nullptr;
430 }
431 if (napi_create_reference(env, argv[PARAM0], 1, &context->crlMatchParamsRef) != napi_ok) {
432 LOGE("create param ref failed!");
433 FreeCryptoFwkCtx(env, context);
434 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "Create param ref failed"));
435 return nullptr;
436 }
437 if (!CreateCallbackAndPromise(env, context, argc, ARGS_SIZE_TWO, argv[PARAM1])) {
438 napi_throw(env, CertGenerateBusinessError(env, CF_INVALID_PARAMS, "CreateCallbackAndPromise failed"));
439 LOGE("BuildX509CrlMatchParamss failed!");
440 FreeCryptoFwkCtx(env, context);
441 return nullptr;
442 }
443
444 napi_create_async_work(env, nullptr, CertGetResourceName(env, "SelectCRLs"), SelectCRLExecute, SelectCRLComplete,
445 static_cast<void *>(context), &context->asyncWork);
446
447 napi_queue_async_work(env, context->asyncWork);
448 if (context->asyncType == ASYNC_TYPE_PROMISE) {
449 return context->promise;
450 }
451
452 return CertNapiGetNull(env);
453 }
454
CertCRLColConstructor(napi_env env,napi_callback_info info)455 static napi_value CertCRLColConstructor(napi_env env, napi_callback_info info)
456 {
457 napi_value thisVar = nullptr;
458 napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
459 return thisVar;
460 }
461
ParseCreateCertCRLColJSParams(napi_env env,napi_callback_info info,HcfCertCrlCollection * & out)462 static CfResult ParseCreateCertCRLColJSParams(napi_env env, napi_callback_info info, HcfCertCrlCollection *&out)
463 {
464 size_t argc = ARGS_SIZE_TWO;
465 napi_value argv[ARGS_SIZE_TWO] = { nullptr };
466 napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
467 HcfX509CertificateArray certs = { nullptr, 0 };
468 if (argc > PARAM0 && !GetArrayCertFromNapiValue(env, argv[PARAM0], &certs)) {
469 LOGE("get array cert from data failed!");
470 return CF_INVALID_PARAMS;
471 }
472 HcfX509CrlArray crls = { nullptr, 0 };
473 if (argc > PARAM1 && !GetArrayCRLFromNapiValue(env, argv[PARAM1], &crls)) {
474 LOGE("get array crl from data failed!");
475 CF_FREE_PTR(certs.data);
476 return CF_INVALID_PARAMS;
477 }
478
479 HcfCertCrlCollection *collection = nullptr;
480 CfResult res = HcfCertCrlCollectionCreate(&certs, &crls, &collection);
481 if (res != CF_SUCCESS) {
482 LOGE("get array crl from data failed!");
483 CF_FREE_PTR(certs.data);
484 CF_FREE_PTR(crls.data);
485 return res;
486 }
487 CF_FREE_PTR(certs.data);
488 CF_FREE_PTR(crls.data);
489 out = collection;
490 return CF_SUCCESS;
491 }
492
NapiCreateCertCRLCollection(napi_env env,napi_callback_info info)493 static napi_value NapiCreateCertCRLCollection(napi_env env, napi_callback_info info)
494 {
495 HcfCertCrlCollection *collection = nullptr;
496 CfResult res = ParseCreateCertCRLColJSParams(env, info, collection);
497 if (res != CF_SUCCESS) {
498 LOGE("Failed to parse JS params for create certcrlcollection object");
499 napi_throw(env, CertGenerateBusinessError(env, res, "parse param failed."));
500 return nullptr;
501 }
502 NapiCertCRLCollection *napiObject = new (std::nothrow) NapiCertCRLCollection(collection);
503 if (napiObject == nullptr) {
504 LOGE("Failed to create napi certcrlcolletion class");
505 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_MALLOC, "malloc napiObject failed."));
506 CfObjDestroy(collection);
507 return nullptr;
508 }
509
510 napi_value instance = NapiCertCRLCollection::CreateCertCRLCollection(env);
511 napi_status status = napi_wrap(
512 env, instance, napiObject,
513 [](napi_env env, void *data, void *hint) {
514 NapiCertCRLCollection *objClass = static_cast<NapiCertCRLCollection *>(data);
515 delete objClass;
516 return;
517 },
518 nullptr, nullptr);
519 if (status != napi_ok) {
520 napi_throw(env, CertGenerateBusinessError(env, CF_ERR_NAPI, "failed to wrap obj!"));
521 LOGE("failed to wrap obj!");
522 delete napiObject;
523 return nullptr;
524 }
525
526 return instance;
527 }
528
DefineCertCRLCollectionJSClass(napi_env env,napi_value exports)529 void NapiCertCRLCollection::DefineCertCRLCollectionJSClass(napi_env env, napi_value exports)
530 {
531 napi_property_descriptor desc[] = {
532 DECLARE_NAPI_FUNCTION("createCertCRLCollection", NapiCreateCertCRLCollection),
533 };
534 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
535
536 napi_property_descriptor certCrlColDesc[] = {
537 DECLARE_NAPI_FUNCTION("selectCerts", NapiSelectCerts),
538 DECLARE_NAPI_FUNCTION("selectCRLs", NapiSelectCRLs),
539 };
540 napi_value constructor = nullptr;
541 napi_define_class(env, "CertCrlCollection", NAPI_AUTO_LENGTH, CertCRLColConstructor, nullptr,
542 sizeof(certCrlColDesc) / sizeof(certCrlColDesc[0]), certCrlColDesc, &constructor);
543
544 napi_create_reference(env, constructor, 1, &classRef_);
545 }
546
CreateCertCRLCollection(napi_env env)547 napi_value NapiCertCRLCollection::CreateCertCRLCollection(napi_env env)
548 {
549 napi_value constructor = nullptr;
550 napi_value instance = nullptr;
551 napi_get_reference_value(env, classRef_, &constructor);
552 napi_new_instance(env, constructor, 0, nullptr, &instance);
553 return instance;
554 }
555 } // namespace CertFramework
556 } // namespace OHOS
557