2014-04-11 13:28:43 +02:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/base64.h"
|
|
|
|
#include "mbedtls/pem.h"
|
2014-04-11 13:28:43 +02:00
|
|
|
/* END_HEADER */
|
|
|
|
|
2016-10-24 15:31:54 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
|
2015-04-08 12:49:31 +02:00
|
|
|
void mbedtls_pem_write_buffer( char *start, char *end, char *buf_str, char *result_str )
|
2014-04-11 13:28:43 +02:00
|
|
|
{
|
|
|
|
unsigned char buf[5000];
|
2014-07-10 15:26:12 +02:00
|
|
|
unsigned char *check_buf = NULL;
|
2014-04-11 13:28:43 +02:00
|
|
|
int ret;
|
|
|
|
size_t buf_len, olen = 0, olen2 = 0;
|
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
|
|
|
|
buf_len = unhexify( buf, buf_str );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, NULL, 0, &olen );
|
|
|
|
TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
|
2014-04-11 13:28:43 +02:00
|
|
|
|
2015-05-26 16:04:06 +02:00
|
|
|
check_buf = (unsigned char *) mbedtls_calloc( 1, olen );
|
2014-04-11 13:28:43 +02:00
|
|
|
TEST_ASSERT( check_buf != NULL );
|
|
|
|
|
|
|
|
memset( check_buf, 0, olen );
|
2015-04-08 12:49:31 +02:00
|
|
|
ret = mbedtls_pem_write_buffer( start, end, buf, buf_len, check_buf, olen, &olen2 );
|
2014-04-11 13:28:43 +02:00
|
|
|
|
|
|
|
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 );
|
2014-07-10 15:26:12 +02:00
|
|
|
|
|
|
|
exit:
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_free( check_buf );
|
2014-04-11 13:28:43 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2016-10-24 15:31:54 +02:00
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_AES_C:MBEDTLS_DES_C:MBEDTLS_MD5_C:MBEDTLS_CIPHER_MODE_CBC */
|
|
|
|
void mbedtls_pem_read_buffer( char *header, char *footer, char *data, int ret )
|
|
|
|
{
|
|
|
|
mbedtls_pem_context ctx;
|
|
|
|
size_t use_len = 0;
|
|
|
|
|
|
|
|
mbedtls_pem_init( &ctx );
|
|
|
|
|
|
|
|
TEST_ASSERT( mbedtls_pem_read_buffer( &ctx, header, footer,
|
|
|
|
(const unsigned char *)data, NULL, 0,
|
|
|
|
&use_len ) == ret );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_pem_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|