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 #ifndef HITLS_PKI_UTILS_H 17 #define HITLS_PKI_UTILS_H 18 19 #include "hitls_pki_types.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 typedef struct _HITLS_X509_Ext HITLS_X509_Ext; 26 27 typedef struct _HITLS_X509_Attrs HITLS_X509_Attrs; 28 29 /** 30 * @ingroup pki 31 * @brief Generic function to set/get an extension. 32 * 33 * @param ext [IN] extensions 34 * @param cmd [IN] HITLS_X509_EXT_SET_XXX 35 * cmd data type 36 * HITLS_X509_EXT_GET|SET_KUSAGE HITLS_X509_ExtKeyUsage 37 * HITLS_X509_EXT_GET|SET_BCONS HITLS_X509_ExtBCons 38 * HITLS_X509_EXT_GET|SET_AKI HITLS_X509_ExtAki 39 * HITLS_X509_EXT_GET|SET_SKI HITLS_X509_ExtSki 40 * HITLS_X509_EXT_GET|SET_SAN HITLS_X509_ExtSan 41 * HITLS_X509_EXT_GET|SET_EXKUSAGE HITLS_X509_ExtExKeyUsage 42 * HITLS_X509_EXT_CHECK_SKI bool 43 * @param val [IN/OUT] input and output value 44 * @param valLen [In] value length 45 * @retval #HITLS_PKI_SUCCESS, success. 46 * Error codes can be found in hitls_pki_errno.h 47 */ 48 int32_t HITLS_X509_ExtCtrl(HITLS_X509_Ext *ext, int32_t cmd, void *val, uint32_t valLen); 49 50 /** 51 * @ingroup pki 52 * @brief Allocate a extension. 53 * 54 * @retval HITLS_X509_Ext * 55 */ 56 HITLS_X509_Ext *HITLS_X509_ExtNew(int32_t type); 57 58 /** 59 * @ingroup pki 60 * @brief Unallocate a extension. 61 * 62 * @param ext [IN] The extension. 63 */ 64 void HITLS_X509_ExtFree(HITLS_X509_Ext *ext); 65 66 /** 67 * @ingroup pki 68 * @brief clear the HITLS_X509_ExtAki structure. 69 * @par Description: This interface needs to be called to clean up memory when obtaining AKI extensions from 70 * certificates, CRLs, or CSRs using the macro HITLS_X509_EXT_GET_AKI. 71 * 72 * @param aki [IN] The HITLS_X509_ExtAki aki 73 */ 74 void HITLS_X509_ClearAuthorityKeyId(HITLS_X509_ExtAki *aki); 75 76 /** 77 * @ingroup pki 78 * @brief Free a general name. 79 * 80 * @param data [IN] The general name. 81 */ 82 void HITLS_X509_FreeGeneralName(HITLS_X509_GeneralName *data); 83 84 /** 85 * @ingroup pki 86 * @brief New a list of distinguish name, the item is HITLS_X509_NameNode. 87 * @attention You need to HITLS_X509_DnListFree to free list, after the end of use 88 * 89 * @retval #BslList *, success. 90 * error return NULL. 91 */ 92 BslList *HITLS_X509_DnListNew(void); 93 94 /** 95 * @ingroup pki 96 * @brief New a list of distinguish name, the list . 97 * 98 * @param list [IN] The name list 99 * @retval void 100 */ 101 void HITLS_X509_DnListFree(BslList *dnList); 102 103 /** 104 * @ingroup pki 105 * @brief Add a distinguish name array to list. 106 * 107 * @param list [IN] The name list 108 * @param dnNames [IN] dnName array 109 * @param size [IN] The count of dnName array 110 * @retval #HITLS_PKI_SUCCESS, success. 111 * Error codes can be found in hitls_pki_errno.h 112 */ 113 int32_t HITLS_X509_AddDnName(BslList *list, HITLS_X509_DN *dnNames, uint32_t size); 114 115 /** 116 * @ingroup pki 117 * @brief Generic function to process attribute function 118 * 119 * @param attributes [IN] The attribute list 120 * @param cmd [IN] HITLS_X509_AttrCmd 121 * @param val data type 122 * HITLS_X509_ATTR_XX_REQUESTED_EXTENSIONS HITLS_X509_Ext 123 * @param valLen The length of value. 124 * @retval #HITLS_PKI_SUCCESS, success. 125 * Error codes can be found in hitls_pki_errno.h 126 */ 127 int32_t HITLS_X509_AttrCtrl(HITLS_X509_Attrs *attributes, HITLS_X509_AttrCmd cmd, void *val, uint32_t valLen); 128 129 #ifdef __cplusplus 130 } 131 #endif 132 133 #endif // HITLS_PKI_UTILS_H 134