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 #ifndef HITLS_COOKIE_H 18 #define HITLS_COOKIE_H 19 20 #include <stdint.h> 21 #include "hitls_type.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define HITLS_COOKIE_GENERATE_SUCCESS 1 /* Cookie Generated successfully */ 28 #define HITLS_COOKIE_GENERATE_ERROR 0 /* Cookie Generation failed */ 29 #define HITLS_COOKIE_VERIFY_SUCCESS 1 /* Cookie verification succeeded */ 30 #define HITLS_COOKIE_VERIFY_ERROR 0 /* Cookie verification failed */ 31 32 33 /** 34 * @ingroup hitls_config 35 * @brief Cookie Generation callback prototype for the server to process the callback. 36 * 37 * @param ctx [IN] Ctx context 38 * @param cookie [OUT] Generated cookie 39 * @param cookie_len [OUT] Length of Generated cookie 40 * @retval COOKIE_GEN_SUCCESS: successful. Other values are considered as failure. 41 */ 42 typedef int32_t (*HITLS_AppGenCookieCb)(HITLS_Ctx *ctx, uint8_t *cookie, uint32_t *cookieLen); 43 44 /** 45 * @ingroup hitls_config 46 * @brief Cookie Verification callback prototype for the server to process the callback. 47 * 48 * @param ctx [IN] Ctx context 49 * @param cookie [IN] Cookie to be verified 50 * @param cookie_len [IN] Length of Cookie to be verified 51 * @retval COOKIE_VERIFY_SUCCESS: successful. Other values are considered as failure. 52 */ 53 typedef int32_t (*HITLS_AppVerifyCookieCb)(HITLS_Ctx *ctx, const uint8_t *cookie, uint32_t cookieLen); 54 55 /** 56 * @ingroup hitls_config 57 * @brief Set the cookie generation callback on the server. 58 * 59 * @param config [OUT] Config context 60 * @param callback [IN] CookieGenerate callback 61 * @retval HITLS_SUCCESS, if successful. 62 * For details about other error codes, see hitls_error.h. 63 */ 64 int32_t HITLS_CFG_SetCookieGenCb(HITLS_Config *config, HITLS_AppGenCookieCb callback); 65 66 /** 67 * @ingroup hitls_config 68 * @brief Set the cookie verification callback on the server. 69 * 70 * @param config [OUT] Config context 71 * @param callback [IN] CookieVerify callback 72 * @retval HITLS_SUCCESS, if successful. 73 * For details about other error codes, see hitls_error.h. 74 */ 75 int32_t HITLS_CFG_SetCookieVerifyCb(HITLS_Config *config, HITLS_AppVerifyCookieCb callback); 76 77 #ifdef __cplusplus 78 } 79 #endif 80 81 #endif // HITLS_COOKIE_H