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 APP_H 17 #define APP_H 18 19 #include <stdint.h> 20 #include "hitls_build.h" 21 #include "tls.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /** 28 * @ingroup app 29 * @brief TLS can read data of any length, not in the unit of record. DTLS can read data in the unit of record. 30 * Reads num bytes from the CTX to the buffer. Users can transfer any num bytes (num must be greater than 0). 31 * 32 * @attention Reads only the application data decrypted by one record at a time. 33 * HITLS copies the application data to the input cache. 34 * If the cache size is less than 16K, the maximum size of the application message decrypted from a single record is 16K 35 * This will result in a partial copy of the application data. 36 * You can call APP_GetReadPendingBytes to obtain the size of the remaining readable application data in current record. 37 * This is useful in DTLS scenarios. 38 * 39 * @param ctx [IN] TLS context 40 * @param buf [OUT] Place the data which read from the TLS context into the buffer. 41 * @param num [IN] Attempting to read num bytes 42 * @param readLen [OUT] Read length 43 * 44 * @retval HITLS_SUCCESS Read successful. 45 * @retval Other return value refers to REC_Read. 46 */ 47 int32_t APP_Read(TLS_Ctx *ctx, uint8_t *buf, uint32_t num, uint32_t *readLen); 48 49 /** 50 * @ingroup app 51 * @brief Obtain the maximum writable plaintext length of a single record. 52 * 53 * @param ctx [IN] TLS_Ctx context 54 * @param len [OUT] Maximum length of the plaintext 55 * 56 * @retval HITLS_SUCCESS Obtain successful. 57 * @retval Other return value refers to REC_GetMaxWriteSize. 58 */ 59 int32_t APP_GetMaxWriteSize(const TLS_Ctx *ctx, uint32_t *len); 60 61 /** 62 * @ingroup app 63 * @brief Send app message in the unit of record. 64 * 65 * @param ctx [IN] TLS context 66 * @param data [IN] Data to be written 67 * @param dataLen [IN] Data length 68 * @param writeLen [OUT] Length of Successful Writes 69 * 70 * @retval HITLS_SUCCESS Write successful. 71 * @retval HITLS_APP_ERR_TOO_LONG_TO_WRITE The data to be written is too long. 72 * @retval Other reuturn value referst to REC_Write. 73 */ 74 int32_t APP_Write(TLS_Ctx *ctx, const uint8_t *data, uint32_t dataLen, uint32_t *writeLen); 75 76 #ifdef __cplusplus 77 } 78 #endif 79 80 #endif 81