53 #define DATA(...) { __VA_ARGS__ } 56 #define BASE64( name, DATA, ENCODED ) \ 57 static const uint8_t name ## _data[] = DATA; \ 58 static struct base64_test name = { \ 59 .data = name ## _data, \ 60 .len = sizeof ( name ## _data ), \ 69 DATA (
'H',
'e',
'l',
'l',
'o',
' ',
'w',
'o',
'r',
'l',
'd' ),
74 DATA ( 0x36, 0x03, 0x84, 0xdc, 0x4e, 0x03, 0x46, 0xa0, 0xb5, 0x2d,
75 0x03, 0x6e, 0xd0, 0x56, 0xed, 0xa0, 0x37, 0x02, 0xac, 0xc6,
77 "NgOE3E4DRqC1LQNu0FbtoDcCrMZl0Q==" );
94 okx ( check_len ==
len, file, line );
97 #define base64_encode_ok( test ) base64_encode_okx ( test, __FILE__, __LINE__ ) 107 unsigned int line ) {
113 okx (
len >= 0, file, line );
114 okx ( (
size_t )
len <= max_len, file, line );
115 okx ( (
size_t )
len ==
test->len, file, line );
118 #define base64_decode_ok( test ) base64_decode_okx ( test, __FILE__, __LINE__ ) #define base64_decode_ok(test)
const void * data
Raw data.
static void base64_encode_okx(struct base64_test *test, const char *file, unsigned int line)
Report a base64 encoding test result.
Self-test infrastructure.
const char * name
Test set name.
static void base64_test_exec(void)
Perform Base64 self-tests.
int base64_decode(const char *encoded, void *data, size_t len)
Base64-decode string.
static size_t base64_encoded_len(size_t raw_len)
Calculate length of base64-encoded data.
static size_t base64_decoded_max_len(const char *encoded)
Calculate maximum length of base64-decoded string.
size_t len
Length of raw data.
#define okx(success, file, line)
Report test result.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define base64_encode_ok(test)
size_t strlen(const char *src)
Get length of string.
const char * encoded
Base64-encoded data.
int strcmp(const char *first, const char *second)
Compare strings.
#define BASE64(name, DATA, ENCODED)
Define a base64 test.
struct self_test base64_test __self_test
Base64 self-test.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
static void base64_decode_okx(struct base64_test *test, const char *file, unsigned int line)
Report a base64 decoding test result.
size_t base64_encode(const void *raw, size_t raw_len, char *data, size_t len)
Base64-encode data.
#define DATA(...)
Define inline data.