mbed TLS Build
Diff: tests/suites/test_suite_pem.function
- Revision:
- 0:cdf462088d13
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/suites/test_suite_pem.function Thu Jan 05 00:18:44 2017 +0000 @@ -0,0 +1,40 @@ +/* BEGIN_HEADER */ +#include "mbedtls/base64.h" +#include "mbedtls/pem.h" +/* END_HEADER */ + +/* BEGIN_DEPENDENCIES + * depends_on:MBEDTLS_PEM_WRITE_C + * END_DEPENDENCIES + */ + +/* BEGIN_CASE */ +void mbedtls_pem_write_buffer( char *start, char *end, char *buf_str, char *result_str ) +{ + unsigned char buf[5000]; + unsigned char *check_buf = NULL; + int ret; + size_t buf_len, olen = 0, olen2 = 0; + + memset( buf, 0, sizeof( buf ) ); + + buf_len = unhexify( buf, buf_str ); + + ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, NULL, 0, &olen ); + TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); + + check_buf = (unsigned char *) mbedtls_calloc( 1, olen ); + TEST_ASSERT( check_buf != NULL ); + + memset( check_buf, 0, olen ); + ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, check_buf, olen, &olen2 ); + + TEST_ASSERT( olen2 <= olen ); + TEST_ASSERT( olen > strlen( (char*) result_str ) ); + TEST_ASSERT( ret == 0 ); + TEST_ASSERT( strncmp( (char *) check_buf, (char *) result_str, olen ) == 0 ); + +exit: + mbedtls_free( check_buf ); +} +/* END_CASE */