1 /* 2 * Copyright (c) 2023-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 HKS_LITE_API_COMMON_H 17 #define HKS_LITE_API_COMMON_H 18 19 #include "jsi.h" 20 21 #include "hks_type.h" 22 #include "hks_mem.h" 23 #include "hks_log.h" 24 25 namespace OHOS { 26 namespace ACELite { 27 #define HKS_HANDLE_SIZE 8 28 29 static const char *HKS_OPTIONS_PROPERTY_PROPERTIES = "properties"; 30 static const char *HKS_OPTIONS_PROPERTY_INDATA = "inData"; 31 static const char *HKS_PARAM_PROPERTY_TAG = "tag"; 32 static const char *HKS_PARAM_PROPERTY_VALUE = "value"; 33 static const char *HKS_HANDLE_PROPERTY_HANDLE = "handle"; 34 static const char *HKS_RESULT_PROPERTY_OUTDATA = "outData"; 35 static const char *BUSINESS_ERROR_PROPERTY_CODE = "code"; 36 static const char *BUSINESS_ERROR_PROPERTY_MESSAGE = "message"; 37 38 const uint32_t ARGS_INDEX_0 = 0; 39 const uint32_t ARGS_INDEX_1 = 1; 40 const uint32_t ARGS_INDEX_2 = 2; 41 42 struct HksLiteApiResult { 43 struct HksBlob *outData; 44 struct HksBlob *handle; 45 bool isBoolean; 46 }; 47 48 int32_t HksParseParamSetWithAdd(const JSIValue* args, uint32_t index, struct HksParamSet **outParamSet, 49 struct HksParam *paramsToAdd, uint32_t paramsToAddSize); 50 51 int32_t HksParseKeyAlias(const JSIValue* args, uint32_t index, struct HksBlob *outKeyAliasBlob); 52 53 int32_t HksParseHandle(const JSIValue* args, uint32_t index, struct HksBlob *outHandle); 54 55 int32_t HksParseInData(const JSIValue* args, uint32_t index, struct HksBlob *outInData); 56 57 JSIValue HksConvertErrorCodeToError(int32_t rawErrorCode); 58 59 JSIValue HksConstructJSIResult(void); 60 61 void HksCallbackResultFailure(const JSIValue thisVal, const JSIValue callback, int32_t error); 62 63 void HksCallbackResultSuccess(const JSIValue thisVal, JSIValue callback, const struct HksLiteApiResult *result); 64 65 int32_t InitHuksModule(void); 66 } // namespace ACELite 67 } // namespace OHOS 68 #endif // HKS_LITE_API_COMMON_H 69