mbed TLS Build

Dependents:   Encrypt_Decrypt1 mbed_blink_tls encrypt encrypt

Committer:
markrad
Date:
Thu Jan 05 00:18:44 2017 +0000
Revision:
0:cdf462088d13
Initial commit

Who changed what in which revision?

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