1 /* $NetBSD: ssl_init.c,v 1.1.1.5 2016/01/08 21:21:33 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 void test_MD5KeyTypeWithoutDigestLength(void); 20 void test_MD5KeyTypeWithDigestLength(void); 21 void test_SHA1KeyTypeWithDigestLength(void); 22 void test_MD5KeyName(void); 23 void test_SHA1KeyName(void); 24 25 26 // keytype_from_text() 27 void 28 test_MD5KeyTypeWithoutDigestLength(void) { 29 TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", NULL)); 30 } 31 32 void 33 test_MD5KeyTypeWithDigestLength(void) { 34 size_t digestLength; 35 size_t expected = TEST_MD5_DIGEST_LENGTH; 36 37 TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", &digestLength)); 38 TEST_ASSERT_EQUAL(expected, digestLength); 39 } 40 41 42 void 43 test_SHA1KeyTypeWithDigestLength(void) { 44 #ifdef OPENSSL 45 size_t digestLength; 46 size_t expected = TEST_SHA1_DIGEST_LENGTH; 47 48 TEST_ASSERT_EQUAL(NID_sha, keytype_from_text("SHA", &digestLength)); 49 TEST_ASSERT_EQUAL(expected, digestLength); 50 /* OPENSSL */ 51 #else 52 TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined"); 53 #endif 54 } 55 56 57 // keytype_name() 58 void 59 test_MD5KeyName(void) { 60 TEST_ASSERT_EQUAL_STRING("MD5", keytype_name(KEY_TYPE_MD5)); 61 } 62 63 64 void 65 test_SHA1KeyName(void) { 66 #ifdef OPENSSL 67 TEST_ASSERT_EQUAL_STRING("SHA", keytype_name(NID_sha)); 68 #else 69 TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined"); 70 #endif /* OPENSSL */ 71 } 72