Test result of mbedtls_asn1_write_len() through mbedtls_asn1_get_len()

This commit is contained in:
Paul Bakker 2016-07-14 11:14:54 +01:00 committed by Simon Butcher
parent 58bfb83bb0
commit 5e8b77cd8c

View File

@ -91,7 +91,7 @@ void mbedtls_asn1_write_len( int len, char *check_str, int buf_len,
unsigned char buf[150];
unsigned char asn1[150];
unsigned char *p;
size_t asn1_len, i;
size_t asn1_len, i, read_len;
memset( buf, GUARD_VAL, sizeof( buf ) );
memset( asn1, 0, sizeof( asn1 ) );
@ -116,6 +116,23 @@ void mbedtls_asn1_write_len( int len, char *check_str, int buf_len,
TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + buf_len );
TEST_ASSERT( memcmp( p, asn1, asn1_len ) == 0 );
/* Read back with mbedtls_asn1_get_len() to check */
ret = mbedtls_asn1_get_len( &p, buf + GUARD_LEN + buf_len, &read_len );
if( len == 0 )
{
TEST_ASSERT( ret == 0 );
}
else
{
/* Return will be MBEDTLS_ERR_ASN1_OUT_OF_DATA because the rest of
* the buffer is missing
*/
TEST_ASSERT( ret == MBEDTLS_ERR_ASN1_OUT_OF_DATA );
}
TEST_ASSERT( read_len == (size_t) len );
TEST_ASSERT( p == buf + GUARD_LEN + buf_len );
}
}
/* END_CASE */