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