1/* BEGIN_HEADER */ 2#include "mbedtls/base64.h" 3#include "mbedtls/pem.h" 4/* END_HEADER */ 5 6/* BEGIN_DEPENDENCIES 7 * depends_on:MBEDTLS_PEM_WRITE_C 8 * END_DEPENDENCIES 9 */ 10 11/* BEGIN_CASE */ 12void mbedtls_pem_write_buffer( char *start, char *end, char *buf_str, char *result_str ) 13{ 14 unsigned char buf[5000]; 15 unsigned char *check_buf = NULL; 16 int ret; 17 size_t buf_len, olen = 0, olen2 = 0; 18 19 memset( buf, 0, sizeof( buf ) ); 20 21 buf_len = unhexify( buf, buf_str ); 22 23 ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, NULL, 0, &olen ); 24 TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); 25 26 check_buf = (unsigned char *) mbedtls_calloc( 1, olen ); 27 TEST_ASSERT( check_buf != NULL ); 28 29 memset( check_buf, 0, olen ); 30 ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, check_buf, olen, &olen2 ); 31 32 TEST_ASSERT( olen2 <= olen ); 33 TEST_ASSERT( olen > strlen( (char*) result_str ) ); 34 TEST_ASSERT( ret == 0 ); 35 TEST_ASSERT( strncmp( (char *) check_buf, (char *) result_str, olen ) == 0 ); 36 37exit: 38 mbedtls_free( check_buf ); 39} 40/* END_CASE */ 41