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
24namespace OHOS {
25namespace Security {
26namespace CodeSign {
27class HUKSParamSet {
28public:
29    HUKSParamSet() : paramSet(nullptr)
30    {
31    }
32
33    ~HUKSParamSet()
34    {
35        if (paramSet != nullptr) {
36            HksFreeParamSet(&paramSet);
37            paramSet = nullptr;
38        }
39    }
40
41    bool Init(const struct HksParam tmpParams[], uint32_t paramCount)
42    {
43        int32_t ret = HksInitParamSet(&paramSet);
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(&paramSet);
55        if (ret != HKS_SUCCESS) {
56            LOG_ERROR("HksBuildParamSet failed");
57            return false;
58        }
59        return true;
60    }
61
62    HksParamSet *GetParamSet() const
63    {
64        return paramSet;
65    }
66private:
67    HksParamSet *paramSet = nullptr;
68};
69}
70}
71}
72#endif