2 * Copyright (C) 2013-2015 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "test_suite.h"
19 #include <utils/utils.h>
20 #include <ipsec/ipsec_types.h>
21 #include <credentials/keys/public_key.h>
25 /*******************************************************************************
26 * object storage on lib
29 START_TEST(test_objects
)
31 char *k1
= "key1", *k2
= "key2";
32 char *v1
= "val1", *val
;
34 ck_assert(lib
->get(lib
, k1
) == NULL
);
36 ck_assert(lib
->set(lib
, k1
, v1
));
37 ck_assert(!lib
->set(lib
, k1
, v1
));
39 val
= lib
->get(lib
, k1
);
40 ck_assert(val
!= NULL
);
41 ck_assert(streq(val
, v1
));
43 ck_assert(lib
->set(lib
, k1
, NULL
));
44 ck_assert(!lib
->set(lib
, k2
, NULL
));
46 ck_assert(lib
->get(lib
, k1
) == NULL
);
50 /*******************************************************************************
51 * test return_... functions
54 START_TEST(test_return_functions
)
56 ck_assert(return_null() == NULL
);
57 ck_assert(return_null("asdf", 5, NULL
, 1, "qwer") == NULL
);
59 ck_assert(return_true() == TRUE
);
60 ck_assert(return_true("asdf", 5, NULL
, 1, "qwer") == TRUE
);
62 ck_assert(return_false() == FALSE
);
63 ck_assert(return_false("asdf", 5, NULL
, 1, "qwer") == FALSE
);
65 ck_assert(return_failed() == FAILED
);
66 ck_assert(return_failed("asdf", 5, NULL
, 1, "qwer") == FAILED
);
68 ck_assert(return_success() == SUCCESS
);
69 ck_assert(return_success("asdf", 5, NULL
, 1, "qwer") == SUCCESS
);
71 /* just make sure this works */
73 nop("asdf", 5, NULL
, 1, "qwer");
77 /*******************************************************************************
81 START_TEST(test_timeval_add_ms
)
87 timeval_add_ms(&tv
, 0);
88 ck_assert_int_eq(tv
.tv_sec
, 0);
89 ck_assert_int_eq(tv
.tv_usec
, 0);
91 timeval_add_ms(&tv
, 1);
92 ck_assert_int_eq(tv
.tv_sec
, 0);
93 ck_assert_int_eq(tv
.tv_usec
, 1000);
95 timeval_add_ms(&tv
, 0);
96 ck_assert_int_eq(tv
.tv_sec
, 0);
97 ck_assert_int_eq(tv
.tv_usec
, 1000);
99 timeval_add_ms(&tv
, 999);
100 ck_assert_int_eq(tv
.tv_sec
, 1);
101 ck_assert_int_eq(tv
.tv_usec
, 0);
103 timeval_add_ms(&tv
, 0);
104 ck_assert_int_eq(tv
.tv_sec
, 1);
105 ck_assert_int_eq(tv
.tv_usec
, 0);
107 timeval_add_ms(&tv
, 1000);
108 ck_assert_int_eq(tv
.tv_sec
, 2);
109 ck_assert_int_eq(tv
.tv_usec
, 0);
111 timeval_add_ms(&tv
, 1500);
112 ck_assert_int_eq(tv
.tv_sec
, 3);
113 ck_assert_int_eq(tv
.tv_usec
, 500000);
117 /*******************************************************************************
121 START_TEST(test_htoun
)
123 chunk_t net64
, expected
;
124 u_int16_t host16
= 513;
125 u_int32_t net16
= 0, host32
= 67305985;
126 u_int64_t net32
= 0, host64
= 578437695752307201ULL;
128 net64
= chunk_alloca(16);
129 memset(net64
.ptr
, 0, net64
.len
);
131 expected
= chunk_from_chars(0x00, 0x02, 0x01, 0x00);
132 htoun16((char*)&net16
+ 1, host16
);
133 ck_assert(chunk_equals(expected
, chunk_from_thing(net16
)));
135 expected
= chunk_from_chars(0x00, 0x00, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00);
136 htoun32((u_int16_t
*)&net32
+ 1, host32
);
137 ck_assert(chunk_equals(expected
, chunk_from_thing(net32
)));
139 expected
= chunk_from_chars(0x00, 0x00, 0x00, 0x00,
140 0x08, 0x07, 0x06, 0x05,
141 0x04, 0x03, 0x02, 0x01,
142 0x00, 0x00, 0x00, 0x00);
143 htoun64((u_int32_t
*)net64
.ptr
+ 1, host64
);
144 ck_assert(chunk_equals(expected
, net64
));
148 START_TEST(test_untoh
)
155 net
= chunk_from_chars(0x00, 0x02, 0x01, 0x00);
156 host16
= untoh16(net
.ptr
+ 1);
157 ck_assert(host16
== 513);
159 net
= chunk_from_chars(0x00, 0x00, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00);
160 host32
= untoh32(net
.ptr
+ 2);
161 ck_assert(host32
== 67305985);
163 net
= chunk_from_chars(0x00, 0x00, 0x00, 0x00, 0x08, 0x07, 0x06, 0x05,
164 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00);
165 host64
= untoh64(net
.ptr
+ 4);
166 ck_assert(host64
== 578437695752307201ULL);
170 /*******************************************************************************
171 * pad_len/round_up/down
174 START_TEST(test_round
)
176 ck_assert_int_eq(pad_len(0, 4), 0);
177 ck_assert_int_eq(pad_len(1, 4), 3);
178 ck_assert_int_eq(pad_len(2, 4), 2);
179 ck_assert_int_eq(pad_len(3, 4), 1);
180 ck_assert_int_eq(pad_len(4, 4), 0);
181 ck_assert_int_eq(pad_len(5, 4), 3);
183 ck_assert_int_eq(round_up(0, 4), 0);
184 ck_assert_int_eq(round_up(1, 4), 4);
185 ck_assert_int_eq(round_up(2, 4), 4);
186 ck_assert_int_eq(round_up(3, 4), 4);
187 ck_assert_int_eq(round_up(4, 4), 4);
188 ck_assert_int_eq(round_up(5, 4), 8);
190 ck_assert_int_eq(round_down(0, 4), 0);
191 ck_assert_int_eq(round_down(1, 4), 0);
192 ck_assert_int_eq(round_down(2, 4), 0);
193 ck_assert_int_eq(round_down(3, 4), 0);
194 ck_assert_int_eq(round_down(4, 4), 4);
195 ck_assert_int_eq(round_down(5, 4), 4);
199 /*******************************************************************************
209 {"", "", TRUE
, TRUE
},
210 {"abc", "", TRUE
, TRUE
},
211 {"abc", "a", TRUE
, TRUE
},
212 {"abc", "ab", TRUE
, TRUE
},
213 {"abc", "abc", TRUE
, TRUE
},
214 {"abc", "abcd", FALSE
, FALSE
},
215 {"abc", "AB", FALSE
, TRUE
},
216 {"ABC", "ab", FALSE
, TRUE
},
217 {" abc", "abc", FALSE
, FALSE
},
220 START_TEST(test_strpfx
)
224 prefix
= strpfx(strpfx_data
[_i
].str
, strpfx_data
[_i
].pfx
);
225 ck_assert(prefix
== strpfx_data
[_i
].prefix
);
226 prefix
= strcasepfx(strpfx_data
[_i
].str
, strpfx_data
[_i
].pfx
);
227 ck_assert(prefix
== strpfx_data
[_i
].case_prefix
);
231 /*******************************************************************************
232 * mallac_align/free_align
235 START_TEST(test_malloc_align
)
240 for (size
= 0; size
< countof(ptr
); size
++)
242 for (align
= 0; align
< countof(ptr
[0]); align
++)
244 ptr
[size
][align
] = malloc_align(size
, align
);
247 ck_assert((uintptr_t)ptr
[size
][align
] % align
== 0);
251 ck_assert(ptr
[size
][align
]);
252 memset(ptr
[size
][align
], 0xEF, size
);
256 for (size
= 0; size
< countof(ptr
); size
++)
258 for (align
= 0; align
< countof(ptr
[0]); align
++)
260 free_align(ptr
[size
][align
]);
266 /*******************************************************************************
270 static void do_memxor(chunk_t a
, chunk_t b
, chunk_t exp
)
274 dst
= chunk_clonea(a
);
276 memxor(dst
.ptr
, b
.ptr
, b
.len
);
277 ck_assert(chunk_equals(dst
, exp
));
280 START_TEST(test_memxor
)
285 a
= chunk_alloca(64);
286 memset(a
.ptr
, 0, a
.len
);
287 b
= chunk_alloca(64);
288 for (i
= 0; i
< 64; i
++)
297 dst
= chunk_clonea(a
);
298 memxor(dst
.ptr
, b
.ptr
, b
.len
);
299 ck_assert(chunk_equals(dst
, b
));
301 memxor(dst
.ptr
, b
.ptr
, 0);
302 memxor(dst
.ptr
, b
.ptr
, 1);
303 memxor(dst
.ptr
+ 1, b
.ptr
+ 1, 1);
304 memxor(dst
.ptr
+ 2, b
.ptr
+ 2, b
.len
- 2);
305 ck_assert(chunk_equals(dst
, a
));
309 START_TEST(test_memxor_aligned
)
311 u_int64_t a
= 0, b
= 0;
315 ca
= chunk_from_thing(a
);
316 cb
= chunk_from_thing(b
);
318 for (i
= 0; i
< 8; i
++)
324 memxor(ca
.ptr
, cb
.ptr
, 8);
326 /* 32-bit aligned source */
328 memxor(ca
.ptr
, cb
.ptr
+ 4, 4);
329 ck_assert(chunk_equals(ca
, chunk_from_chars(0x05, 0x06, 0x07, 0x08,
330 0x00, 0x00, 0x00, 0x00)));
331 /* 16-bit aligned source */
333 memxor(ca
.ptr
, cb
.ptr
+ 2, 6);
334 ck_assert(chunk_equals(ca
, chunk_from_chars(0x03, 0x04, 0x05, 0x06,
335 0x07, 0x08, 0x00, 0x00)));
336 /* 8-bit aligned source */
338 memxor(ca
.ptr
, cb
.ptr
+ 1, 7);
339 ck_assert(chunk_equals(ca
, chunk_from_chars(0x02, 0x03, 0x04, 0x05,
340 0x06, 0x07, 0x08, 0x00)));
344 /*******************************************************************************
354 {NULL
, NULL
, 0, TRUE
},
357 {"abcdefgh", "abcdefgh", 8, TRUE
},
358 {"a", "b", 1, FALSE
},
359 {"A", "a", 1, FALSE
},
360 {"\0a", "\0b", 2, FALSE
},
361 {"abc", "abd", 3, FALSE
},
362 {"abc", "dbd", 3, FALSE
},
363 {"abcdefgh", "abcdffgh", 8, FALSE
},
364 {"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
365 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 52, TRUE
},
366 {"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
367 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyy", 52, FALSE
},
368 {"bbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
369 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 52, FALSE
},
372 START_TEST(test_memeq
)
374 ck_assert(memeq(memeq_data
[_i
].a
, memeq_data
[_i
].b
,
375 memeq_data
[_i
].n
) == memeq_data
[_i
].res
);
379 START_TEST(test_memeq_const
)
381 ck_assert(memeq_const(memeq_data
[_i
].a
, memeq_data
[_i
].b
,
382 memeq_data
[_i
].n
) == memeq_data
[_i
].res
);
386 /*******************************************************************************
398 {NULL
, "abc", 0, -1},
399 {NULL
, "abc", 3, -1},
401 {"abc", NULL
, 3, -1},
403 {"abc", "abc", 3, 0},
404 {" abc", "abc", 4, 1},
405 {" abc", "abc", 3, -1},
406 {"abcabc", "abc", 6, 0},
407 {" abc ", "abc", 5, 1},
410 START_TEST(test_memstr
)
414 ret
= memstr(memstr_data
[_i
].haystack
, memstr_data
[_i
].needle
, memstr_data
[_i
].n
);
415 if (memstr_data
[_i
].offset
>= 0)
417 ck_assert(ret
== memstr_data
[_i
].haystack
+ memstr_data
[_i
].offset
);
421 ck_assert(ret
== NULL
);
426 /*******************************************************************************
440 {"foo", '\0', 3, -1},
450 START_TEST(test_utils_memrchr
)
454 ret
= utils_memrchr(memrchr_data
[_i
].s
, memrchr_data
[_i
].c
, memrchr_data
[_i
].n
);
455 if (memrchr_data
[_i
].offset
>= 0)
457 ck_assert(ret
== memrchr_data
[_i
].s
+ memrchr_data
[_i
].offset
);
461 ck_assert(ret
== NULL
);
466 /*******************************************************************************
475 } translate_data
[] = {
476 {NULL
, "", "", NULL
},
477 {"abc", "", "", "abc"},
478 {"abc", "", "x", "abc"},
479 {"abc", "x", "", "abc"},
480 {"abc", "abc", "xyz", "xyz"},
481 {"aabbcc", "abc", "xyz", "xxyyzz"},
482 {"abbaccb", "abc", "xyz", "xyyxzzy"},
483 {"abxyzc", "abc", "xyz", "xyxyzz"},
484 {"abcdef", "abc", "xyz", "xyzdef"},
485 {"aaa", "abc", "xyz", "xxx"},
486 {"abc", "aaa", "xyz", "xbc"},
487 {"abc", "abc", "xxx", "xxx"},
490 START_TEST(test_translate
)
494 str
= strdupnull(translate_data
[_i
].in
);
495 ret
= translate(str
, translate_data
[_i
].from
, translate_data
[_i
].to
);
496 ck_assert(ret
== str
);
497 if (ret
!= translate_data
[_i
].out
)
499 ck_assert_str_eq(str
, translate_data
[_i
].out
);
505 /*******************************************************************************
515 } strreplace_data
[] = {
516 /* invalid arguments */
517 {NULL
, NULL
, NULL
, NULL
, FALSE
},
518 {"", "", NULL
, NULL
, FALSE
},
519 {"", "", "", NULL
, FALSE
},
520 {"", "", NULL
, "", FALSE
},
521 {"", "", "", "", FALSE
},
522 {"", "", "", "asdf", FALSE
},
523 {"", "", "asdf", "", FALSE
},
524 {"asdf", "asdf", NULL
, NULL
, FALSE
},
525 {"asdf", "asdf", "", NULL
, FALSE
},
526 {"asdf", "asdf", NULL
, "", FALSE
},
527 {"asdf", "asdf", "", "", FALSE
},
528 {"asdf", "asdf", "", "asdf", FALSE
},
529 {"asdf", "asdf", "asdf", NULL
, FALSE
},
530 {"qwer", "qwer", "", "asdf", FALSE
},
531 /* replacement shorter */
532 {"asdf", "", "asdf", "", TRUE
},
533 {"asdfasdf", "", "asdf", "", TRUE
},
534 {"asasdfdf", "asdf", "asdf", "", TRUE
},
535 {"asdf", "df", "as", "", TRUE
},
536 {"asdf", "as", "df", "", TRUE
},
537 {"qwer", "qwer", "asdf", "", FALSE
},
538 /* replacement same length */
539 {"a", "b", "a", "b", TRUE
},
540 {"aaa", "bbb", "a", "b", TRUE
},
541 {"aaa", "bbb", "aaa", "bbb", TRUE
},
542 {"asdf", "asdf", "asdf", "asdf", TRUE
},
543 {"qwer", "qwer", "asdf", "asdf", FALSE
},
544 /* replacement longer */
545 {"asdf", "asdf", "", "asdf", FALSE
},
546 {"asdf", "asdfasdf", "asdf", "asdfasdf", TRUE
},
547 {"asdf", "asdfsdf", "a", "asdf", TRUE
},
548 {"asdf", "asdasdf", "f", "asdf", TRUE
},
549 {"aaa", "asdfasdfasdf", "a", "asdf", TRUE
},
550 {"qwer", "qwer", "asdf", "asdfasdf", FALSE
},
552 {"http://x.org/no/spaces", "http://x.org/no/spaces", " ", "%20", FALSE
},
553 {"http://x.org/end ", "http://x.org/end%20", " ", "%20", TRUE
},
554 {" http://x.org/start", "%20http://x.org/start", " ", "%20", TRUE
},
555 {" http://x.org/both ", "%20http://x.org/both%20", " ", "%20", TRUE
},
556 {"http://x.org/ /slash", "http://x.org/%20/slash", " ", "%20", TRUE
},
557 {"http://x.org/ /three", "http://x.org/%20%20%20/three", " ", "%20", TRUE
},
558 {"http://x.org/ ", "http://x.org/%20%20%20%20%20%20", " ", "%20", TRUE
},
559 {"http://x.org/%20/encoded", "http://x.org/%20/encoded", " ", "%20", FALSE
},
562 START_TEST(test_strreplace
)
566 ret
= strreplace(strreplace_data
[_i
].in
, strreplace_data
[_i
].search
,
567 strreplace_data
[_i
].replace
);
568 if (ret
&& strreplace_data
[_i
].out
)
570 ck_assert_str_eq(ret
, strreplace_data
[_i
].out
);
574 ck_assert(ret
== strreplace_data
[_i
].out
);
576 if (strreplace_data
[_i
].allocated
)
578 ck_assert(ret
!= strreplace_data
[_i
].in
);
583 ck_assert(ret
== strreplace_data
[_i
].in
);
588 /*******************************************************************************
589 * path_dirname/basename/absolute
598 {NULL
, ".", ".", FALSE
},
599 {"", ".", ".", FALSE
},
600 {".", ".", ".", FALSE
},
601 {"..", ".", "..", FALSE
},
603 {"C:\\", "C:", "C:", TRUE
},
604 {"X:\\\\", "X:", "X:", TRUE
},
605 {"foo", ".", "foo", FALSE
},
606 {"f\\", ".", "f", FALSE
},
607 {"foo\\", ".", "foo", FALSE
},
608 {"foo\\\\", ".", "foo", FALSE
},
609 {"d:\\f", "d:", "f", TRUE
},
610 {"C:\\f\\", "C:", "f", TRUE
},
611 {"C:\\foo", "C:", "foo", TRUE
},
612 {"C:\\foo\\", "C:", "foo", TRUE
},
613 {"foo\\bar", "foo", "bar", FALSE
},
614 {"foo\\\\bar", "foo", "bar", FALSE
},
615 {"C:\\foo\\bar", "C:\\foo", "bar", TRUE
},
616 {"C:\\foo\\bar\\", "C:\\foo", "bar", TRUE
},
617 {"C:\\foo\\bar\\baz", "C:\\foo\\bar", "baz", TRUE
},
618 {"\\foo\\bar", "\\foo", "bar", FALSE
},
619 {"\\\\foo\\bar", "\\\\foo", "bar", TRUE
},
621 {"/", "/", "/", TRUE
},
622 {"//", "/", "/", TRUE
},
623 {"foo", ".", "foo", FALSE
},
624 {"f/", ".", "f", FALSE
},
625 {"foo/", ".", "foo", FALSE
},
626 {"foo//", ".", "foo", FALSE
},
627 {"/f", "/", "f", TRUE
},
628 {"/f/", "/", "f", TRUE
},
629 {"/foo", "/", "foo", TRUE
},
630 {"/foo/", "/", "foo", TRUE
},
631 {"//foo/", "/", "foo", TRUE
},
632 {"foo/bar", "foo", "bar", FALSE
},
633 {"foo//bar", "foo", "bar", FALSE
},
634 {"/foo/bar", "/foo", "bar", TRUE
},
635 {"/foo/bar/", "/foo", "bar", TRUE
},
636 {"/foo/bar/baz", "/foo/bar", "baz", TRUE
},
640 START_TEST(test_path_dirname
)
644 dir
= path_dirname(path_data
[_i
].path
);
645 ck_assert_str_eq(path_data
[_i
].dir
, dir
);
650 START_TEST(test_path_basename
)
654 base
= path_basename(path_data
[_i
].path
);
655 ck_assert_str_eq(path_data
[_i
].base
, base
);
660 START_TEST(test_path_absolute
)
662 ck_assert(path_data
[_i
].absolute
== path_absolute(path_data
[_i
].path
));
666 /*******************************************************************************
675 {UNDEFINED_TIME
, FALSE
, "--- -- --:--:-- ----"},
676 {UNDEFINED_TIME
, TRUE
, "--- -- --:--:-- UTC ----"},
677 {1, FALSE
, "Jan 01 01:00:01 1970"},
678 {1, TRUE
, "Jan 01 00:00:01 UTC 1970"},
679 {1341150196, FALSE
, "Jul 01 15:43:16 2012"},
680 {1341150196, TRUE
, "Jul 01 13:43:16 UTC 2012"},
683 START_TEST(test_time_printf_hook
)
688 len
= snprintf(buf
, sizeof(buf
), "%T", &time_data
[_i
].in
, time_data
[_i
].utc
);
689 ck_assert(len
>= 0 && len
< sizeof(buf
));
690 ck_assert_str_eq(buf
, time_data
[_i
].out
);
694 /*******************************************************************************
695 * time_delta_printf_hook
702 } time_delta_data
[] = {
709 {0, 60, "60 seconds"},
710 {0, 120, "120 seconds"},
711 {0, 121, "2 minutes"},
712 {0, 3600, "60 minutes"},
713 {0, 7200, "120 minutes"},
714 {0, 7201, "2 hours"},
715 {0, 86400, "24 hours"},
716 {0, 172800, "48 hours"},
717 {0, 172801, "2 days"},
718 {172801, 86400, "24 hours"},
721 START_TEST(test_time_delta_printf_hook
)
726 len
= snprintf(buf
, sizeof(buf
), "%V", &time_delta_data
[_i
].a
, &time_delta_data
[_i
].b
);
727 ck_assert(len
>= 0 && len
< sizeof(buf
));
728 ck_assert_str_eq(buf
, time_delta_data
[_i
].out
);
732 /*******************************************************************************
741 {NULL
, FALSE
, { 0 }},
742 {"", TRUE
, { 0, 0xffffffff }},
743 {"/", TRUE
, { 0, 0 }},
744 {"42", TRUE
, { 42, 0xffffffff }},
745 {"0x42", TRUE
, { 0x42, 0xffffffff }},
747 {"42/", TRUE
, { 0, 0 }},
748 {"42/0", TRUE
, { 0, 0 }},
749 {"42/x", FALSE
, { 0 }},
750 {"42/42", TRUE
, { 42, 42 }},
751 {"42/0xff", TRUE
, { 42, 0xff }},
752 {"0x42/0xff", TRUE
, { 0x42, 0xff }},
753 {"/0xff", TRUE
, { 0, 0xff }},
754 {"/x", FALSE
, { 0 }},
755 {"x/x", FALSE
, { 0 }},
756 {"0xffffffff/0x0000ffff", TRUE
, { 0x0000ffff, 0x0000ffff }},
757 {"0xffffffff/0xffffffff", TRUE
, { 0xffffffff, 0xffffffff }},
760 START_TEST(test_mark_from_string
)
764 if (mark_from_string(mark_data
[_i
].s
, &mark
))
766 ck_assert_int_eq(mark
.value
, mark_data
[_i
].m
.value
);
767 ck_assert_int_eq(mark
.mask
, mark_data
[_i
].m
.mask
);
771 ck_assert(!mark_data
[_i
].ok
);
776 /*******************************************************************************
777 * signature_schemes_for_key
783 signature_scheme_t expected
[4];
785 {KEY_RSA
, 1024, { SIGN_RSA_EMSA_PKCS1_SHA256
, SIGN_RSA_EMSA_PKCS1_SHA384
, SIGN_RSA_EMSA_PKCS1_SHA512
, SIGN_UNKNOWN
}},
786 {KEY_RSA
, 2048, { SIGN_RSA_EMSA_PKCS1_SHA256
, SIGN_RSA_EMSA_PKCS1_SHA384
, SIGN_RSA_EMSA_PKCS1_SHA512
, SIGN_UNKNOWN
}},
787 {KEY_RSA
, 4096, { SIGN_RSA_EMSA_PKCS1_SHA384
, SIGN_RSA_EMSA_PKCS1_SHA512
, SIGN_UNKNOWN
}},
788 {KEY_RSA
, 8192, { SIGN_RSA_EMSA_PKCS1_SHA512
, SIGN_UNKNOWN
}},
789 {KEY_ECDSA
, 256, { SIGN_ECDSA_WITH_SHA256_DER
, SIGN_ECDSA_WITH_SHA384_DER
, SIGN_ECDSA_WITH_SHA512_DER
, SIGN_UNKNOWN
}},
790 {KEY_ECDSA
, 384, { SIGN_ECDSA_WITH_SHA384_DER
, SIGN_ECDSA_WITH_SHA512_DER
, SIGN_UNKNOWN
}},
791 {KEY_ECDSA
, 512, { SIGN_ECDSA_WITH_SHA512_DER
, SIGN_UNKNOWN
}},
792 {KEY_BLISS
, 128, { SIGN_BLISS_WITH_SHA256
, SIGN_BLISS_WITH_SHA384
, SIGN_BLISS_WITH_SHA512
, SIGN_UNKNOWN
}},
793 {KEY_BLISS
, 192, { SIGN_BLISS_WITH_SHA384
, SIGN_BLISS_WITH_SHA512
, SIGN_UNKNOWN
}},
794 {KEY_BLISS
, 256, { SIGN_BLISS_WITH_SHA512
, SIGN_UNKNOWN
}},
797 START_TEST(test_signature_schemes_for_key
)
799 enumerator_t
*enumerator
;
800 signature_scheme_t scheme
;
803 enumerator
= signature_schemes_for_key(scheme_data
[_i
].type
, scheme_data
[_i
].size
);
804 for (i
= 0; scheme_data
[_i
].expected
[i
] != SIGN_UNKNOWN
; i
++)
806 ck_assert(enumerator
->enumerate(enumerator
, &scheme
));
807 ck_assert_int_eq(scheme_data
[_i
].expected
[i
], scheme
);
809 ck_assert(!enumerator
->enumerate(enumerator
, &scheme
));
810 enumerator
->destroy(enumerator
);
814 Suite
*utils_suite_create()
819 /* force a timezone to match non-UTC conversions */
821 _putenv("TZ=GST-1GDT");
823 setenv("TZ", "Europe/Zurich", 1);
827 s
= suite_create("utils");
829 tc
= tcase_create("objects");
830 tcase_add_test(tc
, test_objects
);
831 suite_add_tcase(s
, tc
);
833 tc
= tcase_create("return functions");
834 tcase_add_test(tc
, test_return_functions
);
835 suite_add_tcase(s
, tc
);
837 tc
= tcase_create("timeval_add_ms");
838 tcase_add_test(tc
, test_timeval_add_ms
);
839 suite_add_tcase(s
, tc
);
841 tc
= tcase_create("htoun,untoh");
842 tcase_add_test(tc
, test_htoun
);
843 tcase_add_test(tc
, test_untoh
);
844 suite_add_tcase(s
, tc
);
846 tc
= tcase_create("round");
847 tcase_add_test(tc
, test_round
);
848 suite_add_tcase(s
, tc
);
850 tc
= tcase_create("string helper");
851 tcase_add_loop_test(tc
, test_strpfx
, 0, countof(strpfx_data
));
852 suite_add_tcase(s
, tc
);
854 tc
= tcase_create("malloc_align");
855 tcase_add_test(tc
, test_malloc_align
);
856 suite_add_tcase(s
, tc
);
858 tc
= tcase_create("memxor");
859 tcase_add_test(tc
, test_memxor
);
860 tcase_add_test(tc
, test_memxor_aligned
);
861 suite_add_tcase(s
, tc
);
863 tc
= tcase_create("memeq");
864 tcase_add_loop_test(tc
, test_memeq
, 0, countof(memeq_data
));
865 tcase_add_loop_test(tc
, test_memeq_const
, 0, countof(memeq_data
));
866 suite_add_tcase(s
, tc
);
868 tc
= tcase_create("memstr");
869 tcase_add_loop_test(tc
, test_memstr
, 0, countof(memstr_data
));
870 suite_add_tcase(s
, tc
);
872 tc
= tcase_create("utils_memrchr");
873 tcase_add_loop_test(tc
, test_utils_memrchr
, 0, countof(memrchr_data
));
874 suite_add_tcase(s
, tc
);
876 tc
= tcase_create("translate");
877 tcase_add_loop_test(tc
, test_translate
, 0, countof(translate_data
));
878 suite_add_tcase(s
, tc
);
880 tc
= tcase_create("strreplace");
881 tcase_add_loop_test(tc
, test_strreplace
, 0, countof(strreplace_data
));
882 suite_add_tcase(s
, tc
);
884 tc
= tcase_create("path_dirname");
885 tcase_add_loop_test(tc
, test_path_dirname
, 0, countof(path_data
));
886 suite_add_tcase(s
, tc
);
888 tc
= tcase_create("path_basename");
889 tcase_add_loop_test(tc
, test_path_basename
, 0, countof(path_data
));
890 suite_add_tcase(s
, tc
);
892 tc
= tcase_create("path_absolute");
893 tcase_add_loop_test(tc
, test_path_absolute
, 0, countof(path_data
));
894 suite_add_tcase(s
, tc
);
896 tc
= tcase_create("printf_hooks");
897 tcase_add_loop_test(tc
, test_time_printf_hook
, 0, countof(time_data
));
898 tcase_add_loop_test(tc
, test_time_delta_printf_hook
, 0, countof(time_delta_data
));
899 suite_add_tcase(s
, tc
);
901 tc
= tcase_create("mark_from_string");
902 tcase_add_loop_test(tc
, test_mark_from_string
, 0, countof(mark_data
));
903 suite_add_tcase(s
, tc
);
905 tc
= tcase_create("signature_schemes_for_key");
906 tcase_add_loop_test(tc
, test_signature_schemes_for_key
, 0, countof(scheme_data
));
907 suite_add_tcase(s
, tc
);