1 /* 2 * Copyright (c) 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 #ifndef CODE_SIGN_HUKS_PARAM_SET_H 17 #define CODE_SIGN_HUKS_PARAM_SET_H 18 19 #include "hks_type.h" 20 #include "hks_api.h" 21 #include "hks_param.h" 22 #include "log.h" 23 24 namespace OHOS { 25 namespace Security { 26 namespace CodeSign { 27 class HUKSParamSet { 28 public: HUKSParamSet()29 HUKSParamSet() : paramSet(nullptr) 30 { 31 } 32 ~HUKSParamSet()33 ~HUKSParamSet() 34 { 35 if (paramSet != nullptr) { 36 HksFreeParamSet(¶mSet); 37 paramSet = nullptr; 38 } 39 } 40 Init(const struct HksParam tmpParams[],uint32_t paramCount)41 bool Init(const struct HksParam tmpParams[], uint32_t paramCount) 42 { 43 int32_t ret = HksInitParamSet(¶mSet); 44 if (ret != HKS_SUCCESS) { 45 LOG_ERROR("HksInitParamSet failed"); 46 return false; 47 } 48 ret = HksAddParams(paramSet, tmpParams, paramCount); 49 if (ret != HKS_SUCCESS) { 50 LOG_ERROR("HksAddParams failed"); 51 return false; 52 } 53 54 ret = HksBuildParamSet(¶mSet); 55 if (ret != HKS_SUCCESS) { 56 LOG_ERROR("HksBuildParamSet failed"); 57 return false; 58 } 59 return true; 60 } 61 GetParamSet()62 HksParamSet *GetParamSet() const 63 { 64 return paramSet; 65 } 66 private: 67 HksParamSet *paramSet = nullptr; 68 }; 69 } 70 } 71 } 72 #endif