1 /* 2 * Copyright (c) 2021-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 /** 17 * @file hks_param.h 18 * 19 * @brief Declares operate params interface. 20 * 21 * @since 8 22 */ 23 24 #ifndef HKS_PARAM_H 25 #define HKS_PARAM_H 26 27 #include "hks_type.h" 28 29 #define HKS_PARAM_SET_MAX_SIZE (4 * 1024 * 1024) 30 #define HKS_DEFAULT_PARAM_SET_SIZE 1024 31 #define HKS_DEFAULT_PARAM_CNT ((uint32_t)((HKS_DEFAULT_PARAM_SET_SIZE - sizeof(struct HksParamSet)) / \ 32 sizeof(struct HksParam))) 33 #define HKS_TAG_TYPE_MASK (0xF << 28) 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** 40 * @brief Init parameter set 41 * @param paramSet required parameter set 42 * @return error code, see hks_type.h 43 */ 44 HKS_API_EXPORT int32_t HksInitParamSet(struct HksParamSet **paramSet); 45 46 /** 47 * @brief Add parameter set 48 * @param paramSet required parameter set 49 * @param params params need to add 50 * 51 * @param paramCnt numbers of params 52 * @return error code, see hks_type.h 53 */ 54 HKS_API_EXPORT int32_t HksAddParams(struct HksParamSet *paramSet, 55 const struct HksParam *params, uint32_t paramCnt); 56 57 /** 58 * @brief Build parameter set 59 * @param paramSet required parameter set 60 * @return error code, see hks_type.h 61 */ 62 HKS_API_EXPORT int32_t HksBuildParamSet(struct HksParamSet **paramSet); 63 64 /** 65 * @brief Free parameter set 66 * @param paramSet required parameter set 67 * @return error code, see hks_type.h 68 */ 69 HKS_API_EXPORT void HksFreeParamSet(struct HksParamSet **paramSet); 70 71 /** 72 * @brief Free alias set 73 * @param aliasSet required alias set 74 * @return error code, see hks_type.h 75 */ 76 HKS_API_EXPORT void HksFreeKeyAliasSet(struct HksKeyAliasSet *aliasSet); 77 78 /** 79 * @brief Get parameter set 80 * @param inParamSet required parameter set 81 * @param inParamSetSize input patamSet size 82 * @param outParamSet output parameter set 83 * @return error code, see hks_type.h 84 */ 85 HKS_API_EXPORT int32_t HksGetParamSet(const struct HksParamSet *inParamSet, uint32_t inParamSetSize, 86 struct HksParamSet **outParamSet); 87 88 /** 89 * @brief Get parameter 90 * @param paramSet required parameter set 91 * @param tag param's tag 92 * @param param output param 93 * @return error code, see hks_type.h 94 */ 95 HKS_API_EXPORT int32_t HksGetParam(const struct HksParamSet *paramSet, uint32_t tag, struct HksParam **param); 96 97 /** 98 * @brief Fresh parameter set 99 * @param paramSet required parameter set 100 * @param isCopy is copy or not 101 * @return error code, see hks_type.h 102 */ 103 HKS_API_EXPORT int32_t HksFreshParamSet(struct HksParamSet *paramSet, bool isCopy); 104 105 /** 106 * @brief Check param set tag 107 * @param paramSet required parameter set 108 * @return error code, see hks_type.h 109 */ 110 HKS_API_EXPORT int32_t HksCheckParamSetTag(const struct HksParamSet *paramSet); 111 112 /** 113 * @brief Check param set 114 * @param paramSet required parameter set 115 * @param size paramset size 116 * @return error code, see hks_type.h 117 */ 118 HKS_API_EXPORT int32_t HksCheckParamSet(const struct HksParamSet *paramSet, uint32_t size); 119 120 /** 121 * @brief Check param whether match or not 122 * @param baseParam one param 123 * @param param another param 124 * @return error code, see hks_type.h 125 */ 126 HKS_API_EXPORT int32_t HksCheckParamMatch(const struct HksParam *baseParam, const struct HksParam *param); 127 128 /** 129 * @brief Check param set tag 130 * @param paramSet required parameter set 131 * @return error code, see hks_type.h 132 */ 133 HKS_API_EXPORT int32_t HksCheckParamSetTag(const struct HksParamSet *paramSet); 134 135 /** 136 * @brief Check whether the tag exists 137 * @param params required parameter 138 * @param paramsCnt paramter size 139 * @param targetParamSet target paramset 140 * @return error code, see hks_type.h 141 */ 142 HKS_API_EXPORT int32_t HksCheckIsTagAlreadyExist(const struct HksParam *params, uint32_t paramsCnt, 143 const struct HksParamSet *targetParamSet); 144 145 /** 146 * @brief Get tag type 147 * @param tag the tag 148 * @return tag type, see hks_type.h 149 */ 150 HKS_API_EXPORT enum HksTagType GetTagType(enum HksTag tag); 151 152 HKS_API_EXPORT int32_t HksDeleteTagsFromParamSet(const uint32_t *tag, uint32_t tagCount, 153 const struct HksParamSet *paramSet, struct HksParamSet **outParamSet); 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif /* HKS_PARAM_H */ 160