diff --git a/tests/suites/test_suite_asn1write.function b/tests/suites/test_suite_asn1write.function index ba4db88d6..fc5fd8a2e 100644 --- a/tests/suites/test_suite_asn1write.function +++ b/tests/suites/test_suite_asn1write.function @@ -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 */