* This file is part of the openHiTLS project.
*
* openHiTLS is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
* @file hitls_cookie.h
* @brief DTLS cookie callback and helper definitions.
*/
* @defgroup hitls_cookie
* @ingroup tls
* @brief DTLS cookie generation and verification callbacks.
*/
#ifndef HITLS_COOKIE_H
#define HITLS_COOKIE_H
#include <stdint.h>
#include "hitls_type.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HITLS_COOKIE_GENERATE_SUCCESS 1
#define HITLS_COOKIE_GENERATE_ERROR 0
#define HITLS_COOKIE_VERIFY_SUCCESS 1
#define HITLS_COOKIE_VERIFY_ERROR 0
* @ingroup hitls_cookie
* @brief Cookie callback prototype generated by the server.
* @param ctx [IN] Ctx context.
* @param cookie [OUT] Cookie written back by the user.
* @param cookieLen [OUT] Cookie length written back by the user.
* @return HITLS_COOKIE_GENERATE_SUCCESS, indicates that the generation is successful.
HITLS_COOKIE_GENERATE_ERROR, indicates that the generation is failed.
*/
typedef int32_t (*HITLS_AppGenCookieCb)(HITLS_Ctx *ctx, uint8_t *cookie, uint32_t *cookieLen);
* @ingroup hitls_cookie
* @brief The server verifies the cookie callback prototype.
* @param ctx [IN] Ctx context.
* @param cookie [IN] Cookie received by the server.
* @param cookieLen [IN] Cookie length received by the server.
* @return HITLS_COOKIE_VERIFY_SUCCESS, indicates that the verification is successful.
HITLS_COOKIE_VERIFY_ERROR, indicates that the authentication fails.
*/
typedef int32_t (*HITLS_AppVerifyCookieCb)(HITLS_Ctx *ctx, const uint8_t *cookie, uint32_t cookieLen);
* @ingroup hitls_cookie
* @brief Sets the callback for generating cookies on the server.
* @param config [OUT] Config context.
* @param callback [IN] Cookie generate callback.
* @return HITLS_SUCCESS, if successful.
* For details about other error codes, see hitls_error.h.
*/
int32_t HITLS_CFG_SetCookieGenCb(HITLS_Config *config, HITLS_AppGenCookieCb callback);
* @ingroup hitls_cookie
* @brief Set the cookie verification callback on the server.
* @param config [OUT] Config context.
* @param callback [IN] Cookie verification callback.
* @return HITLS_SUCCESS, if successful.
* For details about other error codes, see hitls_error.h.
*/
int32_t HITLS_CFG_SetCookieVerifyCb(HITLS_Config *config, HITLS_AppVerifyCookieCb callback);
#ifdef __cplusplus
}
#endif
#endif