forked from sergeybratus/HammerPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase64.c
38 lines (32 loc) · 1.36 KB
/
base64.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <hammer/hammer.h>
#include "test_suite.h"
const HParser *base64;
void init_parser() {
base64 = h_nothing_p();
}
static void test_base64() {
g_check_parse_ok(base64, PB_MIN, "", 0);
g_check_parse_ok(base64, PB_MIN, "Zg==", 4);
g_check_parse_ok(base64, PB_MIN, "Zm8=", 4);
g_check_parse_ok(base64, PB_MIN, "Zm9v", 4);
g_check_parse_ok(base64, PB_MIN, "Zm9vYg==", 8);
g_check_parse_ok(base64, PB_MIN, "Zm9vYmE=", 8);
g_check_parse_ok(base64, PB_MIN, "Zm9vYmFy", 8);
g_check_parse_failed(base64, PB_MIN, "&Zn8", 4); // char not in Base64 alphabet
g_check_parse_failed(base64, PB_MIN, "Zf==", 4); // char not in 2-bit subset
g_check_parse_failed(base64, PB_MIN, "ZmB=", 4); // char not in 4-bit subset
g_check_parse_failed(base64, PB_MIN, "Zm8", 3); // not enough characters
g_check_parse_failed(base64, PB_MIN, "Zm9vYmE", 7); // one full block, 2nd not enough chars
g_check_parse_failed(base64, PB_MIN, "=", 1); // CVE-2004-0600
g_check_parse_failed(base64, PB_MIN, "====", 4); // all padding isn’t valid either
g_check_parse_failed(base64, PB_MIN, "Z===", 4); // neither is 3 padding chars
}
void register_base64_tests() {
g_test_add_func("/base64", test_base64);
}
int main(int argc, char** argv) {
init_parser();
g_test_init(&argc, &argv, NULL);
register_base64_tests();
return g_test_run();
}