Move MPS reader to mbedtls_mps_ namespace

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
This commit is contained in:
Hanno Becker 2021-01-28 09:45:47 +00:00
parent 984fbded58
commit 8899396fd1
4 changed files with 271 additions and 271 deletions

View File

@ -81,7 +81,7 @@
/*! An invalid argument was passed to the reader. */
#define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR( 0x2 )
/*! An attempt to move a reader to consuming mode through mbedtls_reader_feed()
/*! An attempt to move a reader to consuming mode through mbedtls_mps_reader_feed()
* after pausing failed because the provided data is not sufficient to serve the
* the read requests that lead to the pausing. */
#define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR( 0x3 )

View File

@ -66,7 +66,7 @@ static int mbedtls_mps_trace_id = MBEDTLS_MPS_TRACE_BIT_READER;
*
*/
static inline void mps_reader_zero( mbedtls_reader *rd )
static inline void mps_reader_zero( mbedtls_mps_reader *rd )
{
/* A plain memset() would likely be more efficient,
* but the current way of zeroing makes it harder
@ -74,7 +74,7 @@ static inline void mps_reader_zero( mbedtls_reader *rd )
* It's also more suitable for VF efforts since it
* doesn't require reasoning about structs being
* interpreted as unstructured binary blobs. */
static mbedtls_reader const zero =
static mbedtls_mps_reader const zero =
{ .frag = NULL,
.frag_len = 0,
.commit = 0,
@ -88,9 +88,9 @@ static inline void mps_reader_zero( mbedtls_reader *rd )
*rd = zero;
}
int mbedtls_reader_init( mbedtls_reader *rd,
unsigned char *acc,
mbedtls_mps_size_t acc_len )
int mbedtls_mps_reader_init( mbedtls_mps_reader *rd,
unsigned char *acc,
mbedtls_mps_size_t acc_len )
{
MBEDTLS_MPS_TRACE_INIT( "reader_init, acc len %u", (unsigned) acc_len );
mps_reader_zero( rd );
@ -99,16 +99,16 @@ int mbedtls_reader_init( mbedtls_reader *rd,
MBEDTLS_MPS_TRACE_RETURN( 0 );
}
int mbedtls_reader_free( mbedtls_reader *rd )
int mbedtls_mps_reader_free( mbedtls_mps_reader *rd )
{
MBEDTLS_MPS_TRACE_INIT( "reader_free" );
mps_reader_zero( rd );
MBEDTLS_MPS_TRACE_RETURN( 0 );
}
int mbedtls_reader_feed( mbedtls_reader *rd,
unsigned char *new_frag,
mbedtls_mps_size_t new_frag_len )
int mbedtls_mps_reader_feed( mbedtls_mps_reader *rd,
unsigned char *new_frag,
mbedtls_mps_size_t new_frag_len )
{
unsigned char *acc;
mbedtls_mps_size_t copy_to_acc;
@ -119,7 +119,7 @@ int mbedtls_reader_feed( mbedtls_reader *rd,
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_INVALID_ARG );
MBEDTLS_MPS_STATE_VALIDATE_RAW( rd->frag == NULL,
"mbedtls_reader_feed() requires reader to be in producing mode" );
"mbedtls_mps_reader_feed() requires reader to be in producing mode" );
acc = rd->acc;
if( acc != NULL )
@ -173,10 +173,10 @@ int mbedtls_reader_feed( mbedtls_reader *rd,
}
int mbedtls_reader_get( mbedtls_reader *rd,
mbedtls_mps_size_t desired,
unsigned char **buffer,
mbedtls_mps_size_t *buflen )
int mbedtls_mps_reader_get( mbedtls_mps_reader *rd,
mbedtls_mps_size_t desired,
unsigned char **buffer,
mbedtls_mps_size_t *buflen )
{
unsigned char *frag, *acc;
mbedtls_mps_size_t end, fo, fl, frag_fetched, frag_remaining;
@ -185,7 +185,7 @@ int mbedtls_reader_get( mbedtls_reader *rd,
frag = rd->frag;
MBEDTLS_MPS_STATE_VALIDATE_RAW( frag != NULL,
"mbedtls_reader_get() requires reader to be in consuming mode" );
"mbedtls_mps_reader_get() requires reader to be in consuming mode" );
/* The fragment offset indicates the offset of the fragment
* from the accmulator, if the latter is present. Use a offset
@ -269,7 +269,7 @@ int mbedtls_reader_get( mbedtls_reader *rd,
* fo/frag_offset aa/acc_avail
*
* In case of Allowed #1 and #2 we're switching to serve from
* `frag` starting from the next call to mbedtls_reader_get().
* `frag` starting from the next call to mbedtls_mps_reader_get().
*/
mbedtls_mps_size_t aa;
@ -348,14 +348,14 @@ int mbedtls_reader_get( mbedtls_reader *rd,
MBEDTLS_MPS_TRACE_RETURN( 0 );
}
int mbedtls_reader_commit( mbedtls_reader *rd )
int mbedtls_mps_reader_commit( mbedtls_mps_reader *rd )
{
unsigned char *acc;
mbedtls_mps_size_t aa, end, fo, shift;
MBEDTLS_MPS_TRACE_INIT( "reader_commit" );
MBEDTLS_MPS_STATE_VALIDATE_RAW( rd->frag != NULL,
"mbedtls_reader_commit() requires reader to be in consuming mode" );
"mbedtls_mps_reader_commit() requires reader to be in consuming mode" );
acc = rd->acc;
end = rd->end;
@ -400,8 +400,8 @@ int mbedtls_reader_commit( mbedtls_reader *rd )
MBEDTLS_MPS_TRACE_RETURN( 0 );
}
int mbedtls_reader_reclaim( mbedtls_reader *rd,
mbedtls_mps_size_t *paused )
int mbedtls_mps_reader_reclaim( mbedtls_mps_reader *rd,
mbedtls_mps_size_t *paused )
{
unsigned char *frag, *acc;
mbedtls_mps_size_t pending, commit;
@ -413,7 +413,7 @@ int mbedtls_reader_reclaim( mbedtls_reader *rd,
frag = rd->frag;
MBEDTLS_MPS_STATE_VALIDATE_RAW( frag != NULL,
"mbedtls_reader_reclaim() requires reader to be in consuming mode" );
"mbedtls_mps_reader_reclaim() requires reader to be in consuming mode" );
acc = rd->acc;
pending = rd->pending;

View File

@ -57,9 +57,9 @@
* From the perspective of the consumer, the state of the
* reader is a potentially empty list of input buffers that
* the reader has provided to the consumer.
* New buffers can be requested through calls to mbedtls_reader_get(),
* New buffers can be requested through calls to mbedtls_mps_reader_get(),
* while previously obtained input buffers can be marked processed
* through calls to mbedtls_reader_consume(), emptying the list of
* through calls to mbedtls_mps_reader_consume(), emptying the list of
* input buffers and invalidating them from the consumer's perspective.
* The consumer need not be aware of the distinction between consumer
* and producer mode, because he only interfaces with the reader
@ -82,9 +82,9 @@
* while the Attached state belongs to consuming mode.
*
* Transitioning from Unset or Accumulating to Attached is
* done via calls to mbedtls_reader_feed(), while transitioning
* done via calls to mbedtls_mps_reader_feed(), while transitioning
* from Consuming to either Unset or Accumulating (depending
* on what has been processed) is done via mbedtls_reader_reclaim().
* on what has been processed) is done via mbedtls_mps_reader_reclaim().
*
* The following diagram depicts the producer-state progression:
*
@ -119,18 +119,18 @@
#include "mps_common.h"
#include "mps_error.h"
struct mbedtls_reader;
typedef struct mbedtls_reader mbedtls_reader;
struct mbedtls_mps_reader;
typedef struct mbedtls_mps_reader mbedtls_mps_reader;
/*
* Structure definitions
*/
struct mbedtls_reader
struct mbedtls_mps_reader
{
unsigned char *frag; /*!< The fragment of incoming data managed by
* the reader; it is provided to the reader
* through mbedtls_reader_feed(). The reader
* through mbedtls_mps_reader_feed(). The reader
* does not own the fragment and does not
* perform any allocation operations on it,
* but does have read and write access to it. */
@ -146,18 +146,18 @@ struct mbedtls_reader
mbedtls_mps_stored_size_t end;
/*!< The offset of the end of the last chunk
* passed to the user through a call to
* mbedtls_reader_get(), relative to the first
* mbedtls_mps_reader_get(), relative to the first
* byte in the accumulator.
* This is only used when the reader is in
* consuming mode, i.e. \c frag != \c NULL;
* otherwise, its value is \c 0. */
mbedtls_mps_stored_size_t pending;
/*!< The amount of incoming data missing on the
* last call to mbedtls_reader_get().
* last call to mbedtls_mps_reader_get().
* In particular, it is \c 0 if the last call
* was successful.
* If a reader is reclaimed after an
* unsuccessful call to mbedtls_reader_get(),
* unsuccessful call to mbedtls_mps_reader_get(),
* this variable is used to have the reader
* remember how much data should be accumulated
* before the reader can be passed back to
@ -171,7 +171,7 @@ struct mbedtls_reader
* separate struct and using a pointer here. */
unsigned char *acc; /*!< The accumulator is used to gather incoming
* data if a read-request via mbedtls_reader_get()
* data if a read-request via mbedtls_mps_reader_get()
* cannot be served from the current fragment. */
mbedtls_mps_stored_size_t acc_len;
/*!< The total size of the accumulator. */
@ -218,8 +218,8 @@ struct mbedtls_reader
*
* \param reader The reader to be initialized.
* \param acc The buffer to be used as a temporary accumulator
* in case read requests through mbedtls_reader_get()
* exceed the buffer provided by mbedtls_reader_feed().
* in case read requests through mbedtls_mps_reader_get()
* exceed the buffer provided by mbedtls_mps_reader_feed().
* This buffer is owned by the caller and exclusive use
* for reading and writing is given to the reade for the
* duration of the reader's lifetime. It is thus the caller's
@ -231,9 +231,9 @@ struct mbedtls_reader
* \return \c 0 on success.
* \return A negative \c MBEDTLS_ERR_READER_XXX error code on failure.
*/
int mbedtls_reader_init( mbedtls_reader *reader,
unsigned char *acc,
mbedtls_mps_size_t acc_len );
int mbedtls_mps_reader_init( mbedtls_mps_reader *reader,
unsigned char *acc,
mbedtls_mps_size_t acc_len );
/**
* \brief Free a reader object
@ -243,7 +243,7 @@ int mbedtls_reader_init( mbedtls_reader *reader,
* \return \c 0 on success.
* \return A negative \c MBEDTLS_ERR_READER_XXX error code on failure.
*/
int mbedtls_reader_free( mbedtls_reader *reader );
int mbedtls_mps_reader_free( mbedtls_mps_reader *reader );
/**
* \brief Pass chunk of data for the reader to manage.
@ -255,19 +255,19 @@ int mbedtls_reader_free( mbedtls_reader *reader );
*
* \return \c 0 on success. In this case, the reader will be
* moved to consuming state, and ownership of \p buf
* will be passed to the reader until mbedtls_reader_reclaim()
* will be passed to the reader until mbedtls_mps_reader_reclaim()
* is called.
* \return \c MBEDTLS_ERR_MPS_READER_NEED_MORE if more input data is
* required to fulfill a previous request to mbedtls_reader_get().
* required to fulfill a previous request to mbedtls_mps_reader_get().
* In this case, the reader remains in producing state and
* takes no ownership of the provided buffer (an internal copy
* is made instead).
* \return Another negative \c MBEDTLS_ERR_READER_XXX error code on
* different kinds of failures.
*/
int mbedtls_reader_feed( mbedtls_reader *reader,
unsigned char *buf,
mbedtls_mps_size_t buflen );
int mbedtls_mps_reader_feed( mbedtls_mps_reader *reader,
unsigned char *buf,
mbedtls_mps_size_t buflen );
/**
* \brief Reclaim reader's access to the current input buffer.
@ -278,14 +278,14 @@ int mbedtls_reader_feed( mbedtls_reader *reader,
* modified to indicate whether the reader has been paused
* (value \c 1) or not (value \c 0). Pausing happens if there
* is uncommitted data and a previous request to
* mbedtls_reader_get() has exceeded the bounds of the
* mbedtls_mps_reader_get() has exceeded the bounds of the
* input buffer.
*
* \return \c 0 on success.
* \return A negative \c MBEDTLS_ERR_READER_XXX error code on failure.
*/
int mbedtls_reader_reclaim( mbedtls_reader *reader,
mbedtls_mps_size_t *paused );
int mbedtls_mps_reader_reclaim( mbedtls_mps_reader *reader,
mbedtls_mps_size_t *paused );
/*
* Usage API (Upper layer)
@ -306,14 +306,14 @@ int mbedtls_reader_reclaim( mbedtls_reader *reader,
* address of a buffer of size \c *buflen
* (if \c buflen != \c NULL) or \c desired
* (if \c buflen == \c NULL). The user hass ownership
* of the buffer until the next call to mbedtls_reader_commit().
* or mbedtls_reader_reclaim().
* of the buffer until the next call to mbedtls_mps_reader_commit().
* or mbedtls_mps_reader_reclaim().
* \return #MBEDTLS_ERR_MPS_READER_OUT_OF_DATA if there is not enough
* data available to serve the read request. In this case,
* the reader remains intact, and additional data can be
* provided by reclaiming the current input buffer via
* mbedtls_reader_reclaim() and feeding a new one via
* mbedtls_reader_feed().
* mbedtls_mps_reader_reclaim() and feeding a new one via
* mbedtls_mps_reader_feed().
* \return Another negative \c MBEDTLS_ERR_READER_XXX error
* code for different kinds of failure.
*
@ -323,10 +323,10 @@ int mbedtls_reader_reclaim( mbedtls_reader *reader,
* address as buflen and checking \c *buflen == \c desired
* afterwards.
*/
int mbedtls_reader_get( mbedtls_reader *reader,
mbedtls_mps_size_t desired,
unsigned char **buffer,
mbedtls_mps_size_t *buflen );
int mbedtls_mps_reader_get( mbedtls_mps_reader *reader,
mbedtls_mps_size_t desired,
unsigned char **buffer,
mbedtls_mps_size_t *buflen );
/**
* \brief Signal that all input buffers previously obtained
@ -344,6 +344,6 @@ int mbedtls_reader_get( mbedtls_reader *reader,
* pointers corresponding to the committed data anymore.
*
*/
int mbedtls_reader_commit( mbedtls_reader *reader );
int mbedtls_mps_reader_commit( mbedtls_mps_reader *reader );
#endif /* MBEDTLS_READER_H */

View File

@ -40,24 +40,24 @@ void mbedtls_mps_reader_no_pausing_single_step_single_round( int with_acc )
unsigned char bufA[100];
unsigned char acc[10];
unsigned char *tmp;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( bufA ); i++ )
bufA[i] = (unsigned char) i;
/* Preparation (lower layer) */
if( with_acc == 0 )
mbedtls_reader_init( &rd, NULL, 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
else
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
/* Consumption (upper layer) */
/* Consume exactly what's available */
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 100, bufA, 100 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup (lower layer) */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -82,7 +82,7 @@ void mbedtls_mps_reader_no_pausing_single_step_multiple_rounds( int with_acc )
unsigned char bufA[100], bufB[100];
unsigned char acc[10];
unsigned char *tmp;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( bufA ); i++ )
bufA[i] = (unsigned char) i;
for( int i=0; (unsigned) i < sizeof( bufB ); i++ )
@ -90,25 +90,25 @@ void mbedtls_mps_reader_no_pausing_single_step_multiple_rounds( int with_acc )
/* Preparation (lower layer) */
if( with_acc == 0 )
mbedtls_reader_init( &rd, NULL, 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
else
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
/* Consumption (upper layer) */
/* Consume exactly what's available */
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 100, bufA, 100 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
/* Consumption */
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 100, bufB, 100 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup (lower layer) */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -118,7 +118,7 @@ void mbedtls_mps_reader_no_pausing_multiple_steps_single_round( int with_acc )
/* This test exercises one round of the following:
* - The 'producing' layer provides a buffer
* - The 'consuming' layer fetches it in multiple calls
* to `mbedtls_reader_get()`, without comitting in between.
* to `mbedtls_mps_reader_get()`, without comitting in between.
* - After processing, the consuming layer commit the data
* and returns back to the producing layer.
*
@ -137,27 +137,27 @@ void mbedtls_mps_reader_no_pausing_multiple_steps_single_round( int with_acc )
unsigned char acc[10];
unsigned char *tmp;
mbedtls_mps_size_t tmp_len;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
buf[i] = (unsigned char) i;
/* Preparation (lower layer) */
if( with_acc == 0 )
mbedtls_reader_init( &rd, NULL, 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
else
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, buf, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 70, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 70, buf + 10, 70 );
TEST_ASSERT( mbedtls_reader_get( &rd, 30, &tmp, &tmp_len ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, &tmp_len ) == 0 );
ASSERT_COMPARE( tmp, tmp_len, buf + 80, 20 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup (lower layer) */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -172,7 +172,7 @@ void mbedtls_mps_reader_no_pausing_multiple_steps_multiple_rounds( int with_acc
unsigned char acc[10];
unsigned char *tmp;
mbedtls_mps_size_t tmp_len;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( bufA ); i++ )
bufA[i] = (unsigned char) i;
for( int i=0; (unsigned) i < sizeof( bufB ); i++ )
@ -180,28 +180,28 @@ void mbedtls_mps_reader_no_pausing_multiple_steps_multiple_rounds( int with_acc
/* Preparation (lower layer) */
if( with_acc == 0 )
mbedtls_reader_init( &rd, NULL, 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
else
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 70, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 70, bufA + 10, 70 );
TEST_ASSERT( mbedtls_reader_get( &rd, 30, &tmp, &tmp_len ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, &tmp_len ) == 0 );
ASSERT_COMPARE( tmp, tmp_len, bufA + 80, 20 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
/* Consumption */
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 100, bufB, 100 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -217,23 +217,23 @@ void mbedtls_mps_reader_pausing_needed_disabled()
unsigned char buf[100];
unsigned char *tmp;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
buf[i] = (unsigned char) i;
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, NULL, 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf, 50 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Wrapup (lower layer) */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR );
mbedtls_reader_free( &rd );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -250,23 +250,23 @@ void mbedtls_mps_reader_pausing_needed_buffer_too_small()
unsigned char buf[100];
unsigned char acc[10];
unsigned char *tmp;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
buf[i] = (unsigned char) i;
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf, 50 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Wrapup (lower layer) */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
mbedtls_reader_free( &rd );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -293,89 +293,89 @@ void mbedtls_mps_reader_pausing( int option )
unsigned char bufA[100], bufB[100];
unsigned char *tmp;
unsigned char acc[40];
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( bufA ); i++ )
bufA[i] = (unsigned char) i;
for( int i=0; (unsigned) i < sizeof( bufB ); i++ )
bufB[i] = ~ ((unsigned char) i);
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
/* Consumption (upper layer) */
/* Ask for more than what's available. */
TEST_ASSERT( mbedtls_reader_get( &rd, 80, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 80, bufA, 80 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
switch( option )
{
case 0: /* Single uncommitted fetch at pausing */
case 1:
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
break;
default: /* Multiple uncommitted fetches at pausing */
break;
}
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
/* Consumption */
switch( option )
{
case 0: /* Single fetch at pausing, re-fetch with commit. */
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
break;
case 1: /* Single fetch at pausing, re-fetch without commit. */
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
break;
case 2: /* Multiple fetches at pausing, repeat without commit. */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
break;
case 3: /* Multiple fetches at pausing, repeat with commit 1. */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
break;
case 4: /* Multiple fetches at pausing, repeat with commit 2. */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
break;
case 5: /* Multiple fetches at pausing, repeat with commit 3. */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
break;
default:
@ -383,13 +383,13 @@ void mbedtls_mps_reader_pausing( int option )
}
/* In all cases, fetch the rest of the second buffer. */
TEST_ASSERT( mbedtls_reader_get( &rd, 90, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 90, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 90, bufB + 10, 90 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -400,8 +400,8 @@ void mbedtls_mps_reader_pausing_multiple_feeds( int option )
* in the following situation:
* - The consumer has asked for mre than what's available, so the
* reader pauses and waits for further input data via
* `mbedtls_reader_feed()`
* - Multiple such calls to `mbedtls_reader_feed()` are necessary
* `mbedtls_mps_reader_feed()`
* - Multiple such calls to `mbedtls_mps_reader_feed()` are necessary
* to fulfill the original request, and the reader needs to do
* the necessary bookkeeping under the hood.
*
@ -413,7 +413,7 @@ void mbedtls_mps_reader_pausing_multiple_feeds( int option )
unsigned char bufA[100], bufB[100];
unsigned char *tmp;
unsigned char acc[70];
mbedtls_reader rd;
mbedtls_mps_reader rd;
mbedtls_mps_size_t fetch_len;
for( int i=0; (unsigned) i < sizeof( bufA ); i++ )
bufA[i] = (unsigned char) i;
@ -421,46 +421,46 @@ void mbedtls_mps_reader_pausing_multiple_feeds( int option )
bufB[i] = ~ ((unsigned char) i);
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
/* Consumption (upper layer) */
/* Ask for more than what's available. */
TEST_ASSERT( mbedtls_reader_get( &rd, 80, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 80, bufA, 80 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* 20 left, ask for 70 -> 50 overhead */
TEST_ASSERT( mbedtls_reader_get( &rd, 70, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
switch( option )
{
case 0: /* 10 + 10 + 80 byte feed */
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB, 10 ) ==
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, 10 ) ==
MBEDTLS_ERR_MPS_READER_NEED_MORE );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB + 10, 10 ) ==
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 10, 10 ) ==
MBEDTLS_ERR_MPS_READER_NEED_MORE );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB + 20, 80 ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 20, 80 ) == 0 );
break;
case 1: /* 50 x 1byte */
for( int num_feed=0; num_feed<49; num_feed++ )
{
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB + num_feed, 1 ) ==
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + num_feed, 1 ) ==
MBEDTLS_ERR_MPS_READER_NEED_MORE );
}
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB + 49, 1 ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 49, 1 ) == 0 );
break;
case 2: /* 49 x 1byte + 51bytes */
for( int num_feed=0; num_feed<49; num_feed++ )
{
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB + num_feed, 1 ) ==
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + num_feed, 1 ) ==
MBEDTLS_ERR_MPS_READER_NEED_MORE );
}
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB + 49, 51 ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB + 49, 51 ) == 0 );
break;
default:
@ -469,10 +469,10 @@ void mbedtls_mps_reader_pausing_multiple_feeds( int option )
}
/* Consumption */
TEST_ASSERT( mbedtls_reader_get( &rd, 70, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 70, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
ASSERT_COMPARE( tmp + 20, 50, bufB, 50 );
TEST_ASSERT( mbedtls_reader_get( &rd, 1000, &tmp, &fetch_len ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 1000, &tmp, &fetch_len ) == 0 );
switch( option )
{
case 0:
@ -491,11 +491,11 @@ void mbedtls_mps_reader_pausing_multiple_feeds( int option )
TEST_ASSERT( 0 );
break;
}
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -504,32 +504,32 @@ void mbedtls_mps_reader_pausing_multiple_feeds( int option )
void mbedtls_mps_reader_reclaim_data_left( int option )
{
/* This test exercises the behaviour of the MPS reader when a
* call to mbedtls_reader_reclaim() is made before all data
* call to mbedtls_mps_reader_reclaim() is made before all data
* provided by the producer has been fetched and committed. */
unsigned char buf[100];
unsigned char *tmp;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
buf[i] = (unsigned char) i;
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, NULL, 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
switch( option )
{
case 0:
/* Fetch (but not commit) the entire buffer. */
TEST_ASSERT( mbedtls_reader_get( &rd, sizeof( buf ), &tmp, NULL )
TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ), &tmp, NULL )
== 0 );
ASSERT_COMPARE( tmp, 100, buf, 100 );
break;
case 1:
/* Fetch (but not commit) parts of the buffer. */
TEST_ASSERT( mbedtls_reader_get( &rd, sizeof( buf ) / 2,
TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ) / 2,
&tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, sizeof( buf ) / 2, buf, sizeof( buf ) / 2 );
break;
@ -537,11 +537,11 @@ void mbedtls_mps_reader_reclaim_data_left( int option )
case 2:
/* Fetch and commit parts of the buffer, then
* fetch but not commit the rest of the buffer. */
TEST_ASSERT( mbedtls_reader_get( &rd, sizeof( buf ) / 2,
TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ) / 2,
&tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, sizeof( buf ) / 2, buf, sizeof( buf ) / 2 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, sizeof( buf ) / 2,
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, sizeof( buf ) / 2,
&tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, sizeof( buf ) / 2,
buf + sizeof( buf ) / 2,
@ -554,9 +554,9 @@ void mbedtls_mps_reader_reclaim_data_left( int option )
}
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
MBEDTLS_ERR_MPS_READER_DATA_LEFT );
mbedtls_reader_free( &rd );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -568,30 +568,30 @@ void mbedtls_mps_reader_reclaim_data_left_retry()
* to be processed, and the consumer subsequently fetches more data. */
unsigned char buf[100];
unsigned char *tmp;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
buf[i] = (unsigned char) i;
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, NULL, 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf, 50 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf + 50, 50 );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
MBEDTLS_ERR_MPS_READER_DATA_LEFT );
/* Consumption */
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf + 50, 50 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -600,7 +600,7 @@ void mbedtls_mps_reader_multiple_pausing( int option )
{
/* This test exercises the behaviour of the MPS reader
* in the following situation:
* - A read request via `mbedtls_reader_get()` can't
* - A read request via `mbedtls_mps_reader_get()` can't
* be served and the reader is paused to accumulate
* the desired amount of data from the producer.
* - Once enough data is availble, the consumer successfully
@ -613,7 +613,7 @@ void mbedtls_mps_reader_multiple_pausing( int option )
unsigned char *tmp;
unsigned char acc[50];
mbedtls_mps_size_t tmp_len;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( bufA ); i++ )
bufA[i] = (unsigned char) i;
for( int i=0; (unsigned) i < sizeof( bufB ); i++ )
@ -622,22 +622,22 @@ void mbedtls_mps_reader_multiple_pausing( int option )
bufC[i] = ~ ((unsigned char) i);
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
/* Consumption (upper layer) */
/* Ask for more than what's available. */
TEST_ASSERT( mbedtls_reader_get( &rd, 80, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 80, bufA, 80 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
switch( option )
{
@ -646,21 +646,21 @@ void mbedtls_mps_reader_multiple_pausing( int option )
* large enough. */
/* Consume */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, &tmp_len ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, &tmp_len ) == 0 );
ASSERT_COMPARE( tmp, tmp_len, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Prepare */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufC, sizeof( bufC ) ) == 0 );;
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufC, sizeof( bufC ) ) == 0 );;
/* Consume */
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufB + 10, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufC, 10 );
break;
@ -668,37 +668,37 @@ void mbedtls_mps_reader_multiple_pausing( int option )
case 1: /* Fetch same chunks, commit afterwards, and
* then exceed bounds of new buffer; accumulator
* not large enough. */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 51, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 51, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Prepare */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
break;
case 2: /* Fetch same chunks, don't commit afterwards, and
* then exceed bounds of new buffer; accumulator
* large enough. */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Prepare */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufC, sizeof( bufC ) ) == 0 );;
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufC, sizeof( bufC ) ) == 0 );;
/* Consume */
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
ASSERT_COMPARE( tmp + 20, 20, bufB, 20 );
ASSERT_COMPARE( tmp + 40, 10, bufC, 10 );
@ -707,16 +707,16 @@ void mbedtls_mps_reader_multiple_pausing( int option )
case 3: /* Fetch same chunks, don't commit afterwards, and
* then exceed bounds of new buffer; accumulator
* not large enough. */
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 80, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 10, bufA + 90, 10 );
ASSERT_COMPARE( tmp + 10, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_get( &rd, 21, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 21, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Prepare */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) ==
MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
break;
@ -725,7 +725,7 @@ void mbedtls_mps_reader_multiple_pausing( int option )
break;
}
mbedtls_reader_free( &rd );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -771,7 +771,7 @@ void mbedtls_mps_reader_random_usage( int num_out_chunks,
int mode = 0; /* Lower layer (0) or Upper layer (1) */
int reclaimed = 1; /* Have to call reclaim at least once before
* returning the reader to the upper layer. */
mbedtls_reader rd;
mbedtls_mps_reader rd;
if( acc_size > 0 )
{
@ -785,7 +785,7 @@ void mbedtls_mps_reader_random_usage( int num_out_chunks,
ASSERT_ALLOC( outgoing, num_out_chunks * max_chunk_size );
ASSERT_ALLOC( incoming, num_out_chunks * max_chunk_size );
mbedtls_reader_init( &rd, acc, acc_size );
mbedtls_mps_reader_init( &rd, acc, acc_size );
cur_out_chunk = 0;
in_commit = 0;
@ -801,7 +801,7 @@ void mbedtls_mps_reader_random_usage( int num_out_chunks,
if( rand_op == 0 )
{
/* Reclaim */
ret = mbedtls_reader_reclaim( &rd, NULL );
ret = mbedtls_mps_reader_reclaim( &rd, NULL );
if( ret == 0 )
{
@ -823,7 +823,7 @@ void mbedtls_mps_reader_random_usage( int num_out_chunks,
ASSERT_ALLOC( tmp, tmp_size );
TEST_ASSERT( mbedtls_test_rnd_std_rand( NULL, tmp, tmp_size ) == 0 );
ret = mbedtls_reader_feed( &rd, tmp, tmp_size );
ret = mbedtls_mps_reader_feed( &rd, tmp, tmp_size );
if( ret == 0 || ret == MBEDTLS_ERR_MPS_READER_NEED_MORE )
{
@ -864,13 +864,13 @@ void mbedtls_mps_reader_random_usage( int num_out_chunks,
get_size = ( rand() % max_request ) + 1;
if( rand_op == 0 )
{
ret = mbedtls_reader_get( &rd, get_size, &chunk_get,
ret = mbedtls_mps_reader_get( &rd, get_size, &chunk_get,
&real_size );
}
else
{
real_size = get_size;
ret = mbedtls_reader_get( &rd, get_size, &chunk_get, NULL );
ret = mbedtls_mps_reader_get( &rd, get_size, &chunk_get, NULL );
}
/* Check if output is in accordance with what was written */
@ -886,7 +886,7 @@ void mbedtls_mps_reader_random_usage( int num_out_chunks,
}
else if( rand_op == 2 ) /* Commit */
{
ret = mbedtls_reader_commit( &rd );
ret = mbedtls_mps_reader_commit( &rd );
if( ret == 0 )
{
in_commit += in_fetch;
@ -904,7 +904,7 @@ void mbedtls_mps_reader_random_usage( int num_out_chunks,
}
/* Cleanup */
mbedtls_reader_free( &rd );
mbedtls_mps_reader_free( &rd );
mbedtls_free( incoming );
mbedtls_free( outgoing );
mbedtls_free( acc );
@ -931,7 +931,7 @@ void mbedtls_reader_inconsistent_usage( int option )
unsigned char bufA[100], bufB[100];
unsigned char *tmp;
unsigned char acc[40];
mbedtls_reader rd;
mbedtls_mps_reader rd;
int success = 0;
for( int i=0; (unsigned) i < sizeof( bufA ); i++ )
bufA[i] = (unsigned char) i;
@ -939,23 +939,23 @@ void mbedtls_reader_inconsistent_usage( int option )
bufB[i] = ~ ((unsigned char) i);
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
mbedtls_mps_reader_init( &rd, acc, sizeof( acc ) );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 80, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 20, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 80, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 20, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, bufB, sizeof( bufB ) ) == 0 );
/* Consumption */
switch( option )
{
case 0:
/* Ask for buffered data in a single chunk, no commit */
TEST_ASSERT( mbedtls_reader_get( &rd, 30, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
ASSERT_COMPARE( tmp + 20, 10, bufB, 10 );
success = 1;
@ -963,40 +963,40 @@ void mbedtls_reader_inconsistent_usage( int option )
case 1:
/* Ask for buffered data in a single chunk, with commit */
TEST_ASSERT( mbedtls_reader_get( &rd, 30, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 30, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 20, bufA + 80, 20 );
ASSERT_COMPARE( tmp + 20, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
success = 1;
break;
case 2:
/* Ask for more than was requested when pausing, #1 */
TEST_ASSERT( mbedtls_reader_get( &rd, 31, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 31, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
break;
case 3:
/* Ask for more than was requested when pausing #2 */
TEST_ASSERT( mbedtls_reader_get( &rd, (mbedtls_mps_size_t) -1, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, (mbedtls_mps_size_t) -1, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
break;
case 4:
/* Asking for buffered data in different
* chunks than before CAN fail. */
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) ==
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 10, &tmp, NULL ) ==
MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
break;
case 5:
/* Asking for buffered data different chunks
* than before NEED NOT fail - no commits */
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
success = 1;
@ -1005,10 +1005,10 @@ void mbedtls_reader_inconsistent_usage( int option )
case 6:
/* Asking for buffered data different chunks
* than before NEED NOT fail - intermediate commit */
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
success = 1;
@ -1017,25 +1017,25 @@ void mbedtls_reader_inconsistent_usage( int option )
case 7:
/* Asking for buffered data different chunks
* than before NEED NOT fail - end commit */
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
success = 1;
break;
case 8:
/* Asking for buffered data different chunks
* than before NEED NOT fail - intermediate & end commit */
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 15, bufA + 80, 15 );
TEST_ASSERT( mbedtls_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 15, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
ASSERT_COMPARE( tmp, 5, bufA + 95, 5 );
ASSERT_COMPARE( tmp + 5, 10, bufB, 10 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
success = 1;
break;
@ -1047,16 +1047,16 @@ void mbedtls_reader_inconsistent_usage( int option )
if( success == 1 )
{
/* In all succeeding cases, fetch the rest of the second buffer. */
TEST_ASSERT( mbedtls_reader_get( &rd, 90, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 90, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 90, bufB + 10, 90 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
}
/* Wrapup */
mbedtls_reader_free( &rd );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */
@ -1067,16 +1067,16 @@ void mbedtls_mps_reader_feed_empty( int option )
* fed a NULL buffer. */
unsigned char buf[100];
unsigned char *tmp;
mbedtls_reader rd;
mbedtls_mps_reader rd;
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
buf[i] = (unsigned char) i;
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, NULL, 0 );
mbedtls_mps_reader_init( &rd, NULL, 0 );
switch( option )
{
case 0: /* NULL buffer */
TEST_ASSERT( mbedtls_reader_feed( &rd, NULL, sizeof( buf ) ) ==
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, NULL, sizeof( buf ) ) ==
MBEDTLS_ERR_MPS_READER_INVALID_ARG );
break;
@ -1085,15 +1085,15 @@ void mbedtls_mps_reader_feed_empty( int option )
break;
}
/* Subsequent feed-calls should still succeed. */
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_get( &rd, 100, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 100, buf, 100 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_mps_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
TEST_ASSERT( mbedtls_mps_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_mps_reader_free( &rd );
}
/* END_CASE */