Move the list of Base64 digits out of the test data
This is part of the definition of the encoding, not a choice of test parameter, so keep it with the test code. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
c1776a01d2
commit
ba951f5584
2 changed files with 14 additions and 8 deletions
|
@ -23,10 +23,10 @@ mask_of_range 'A'..'Z'
|
|||
mask_of_range:65:90
|
||||
|
||||
enc_char (all digits)
|
||||
enc_chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
enc_chars:
|
||||
|
||||
dec_value (all characters)
|
||||
dec_chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
dec_chars:
|
||||
|
||||
Test case mbedtls_base64_encode #1 buffer just right
|
||||
mbedtls_base64_encode:"":"":0:0
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
#include "mbedtls/base64.h"
|
||||
#include "base64_invasive.h"
|
||||
#include <test/constant_flow.h>
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
static const char digits[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
#endif /* MBEDTLS_TEST_HOOKS */
|
||||
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
|
@ -30,7 +36,7 @@ void mask_of_range( int low_arg, int high_arg )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
|
||||
void enc_chars( char *chars )
|
||||
void enc_chars( )
|
||||
{
|
||||
for( unsigned value = 0; value < 64; value++ )
|
||||
{
|
||||
|
@ -39,26 +45,26 @@ void enc_chars( char *chars )
|
|||
unsigned char digit = mbedtls_base64_enc_char( value );
|
||||
TEST_CF_PUBLIC( &value, sizeof( value ) );
|
||||
TEST_CF_PUBLIC( &digit, sizeof( digit ) );
|
||||
TEST_EQUAL( digit, chars[value] );
|
||||
TEST_EQUAL( digit, digits[value] );
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
|
||||
void dec_chars( char *chars )
|
||||
void dec_chars( )
|
||||
{
|
||||
char *p;
|
||||
const size_t chars_len = strlen( chars );
|
||||
signed char expected;
|
||||
|
||||
for( unsigned c = 0; c <= 0xff; c++ )
|
||||
{
|
||||
mbedtls_test_set_step( c );
|
||||
p = memchr( chars, c, chars_len );
|
||||
/* digits is 0-terminated. sizeof()-1 excludes the trailing 0. */
|
||||
p = memchr( digits, c, sizeof( digits ) - 1 );
|
||||
if( p == NULL )
|
||||
expected = -1;
|
||||
else
|
||||
expected = p - chars;
|
||||
expected = p - digits;
|
||||
TEST_CF_SECRET( &c, sizeof( c ) );
|
||||
signed char actual = mbedtls_base64_dec_value( c );
|
||||
TEST_CF_PUBLIC( &c, sizeof( c ) );
|
||||
|
|
Loading…
Reference in a new issue