Go to the documentation of this file.
29 #define MAX_DATA_SIZE 1024
30 #define MAX_ENCODED_SIZE 2048
33 const char *encoded_ref)
40 printf(
"Failed: cannot encode the input data\n");
43 if (encoded_ref && strcmp(encoded, encoded_ref)) {
44 printf(
"Failed: encoded string differs from reference\n"
45 "Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
49 if ((data2_size =
av_base64_decode(data2, encoded, max_data2_size)) != data_size) {
50 printf(
"Failed: cannot decode the encoded string\n"
51 "Encoded:\n%s\n", encoded);
54 if ((data2_size =
av_base64_decode(data2, encoded, data_size)) != data_size) {
55 printf(
"Failed: cannot decode with minimal buffer\n"
56 "Encoded:\n%s\n", encoded);
59 if (memcmp(data2,
data, data_size)) {
60 printf(
"Failed: encoded/decoded data differs from original data\n");
64 printf(
"Failed: decode to NULL buffer\n");
67 if (strlen(encoded)) {
68 char *end = strchr(encoded,
'=');
70 end = encoded + strlen(encoded) - 1;
73 printf(
"Failed: error detection\n");
82 int main(
int argc,
char ** argv)
84 int i, error_count = 0;
87 const char *encoded_ref;
93 {
"4444",
"NDQ0NA=="},
94 {
"55555",
"NTU1NTU="},
95 {
"666666",
"NjY2NjY2"},
96 {
"abc:def",
"YWJjOmRlZg=="},
98 char in[1024],
out[2048];
100 printf(
"Encoding/decoding tests\n");
104 if (argc>1 && !strcmp(argv[1],
"-t")) {
105 memset(in, 123,
sizeof(in));
106 for(
i=0;
i<10000;
i++){
111 for(
i=0;
i<10000;
i++){
117 for(
i=0;
i<10000;
i++){
125 printf(
"Error Count: %d.\n", error_count);
127 return !!error_count;
int main(int argc, char **argv)
#define FF_ARRAY_ELEMS(a)
static int test_encode_decode(const uint8_t *data, unsigned int data_size, const char *encoded_ref)
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
printf("static const uint8_t my_array[100] = {\n")
#define i(width, name, range_min, range_max)
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.