Cryptography Reference
In-Depth Information
parameters->unread_buffer = NULL;
parameters->unread_length = 0;
}
static int receive_tls_msg( int connection,
char *buffer,
int bufsz,
TLSParameters *parameters )
{
int bytes_read, accum_bytes;
int decrypted_length;
// First, check to see if there's any data left over from a previous read.
// If there is, pass that back up.
// This means that if the caller isn't quick about reading available data,
// TLS alerts can be missed.
if ( parameters->unread_buffer != NULL )
{
decrypted_message = parameters->unread_buffer;
decrypted_length = parameters->unread_length;
parameters->unread_buffer = NULL;
parameters->unread_length = 0;
message.type = content_application_data;
}
else
{
if ( recv( connection, header, 5, 0 ) <= 0 )
}
read_pos = decrypted_message;
else if ( message.type == content_application_data )
{
if ( decrypted_length <= bufsz )
{
memcpy( buffer, decrypted_message, decrypted_length );
}
else
{
// Need to hang on to a buffer of data here and pass it back for the
// next call
memcpy( buffer, decrypted_message, bufsz );
parameters->unread_length = decrypted_length - bufsz;
parameters->unread_buffer = malloc( parameters->unread_length );
memcpy( parameters->unread_buffer, decrypted_message + bufsz,
parameters->unread_length );
(Continued)
Search WWH ::




Custom Search