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 REC_READ_H 17 #define REC_READ_H 18 19 #include <stdint.h> 20 #include "rec.h" 21 #include "rec_buf.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #ifdef HITLS_TLS_PROTO_DTLS12 28 29 /** 30 * @brief Read a record in the DTLS protocol 31 * 32 * @param ctx [IN] TLS context 33 * @param recordType [IN] Record type 34 * @param data [OUT] Read data 35 * @param len [OUT] Read data length 36 * @param bufSize [IN] buffer length 37 * 38 * @retval HITLS_SUCCESS 39 * @retval HITLS_REC_NORMAL_RECV_BUF_EMPTY needs to be read again 40 * @retval HITLS_REC_ERR_IO_EXCEPTION I/O error 41 * @retval HITLS_REC_NORMAL_RECV_UNEXPECT_MSG Unexpected message received 42 * @retval HITLS_REC_NORMAL_RECV_DISORDER_MSG Receives out-of-order messages 43 * 44 */ 45 int32_t DtlsRecordRead(TLS_Ctx *ctx, REC_Type recordType, uint8_t *data, uint32_t *len, uint32_t bufSize); 46 47 #endif 48 49 /** 50 * @brief Read a record in the TLS protocol 51 * 52 * @param ctx [IN] TLS context 53 * @param recordType [IN] Record type 54 * @param data [OUT] Read data 55 * @param readLen [OUT] Length of the read data 56 * @param num [IN] The read buffer has num bytes 57 * 58 * @retval HITLS_SUCCESS 59 * @retval HITLS_REC_NORMAL_RECV_BUF_EMPTY needs to be read again 60 * @retval HITLS_REC_ERR_IO_EXCEPTION I/O error 61 * @retval HITLS_REC_ERR_SN_WRAPPING Sequence number wrap 62 * @retval HITLS_REC_NORMAL_RECV_UNEXPECT_MSG Unexpected message received 63 * 64 */ 65 int32_t TlsRecordRead(TLS_Ctx *ctx, REC_Type recordType, uint8_t *data, uint32_t *readLen, uint32_t num); 66 67 /** 68 * @brief Read data from the UIO of the TLS context to the inBuf 69 * 70 * @param ctx [IN] TLS context 71 * @param inBuf [IN] 72 * @param len [IN] len Length to be read 73 * 74 * @retval HITLS_SUCCESS 75 * @retval HITLS_REC_ERR_IO_EXCEPTION I/O error 76 * @retval HITLS_REC_NORMAL_RECV_BUF_EMPTY needs to be read again 77 */ 78 int32_t StreamRead(TLS_Ctx *ctx, RecBuf *inBuf, uint32_t len); 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif