• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef NAPI_CERT_UILTS_H
17 #define NAPI_CERT_UILTS_H
18 
19 #include <cstdint>
20 #include <string>
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 #include "cf_blob.h"
24 #include "cert_chain_validator.h"
25 #include "napi_cert_defines.h"
26 
27 namespace OHOS {
28 namespace CertFramework {
CertAddUint32Property(napi_env env,napi_value object,const char * name,uint32_t value)29 inline void CertAddUint32Property(napi_env env, napi_value object, const char *name, uint32_t value)
30 {
31     napi_value property = nullptr;
32     napi_create_uint32(env, value, &property);
33     napi_set_named_property(env, object, name, property);
34 }
35 
36 CfBlob *CertGetBlobFromNapiValue(napi_env env, napi_value arg);
37 napi_value CertConvertBlobToNapiValue(napi_env env, CfBlob *blob);
38 
39 bool CertGetStringFromJSParams(napi_env env, napi_value arg, std::string &returnStr);
40 bool CertGetInt32FromJSParams(napi_env env, napi_value arg, int32_t &returnInt);
41 bool CertGetCallbackFromJSParams(napi_env env, napi_value arg, napi_ref *returnCb);
42 bool GetEncodingBlobFromValue(napi_env env, napi_value object, CfEncodingBlob **encodingBlob);
43 bool GetCertChainFromValue(napi_env env, napi_value object, HcfCertChainData **certChainData);
44 bool CertCheckArgsCount(napi_env env, size_t argc, size_t expectedCount, bool isSync);
45 AsyncType GetAsyncType(napi_env env, size_t argc, size_t maxCount, napi_value arg);
46 napi_value CertGetResourceName(napi_env env, const char *name);
47 napi_value GenerateArrayBuffer(napi_env env, uint8_t *data, uint32_t size);
48 napi_value CertNapiGetNull(napi_env env);
49 napi_value ConvertArrayToNapiValue(napi_env env, CfArray *array);
50 napi_value ConvertEncodingBlobToNapiValue(napi_env env, CfEncodingBlob *encodingBlob);
51 napi_value CertGenerateBusinessError(napi_env env, int32_t errCode, const char *errMsg);
52 napi_value ConvertBlobToNapiValue(napi_env env, const CfBlob *blob);
53 napi_value ConvertBlobToBigIntWords(napi_env env, const CfBlob &blob);
54 napi_value ConvertBlobToInt64(napi_env env, const CfBlob &blob);
55 }  // namespace CertFramework
56 }  // namespace OHOS
57 #endif
58