Introduce function to indicate if record is fully processed

This commit introduces a function ssl_record_is_in_progress()
to indicate if there is there is more data within the current
record to be processed. Further, it moves the corresponding
call from ssl_read_record_layer() to the parent function
mbedtls_ssl_read_record(). With this change, ssl_read_record_layer()
has the sole purpose of fetching and decoding a new record,
and hence this commit also renames it to ssl_get_next_record().
This commit is contained in:
Hanno Becker 2018-08-15 14:26:08 +01:00
parent 2699459529
commit e74d556b43

View file

@ -4286,7 +4286,8 @@ static void ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl );
/* Helper functions for mbedtls_ssl_read_record(). */
static int ssl_consume_current_message( mbedtls_ssl_context *ssl );
static int ssl_read_record_layer( mbedtls_ssl_context *ssl );
static int ssl_get_next_record( mbedtls_ssl_context *ssl );
static int ssl_record_is_in_progress( mbedtls_ssl_context *ssl );
int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl,
unsigned update_digest )
@ -4303,7 +4304,9 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl,
if( ret != 0 )
return( ret );
ret = ssl_read_record_layer( ssl );
if( ssl_record_is_in_progress( ssl ) == 0 )
{
ret = ssl_get_next_record( ssl );
if( ret == MBEDTLS_ERR_SSL_CONTINUE_PROCESSING )
continue;
@ -4312,6 +4315,7 @@ int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_DEBUG_RET( 1, ( "mbedtls_ssl_read_record_layer" ), ret );
return( ret );
}
}
ret = mbedtls_ssl_handle_message_type( ssl );
@ -4428,22 +4432,22 @@ static int ssl_consume_current_message( mbedtls_ssl_context *ssl )
return( 0 );
}
static int ssl_read_record_layer( mbedtls_ssl_context *ssl )
static int ssl_record_is_in_progress( mbedtls_ssl_context *ssl )
{
if( ssl->in_msglen > 0 )
return( 1 );
return( 0 );
}
static int ssl_get_next_record( mbedtls_ssl_context *ssl )
{
int ret;
/*
* Fetch and decode new record if current one is fully consumed.
* Fetch and decode new record
*/
if( ssl->in_msglen > 0 )
{
/* There's something left to be processed in the current record. */
return( 0 );
}
/* Current record either fully processed or to be discarded. */
if( ( ret = mbedtls_ssl_fetch_input( ssl, mbedtls_ssl_hdr_len( ssl ) ) ) != 0 )
{
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_fetch_input", ret );