mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-15 00:02:49 +03:00
Merge pull request #23 from me-no-dev/add-send-calculator
add send packet size calculator
This commit is contained in:
@ -296,6 +296,15 @@ EXP_FUNC int STDCALL ssl_read(SSL *ssl, uint8_t **in_data);
|
||||
*/
|
||||
EXP_FUNC int STDCALL ssl_write(SSL *ssl, const uint8_t *out_data, int out_len);
|
||||
|
||||
/**
|
||||
* @brief Calculate the size of the encrypted data from what you are about to send
|
||||
* @param ssl [in] An SSL obect reference.
|
||||
* @param out_len [in] The number of bytes to be written.
|
||||
* @return The number of bytes that will be sent, or if < 0 if an error.
|
||||
* @see ssl.h for the error code list.
|
||||
*/
|
||||
EXP_FUNC int STDCALL ssl_calculate_write_length(SSL *ssl, int out_len);
|
||||
|
||||
/**
|
||||
* @brief Find an ssl object based on a file descriptor.
|
||||
*
|
||||
|
29
ssl/tls1.c
29
ssl/tls1.c
@ -315,6 +315,35 @@ EXP_FUNC int STDCALL ssl_write(SSL *ssl, const uint8_t *out_data, int out_len)
|
||||
return out_len;
|
||||
}
|
||||
|
||||
EXP_FUNC int STDCALL ssl_calculate_write_length(SSL *ssl, int length)
|
||||
{
|
||||
int msg_length = 0;
|
||||
if (ssl->hs_status == SSL_ERROR_DEAD)
|
||||
return SSL_ERROR_CONN_LOST;
|
||||
|
||||
if (ssl->flag & SSL_SENT_CLOSE_NOTIFY)
|
||||
return SSL_CLOSE_NOTIFY;
|
||||
|
||||
msg_length += length;
|
||||
|
||||
if (ssl->flag & SSL_TX_ENCRYPTED)
|
||||
{
|
||||
msg_length += ssl->cipher_info->digest_size;
|
||||
{
|
||||
int last_blk_size = msg_length%ssl->cipher_info->padding_size;
|
||||
int pad_bytes = ssl->cipher_info->padding_size - last_blk_size;
|
||||
if (pad_bytes == 0)
|
||||
pad_bytes += ssl->cipher_info->padding_size;
|
||||
msg_length += pad_bytes;
|
||||
}
|
||||
if (ssl->version >= SSL_PROTOCOL_VERSION_TLS1_1)
|
||||
{
|
||||
msg_length += ssl->cipher_info->iv_size;
|
||||
}
|
||||
}
|
||||
return SSL_RECORD_SIZE+msg_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a certificate to the certificate chain.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user