xref: /netbsd-src/external/bsd/ntp/dist/tests/libntp/ssl_init.c (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 /*	$NetBSD: ssl_init.c,v 1.1.1.2 2015/07/10 13:11:14 christos Exp $	*/
2 
3 #include "config.h"
4 
5 #include "ntp.h"
6 
7 #ifdef OPENSSL
8 # include "openssl/err.h"
9 # include "openssl/rand.h"
10 # include "openssl/evp.h"
11 #endif
12 
13 #include "unity.h"
14 
15 
16 static const size_t TEST_MD5_DIGEST_LENGTH = 16;
17 static const size_t TEST_SHA1_DIGEST_LENGTH = 20;
18 
19 
20 // keytype_from_text()
21 void test_MD5KeyTypeWithoutDigestLength() {
22 	TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", NULL));
23 }
24 
25 void test_MD5KeyTypeWithDigestLength() {
26 	size_t digestLength;
27 	size_t expected = TEST_MD5_DIGEST_LENGTH;
28 
29 	TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", &digestLength));
30 	TEST_ASSERT_EQUAL(expected, digestLength);
31 }
32 
33 
34 void test_SHA1KeyTypeWithDigestLength() {
35 #ifdef OPENSSL
36 	size_t digestLength;
37 	size_t expected = TEST_SHA1_DIGEST_LENGTH;
38 
39 	TEST_ASSERT_EQUAL(NID_sha, keytype_from_text("SHA", &digestLength));
40 	TEST_ASSERT_EQUAL(expected, digestLength);
41 	/* OPENSSL */
42 #else
43 	TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
44 #endif
45 }
46 
47 
48 // keytype_name()
49 void test_MD5KeyName() {
50 	TEST_ASSERT_EQUAL_STRING("MD5", keytype_name(KEY_TYPE_MD5));
51 }
52 
53 void test_SHA1KeyName() {
54 #ifdef OPENSSL
55 	TEST_ASSERT_EQUAL_STRING("SHA", keytype_name(NID_sha));
56 #else
57 	TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
58 #endif	/* OPENSSL */
59 }
60 
61