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 Add parameter set and filter in black list way 59 * @param paramSet required parameter set 60 * @param params params need to add 61 * 62 * @param paramCnt numbers of params 63 * @return error code, see hks_type.h 64 */ 65 HKS_API_EXPORT int32_t HksAddParamsWithFilter(struct HksParamSet *paramSet, 66 const struct HksParam *params, uint32_t paramCnt); 67 /** 68 * @brief Build parameter set 69 * @param paramSet required parameter set 70 * @return error code, see hks_type.h 71 */ 72 HKS_API_EXPORT int32_t HksBuildParamSet(struct HksParamSet **paramSet); 73 74 /** 75 * @brief Free parameter set 76 * @param paramSet required parameter set 77 * @return error code, see hks_type.h 78 */ 79 HKS_API_EXPORT void HksFreeParamSet(struct HksParamSet **paramSet); 80 81 /** 82 * @brief Free alias set 83 * @param aliasSet required alias set 84 * @return error code, see hks_type.h 85 */ 86 HKS_API_EXPORT void HksFreeKeyAliasSet(struct HksKeyAliasSet *aliasSet); 87 88 /** 89 * @brief Get parameter set 90 * @param inParamSet required parameter set 91 * @param inParamSetSize input patamSet size 92 * @param outParamSet output parameter set 93 * @return error code, see hks_type.h 94 */ 95 HKS_API_EXPORT int32_t HksGetParamSet(const struct HksParamSet *inParamSet, uint32_t inParamSetSize, 96 struct HksParamSet **outParamSet); 97 98 /** 99 * @brief Get parameter 100 * @param paramSet required parameter set 101 * @param tag param's tag 102 * @param param output param 103 * @return error code, see hks_type.h 104 */ 105 HKS_API_EXPORT int32_t HksGetParam(const struct HksParamSet *paramSet, uint32_t tag, struct HksParam **param); 106 107 /** 108 * @brief Fresh parameter set 109 * @param paramSet required parameter set 110 * @param isCopy is copy or not 111 * @return error code, see hks_type.h 112 */ 113 HKS_API_EXPORT int32_t HksFreshParamSet(struct HksParamSet *paramSet, bool isCopy); 114 115 /** 116 * @brief Check param set tag 117 * @param paramSet required parameter set 118 * @return error code, see hks_type.h 119 */ 120 HKS_API_EXPORT int32_t HksCheckParamSetTag(const struct HksParamSet *paramSet); 121 122 /** 123 * @brief Check param set 124 * @param paramSet required parameter set 125 * @param size paramset size 126 * @return error code, see hks_type.h 127 */ 128 HKS_API_EXPORT int32_t HksCheckParamSet(const struct HksParamSet *paramSet, uint32_t size); 129 130 /** 131 * @brief Check param whether match or not 132 * @param baseParam one param 133 * @param param another param 134 * @return error code, see hks_type.h 135 */ 136 HKS_API_EXPORT int32_t HksCheckParamMatch(const struct HksParam *baseParam, const struct HksParam *param); 137 138 /** 139 * @brief Check param set tag 140 * @param paramSet required parameter set 141 * @return error code, see hks_type.h 142 */ 143 HKS_API_EXPORT int32_t HksCheckParamSetTag(const struct HksParamSet *paramSet); 144 145 /** 146 * @brief Check whether the tag exists 147 * @param params required parameter 148 * @param paramsCnt paramter size 149 * @param targetParamSet target paramset 150 * @return error code, see hks_type.h 151 */ 152 HKS_API_EXPORT int32_t HksCheckIsTagAlreadyExist(const struct HksParam *params, uint32_t paramsCnt, 153 const struct HksParamSet *targetParamSet); 154 155 /** 156 * @brief Get tag type 157 * @param tag the tag 158 * @return tag type, see hks_type.h 159 */ 160 HKS_API_EXPORT enum HksTagType GetTagType(enum HksTag tag); 161 162 HKS_API_EXPORT int32_t HksDeleteTagsFromParamSet(const uint32_t *tag, uint32_t tagCount, 163 const struct HksParamSet *paramSet, struct HksParamSet **outParamSet); 164 165 #ifdef __cplusplus 166 } 167 #endif 168 169 #endif /* HKS_PARAM_H */ 170