From 2d8a2c08521836860bde12c9c2a39b6a77fa5c1a Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Thu, 31 Jan 2019 09:15:53 +0000 Subject: [PATCH] Modify existing X.509 test for also test new copyless API The existing test `x509parse_crt()` for X.509 CRT parsing so far used the generic parsing API `mbedtls_x509_crt_parse()` capable of parsing both PEM encoded and DER encoded certficates, but was actually only used with DER encoded input data. Moreover, as the purpose of the test is the testing of the core DER X.509 parsing functionality, not the PEM vs. DER dispatch (which is now already tested in the various `x509_crt_info()` tests), the call can be replaced with a direct call to `mbedtls_x509_parse_crt_der()`. This commit does that, and further adds to the test an analogous call to the new API `mbedtls_x509_parse_crt_der_nocopy()` to test copyless parsing of X.509 certificates. --- tests/suites/test_suite_x509parse.function | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function index 552c494b0..a921310c6 100644 --- a/tests/suites/test_suite_x509parse.function +++ b/tests/suites/test_suite_x509parse.function @@ -505,8 +505,22 @@ void x509parse_crt( data_t * buf, char * result_str, int result ) mbedtls_x509_crt_init( &crt ); memset( output, 0, 2000 ); + TEST_ASSERT( mbedtls_x509_crt_parse_der( &crt, buf->x, buf->len ) == ( result ) ); + if( ( result ) == 0 ) + { + res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt ); - TEST_ASSERT( mbedtls_x509_crt_parse( &crt, buf->x, buf->len ) == ( result ) ); + TEST_ASSERT( res != -1 ); + TEST_ASSERT( res != -2 ); + + TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 ); + } + + mbedtls_x509_crt_free( &crt ); + mbedtls_x509_crt_init( &crt ); + memset( output, 0, 2000 ); + + TEST_ASSERT( mbedtls_x509_crt_parse_der_nocopy( &crt, buf->x, buf->len ) == ( result ) ); if( ( result ) == 0 ) { res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );