2014-04-11 11:28:43 +00:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 17:05:11 +00:00
|
|
|
#include "mbedtls/base64.h"
|
|
|
|
#include "mbedtls/pem.h"
|
2014-04-11 11:28:43 +00:00
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:POLARSSL_PEM_WRITE_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void pem_write_buffer( char *start, char *end, char *buf_str, char *result_str )
|
|
|
|
{
|
|
|
|
unsigned char buf[5000];
|
2014-07-10 13:26:12 +00:00
|
|
|
unsigned char *check_buf = NULL;
|
2014-04-11 11:28:43 +00:00
|
|
|
int ret;
|
|
|
|
size_t buf_len, olen = 0, olen2 = 0;
|
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
|
|
|
|
buf_len = unhexify( buf, buf_str );
|
|
|
|
|
|
|
|
ret = pem_write_buffer( start, end, buf, buf_len, NULL, 0, &olen );
|
|
|
|
TEST_ASSERT( ret == POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
|
|
|
|
|
|
|
|
check_buf = (unsigned char *) polarssl_malloc( olen );
|
|
|
|
TEST_ASSERT( check_buf != NULL );
|
|
|
|
|
|
|
|
memset( check_buf, 0, olen );
|
|
|
|
ret = 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 );
|
2014-07-10 13:26:12 +00:00
|
|
|
|
|
|
|
exit:
|
2014-04-11 11:28:43 +00:00
|
|
|
polarssl_free( check_buf );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|