1/* BEGIN_HEADER */ 2#include "mbedtls/base64.h" 3#include "mbedtls/pem.h" 4#include "mbedtls/des.h" 5#include "mbedtls/aes.h" 6/* END_HEADER */ 7 8/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */ 9void mbedtls_pem_write_buffer( char * start, char * end, data_t * buf, 10 char * result_str ) 11{ 12 unsigned char *check_buf = NULL; 13 int ret; 14 size_t olen = 0, olen2 = 0; 15 16 17 ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, NULL, 0, &olen ); 18 TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); 19 20 check_buf = (unsigned char *) mbedtls_calloc( 1, olen ); 21 TEST_ASSERT( check_buf != NULL ); 22 23 ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, check_buf, olen, &olen2 ); 24 25 TEST_ASSERT( olen2 <= olen ); 26 TEST_ASSERT( olen > strlen( (char*) result_str ) ); 27 TEST_ASSERT( ret == 0 ); 28 TEST_ASSERT( strncmp( (char *) check_buf, (char *) result_str, olen ) == 0 ); 29 30exit: 31 mbedtls_free( check_buf ); 32} 33/* END_CASE */ 34 35/* BEGIN_CASE depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_AES_C:MBEDTLS_DES_C:MBEDTLS_MD5_C:MBEDTLS_CIPHER_MODE_CBC */ 36void mbedtls_pem_read_buffer( char *header, char *footer, char *data, 37 char *pwd, int res ) 38{ 39 mbedtls_pem_context ctx; 40 int ret; 41 size_t use_len = 0; 42 size_t pwd_len = strlen( pwd ); 43 44 mbedtls_pem_init( &ctx ); 45 46 ret = mbedtls_pem_read_buffer( &ctx, header, footer, (unsigned char *)data, 47 (unsigned char *)pwd, pwd_len, &use_len ); 48 TEST_ASSERT( ret == res ); 49 50exit: 51 mbedtls_pem_free( &ctx ); 52} 53/* END_CASE */ 54