• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SESSION_ENC_H
17 #define SESSION_ENC_H
18 
19 #include <stdint.h>
20 #include "hitls_type.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * Enumerated value of session information
28  * Do not change the enumerated value. If need add the enumerated value, add at the end
29  */
30 typedef enum {
31     SESS_OBJ_VERSION = 0x0101,
32     SESS_OBJ_CIPHER_SUITE = 0x0102,
33     SESS_OBJ_MASTER_SECRET = 0x0103,
34     SESS_OBJ_PEER_CERT = 0x0104,
35     SESS_OBJ_START_TIME = 0x0106,
36     SESS_OBJ_TIMEOUT = 0x0107,
37     SESS_OBJ_HOST_NAME = 0x0108,
38     SESS_OBJ_SESSION_ID_CTX = 0x0109,
39     SESS_OBJ_SESSION_ID = 0x010A,
40     SESS_OBJ_SUPPORT_EXTEND_MASTER_SECRET = 0x010B,
41     SESS_OBJ_VERIFY_RESULT = 0x010C,
42     SESS_OBJ_AGE_ADD = 0x010D,
43 } SessionObjType;
44 
45 /**
46  * @brief   Obtain the length of the encoded SESS information
47  *
48  * @param   sess [IN] sess structure
49  *
50  * @retval  Length of the encoded data
51  */
52 uint32_t SESS_GetTotalEncodeSize(const HITLS_Session *sess);
53 
54 /**
55  * @brief   Encode the SESS information to generate data
56  *
57  * @param   sess [IN] sess structure
58  * @param   data [OUT] Packed data
59  * @param   length [IN] Maximum length of the data array
60  * @param   usedLen [OUT] Data length after packing
61  *
62  * @retval  HITLS_SUCCESS
63  * @retval  For other error codes, see hitls_error.h
64  */
65 int32_t SESS_Encode(const HITLS_Session *sess, uint8_t *data, uint32_t length, uint32_t *usedLen);
66 
67 /**
68  * @brief   Decode data into SESS information
69  *
70  * @param   sess [OUT] sess structure
71  * @param   data [IN] Data to be parsed
72  * @param   length [IN] Length of the data to be parsed
73  *
74  * @retval  HITLS_SUCCESS
75  * @retval  For other error codes, see hitls_error.h
76  */
77 int32_t SESS_Decode(HITLS_Session *sess, const uint8_t *data, uint32_t length);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif
84