blob: 27b6c134c267f9394acbf634d1d9e7f00fe30200 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Paul Bakker367dae42009-06-28 21:50:27 +00002#include <polarssl/base64.h>
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakker367dae42009-06-28 21:50:27 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
6 * depends_on:POLARSSL_BASE64_C
7 * END_DEPENDENCIES
8 */
Paul Bakker5690efc2011-05-26 13:16:06 +00009
Paul Bakker33b43f12013-08-20 11:48:36 +020010/* BEGIN_CASE */
11void base64_encode( char *src_string, char *dst_string, int dst_buf_size,
12 int result )
Paul Bakker367dae42009-06-28 21:50:27 +000013{
14 unsigned char src_str[1000];
15 unsigned char dst_str[1000];
Paul Bakker33b43f12013-08-20 11:48:36 +020016 size_t len = dst_buf_size;
Paul Bakker367dae42009-06-28 21:50:27 +000017
18 memset(src_str, 0x00, 1000);
19 memset(dst_str, 0x00, 1000);
20
Paul Bakker33b43f12013-08-20 11:48:36 +020021 strcpy( (char *) src_str, src_string );
22 TEST_ASSERT( base64_encode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == result );
23 if( result == 0 )
Paul Bakker5946fd92009-07-11 15:29:30 +000024 {
Paul Bakker33b43f12013-08-20 11:48:36 +020025 TEST_ASSERT( strcmp( (char *) dst_str, dst_string ) == 0 );
Paul Bakker5946fd92009-07-11 15:29:30 +000026 }
Paul Bakker367dae42009-06-28 21:50:27 +000027}
Paul Bakker33b43f12013-08-20 11:48:36 +020028/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000029
Paul Bakker33b43f12013-08-20 11:48:36 +020030/* BEGIN_CASE */
31void base64_decode( char *src_string, char *dst_string, int result )
Paul Bakker367dae42009-06-28 21:50:27 +000032{
33 unsigned char src_str[1000];
34 unsigned char dst_str[1000];
Paul Bakkerf4a3f302011-04-24 15:53:29 +000035 size_t len = 1000;
Paul Bakker367dae42009-06-28 21:50:27 +000036 int res;
37
38 memset(src_str, 0x00, 1000);
39 memset(dst_str, 0x00, 1000);
40
Paul Bakker33b43f12013-08-20 11:48:36 +020041 strcpy( (char *) src_str, src_string );
42 TEST_ASSERT( res = base64_decode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == result );
43 if( result == 0 )
Paul Bakker5946fd92009-07-11 15:29:30 +000044 {
Paul Bakker33b43f12013-08-20 11:48:36 +020045 TEST_ASSERT( strcmp( (char *) dst_str, dst_string ) == 0 );
Paul Bakker5946fd92009-07-11 15:29:30 +000046 }
Paul Bakker367dae42009-06-28 21:50:27 +000047}
Paul Bakker33b43f12013-08-20 11:48:36 +020048/* END_CASE */
Paul Bakker3d360822009-07-05 11:29:38 +000049
Manuel Pégourié-Gonnard20140162013-10-10 12:48:03 +020050/* BEGIN_CASE depends_on:POLARSSL_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +020051void base64_selftest()
Paul Bakker3d360822009-07-05 11:29:38 +000052{
53 TEST_ASSERT( base64_self_test( 0 ) == 0 );
54}
Paul Bakker33b43f12013-08-20 11:48:36 +020055/* END_CASE */