8 #include <sodium/randombytes.h>
18 { "foob" ,"Zm9vYg==" },
19 { "fooba" ,"Zm9vYmE=" },
20 { "foobar","Zm9vYmFy" },
22 { "foobarf" ,"Zm9vYmFyZg==" },
23 { "foobarfo" ,"Zm9vYmFyZm8=" },
24 { "foobarfoo" ,"Zm9vYmFyZm9v" },
25 { "foobarfoob" ,"Zm9vYmFyZm9vYg==" },
26 { "foobarfooba" ,"Zm9vYmFyZm9vYmE=" },
27 { "foobarfoobar","Zm9vYmFyZm9vYmFy" },
32 char buf
[1024], buf2
[1024];
34 for (size_t i
= 0; i
< sizeof(tests0
)/sizeof(tests0
[0]); ++i
) {
35 base64_to(buf
, (const u8
*)tests0
[i
].in
, strlen(tests0
[i
].in
));
36 if (strcmp(buf
, tests0
[i
].out
) != 0) {
37 printf("invalid encoding result: \"%s\" -> encoded as \"%s\", but expected \"%s\".\n",
38 tests0
[i
].in
, buf
, tests0
[i
].out
);
41 if (strlen(buf
) != BASE64_TO_LEN(strlen(tests0
[i
].in
))) {
42 printf("encoded length mismatch: got %d expected %d\n",
43 (int) strlen(buf
), (int) BASE64_TO_LEN(strlen(tests0
[i
].in
)));
46 if (!base64_valid(buf
,0)) {
47 printf("encoded data is considered invalid\n");
50 r
= base64_from((u8
*)buf2
, buf
, strlen(buf
));
52 if (strcmp(buf2
, tests0
[i
].in
) != 0) {
53 printf("invalid decoding result: encoded \"%s\", decoded as \"%s\", but expected \"%s\".\n",
54 tests0
[i
].out
, buf2
, tests0
[i
].in
);