• 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 #define HUKS_DISABLE_LOG_AT_FILE_TO_REDUCE_ROM_SIZE
16 
17 #include "hks_lite_api.h"
18 #include "hks_log.h"
19 #include "jsi.h"
20 #include "jsi_types.h"
21 
22 #include "hks_api.h"
23 #include "hks_param.h"
24 #include "hks_lite_api_common.h"
25 
26 namespace OHOS {
27 namespace ACELite {
HksCallGenerateKey(const struct HksBlob * aliasBlob,const struct HksParamSet * paramSet)28 static int32_t HksCallGenerateKey(const struct HksBlob *aliasBlob, const struct HksParamSet *paramSet)
29 {
30     int32_t ret = InitHuksModule();
31     if (ret != HKS_SUCCESS) {
32         HKS_LOG_E("init huks failed");
33         return ret;
34     }
35     ret = HksGenerateKey(aliasBlob, paramSet, nullptr);
36     return ret;
37 }
38 
generateKeyItem(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)39 JSIValue HksLiteModule::generateKeyItem(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
40 {
41     JSIValue undefValue = JSI::CreateUndefined();
42     uint32_t minNumArgs = 3;
43     if (argsNum < minNumArgs || args == nullptr) {
44         HKS_LOG_E("generateKeyItem args invalid, args num(%{public}d).", argsNum);
45         return undefValue;
46     }
47 
48     struct HksBlob aliasBlob = { 0, nullptr };
49     struct HksParamSet *paramSet = nullptr;
50     int32_t ret;
51     do {
52         ret = HksParseKeyAlias(args, ARGS_INDEX_0, &aliasBlob);
53         if (ret != HKS_SUCCESS) {
54             break;
55         }
56         ret = HksParseParamSetWithAdd(args, ARGS_INDEX_1, &paramSet, nullptr, 0);
57         if (ret != HKS_SUCCESS) {
58             break;
59         }
60         ret = HksCallGenerateKey(&aliasBlob, paramSet);
61     } while (0);
62     if (ret == HKS_SUCCESS) {
63         struct HksLiteApiResult result = { nullptr, nullptr, false };
64         HksCallbackResultSuccess(thisVal, args[ARGS_INDEX_2], &result);
65     } else {
66         HksCallbackResultFailure(thisVal, args[ARGS_INDEX_2], ret);
67     }
68 
69     HKS_FREE_BLOB(aliasBlob);
70     HksFreeParamSet(&paramSet);
71     return undefValue;
72 }
73 }
74 }