1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 /** 17 * @defgroup bsl_param 18 * @ingroup bsl 19 * @brief bsl param 20 */ 21 22 #ifndef BSL_PARAMS_H 23 #define BSL_PARAMS_H 24 25 #include <stdint.h> 26 #include <stddef.h> 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #define BSL_PARAM_END {0, 0, NULL, 0, 0} 33 34 typedef enum { 35 BSL_PARAM_TYPE_UINT32_PTR, 36 BSL_PARAM_TYPE_OCTETS_PTR, 37 BSL_PARAM_TYPE_FUNC_PTR, 38 BSL_PARAM_TYPE_CTX_PTR, 39 BSL_PARAM_TYPE_UINT8, 40 BSL_PARAM_TYPE_UINT16, 41 BSL_PARAM_TYPE_UINT32, 42 BSL_PARAM_TYPE_BOOL, 43 BSL_PARAM_TYPE_INT32, 44 BSL_PARAM_TYPE_OCTETS, 45 } BSL_PARAM_VALUE_TYPE; 46 47 typedef struct BslParam { 48 int32_t key; 49 uint32_t valueType; 50 void *value; 51 uint32_t valueLen; 52 uint32_t useLen; 53 } BSL_Param; 54 55 /** 56 * @brief Initialize a BSL parameter structure 57 * @details Initializes a single BSL_Param structure by setting its key, type, value, and length 58 * 59 * @param param [IN] Pointer to the BSL_Param structure to be initialized 60 * @param key [IN] Parameter key value, refer to crypt_params_key.h 61 * @param type [IN] Parameter value type, refer to BSL_PARAM_VALUE_TYPE enum 62 * @param val [IN] Pointer to the parameter value 63 * @param valueLen [IN] Length of the parameter value 64 * 65 * @return int32_t Returns the operation result 66 * - BSL_SUCCESS indicates successful initialization 67 * - Other values indicate initialization failure 68 */ 69 int32_t BSL_PARAM_InitValue(BSL_Param *param, int32_t key, uint32_t type, void *val, uint32_t valueLen); 70 71 /** 72 * @brief Set BSL parameter value 73 * @details Updates the value in an existing BSL_Param structure 74 * 75 * @param param [IN] Pointer to the BSL_Param structure 76 * @param key [IN] Parameter key value, refer to crypt_params_key.h 77 * @param type [IN] Parameter value type, refer to BSL_PARAM_VALUE_TYPE enum 78 * @param val [IN] Pointer to the new parameter value 79 * @param len [IN] Length of the new parameter value 80 * 81 * @return int32_t Returns the operation result 82 * - BSL_SUCCESS indicates successful setting 83 * - Other values indicate setting failure 84 */ 85 int32_t BSL_PARAM_SetValue(BSL_Param *param, int32_t key, uint32_t type, void *val, uint32_t len); 86 87 /** 88 * @brief Get pointer to BSL parameter value 89 * @details Retrieves a pointer to the parameter value for the specified key without copying data 90 * 91 * @param param [IN] Pointer to the BSL_Param structure 92 * @param key [IN] Parameter key value, refer to crypt_params_key.h 93 * @param type [IN] Parameter value type, refer to BSL_PARAM_VALUE_TYPE enum 94 * @param val [OUT] Pointer to store the parameter value pointer 95 * @param valueLen [OUT] Pointer to store the parameter value length 96 * 97 * @return int32_t Returns the operation result 98 * - BSL_SUCCESS indicates successful retrieval 99 * - Other values indicate retrieval failure 100 */ 101 int32_t BSL_PARAM_GetPtrValue(const BSL_Param *param, int32_t key, uint32_t type, void **val, uint32_t *valueLen); 102 103 /** 104 * @brief Get BSL parameter value 105 * @details Retrieves the parameter value for the specified key by copying data to the provided buffer 106 * 107 * @param param [IN] Pointer to the BSL_Param structure 108 * @param key [IN] Parameter key value, refer to crypt_params_key.h 109 * @param type [IN] Parameter value type, refer to BSL_PARAM_VALUE_TYPE enum 110 * @param val [OUT] Buffer pointer to store the parameter value 111 * @param valueLen [OUT] Pointer to store the parameter value length 112 * 113 * @return int32_t Returns the operation result 114 * - BSL_SUCCESS indicates successful retrieval 115 * - Other values indicate retrieval failure 116 */ 117 int32_t BSL_PARAM_GetValue(const BSL_Param *param, int32_t key, uint32_t type, void *val, uint32_t *valueLen); 118 119 /** 120 * @brief Find BSL parameter by key 121 * @details Searches for a parameter with the specified key in the parameter array 122 * 123 * @param param [IN] Pointer to the BSL_Param structure array 124 * @param key [IN] Parameter key value to search for 125 * 126 * @return const BSL_Param* Returns pointer to the found parameter 127 * - Non-NULL indicates the parameter was found 128 * - NULL indicates the parameter was not found 129 */ 130 const BSL_Param *BSL_PARAM_FindConstParam(const BSL_Param *param, int32_t key); 131 132 /** 133 * @brief Find BSL parameter by key 134 * @details Searches for a parameter with the specified key in the parameter array 135 * 136 * @param param [IN] Pointer to the BSL_Param structure array 137 * @param key [IN] Parameter key value to search for 138 * 139 * @return BSL_Param* Returns pointer to the found parameter 140 * - Non-NULL indicates the parameter was found 141 * - NULL indicates the parameter was not found 142 */ 143 BSL_Param *BSL_PARAM_FindParam(BSL_Param *param, int32_t key); 144 145 #ifdef __cplusplus 146 } 147 #endif 148 149 #endif 150