From 41dc933226730d6f4bde66a1bf39c1e8f55f8596 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 19 Sep 2017 22:08:31 +0200 Subject: [PATCH] More tests --- test/default/misuse.c | 38 ++++++++++++++++++++++++++++++++++++- test/default/sodium_utils.c | 13 +++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/test/default/misuse.c b/test/default/misuse.c index d1cced4a..65c59155 100644 --- a/test/default/misuse.c +++ b/test/default/misuse.c @@ -6,12 +6,48 @@ # include static void -sigabrt_handler_6(int sig) +sigabrt_handler_10(int sig) { (void) sig; exit(0); } +static void +sigabrt_handler_9(int sig) +{ + (void) sig; + signal(SIGABRT, sigabrt_handler_10); + assert(sodium_base642bin(NULL, 1, NULL, 1, NULL, NULL, NULL, -1) == -1); + exit(1); +} + +static void +sigabrt_handler_8(int sig) +{ + (void) sig; + signal(SIGABRT, sigabrt_handler_9); + assert(sodium_bin2base64(NULL, 1, NULL, 1, sodium_base64_VARIANT_ORIGINAL) == NULL); + exit(1); +} + +static void +sigabrt_handler_7(int sig) +{ + (void) sig; + signal(SIGABRT, sigabrt_handler_8); + assert(sodium_bin2base64(NULL, 1, NULL, 1, -1) == NULL); + exit(1); +} + +static void +sigabrt_handler_6(int sig) +{ + (void) sig; + signal(SIGABRT, sigabrt_handler_7); + assert(sodium_pad(NULL, NULL, SIZE_MAX, 16, 1) == -1); + exit(1); +} + static void sigabrt_handler_5(int sig) { diff --git a/test/default/sodium_utils.c b/test/default/sodium_utils.c index 6955feb8..19f3a0d8 100644 --- a/test/default/sodium_utils.c +++ b/test/default/sodium_utils.c @@ -209,6 +209,19 @@ main(void) assert(sodium_base642bin(buf1, sizeof buf1, "O", (size_t) 1U, NULL, NULL, NULL, sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == -1); + assert(sodium_base642bin(buf1, sizeof buf1, "kaw", (size_t) 3U, NULL, NULL, NULL, + sodium_base64_VARIANT_ORIGINAL) == -1); + assert(sodium_base642bin(buf1, sizeof buf1, "kQ*", (size_t) 3U, "@", NULL, NULL, + sodium_base64_VARIANT_ORIGINAL) == -1); + assert(sodium_base642bin(buf1, sizeof buf1, "kQ*", (size_t) 3U, "*", NULL, NULL, + sodium_base64_VARIANT_ORIGINAL) == -1); + assert(sodium_base642bin(buf1, sizeof buf1, "kaw=**", (size_t) 6U, "*", NULL, NULL, + sodium_base64_VARIANT_ORIGINAL) == 0); + assert(sodium_base642bin(buf1, sizeof buf1, "kaw*=*", (size_t) 6U, "~*", NULL, NULL, + sodium_base64_VARIANT_ORIGINAL) == 0); + assert(sodium_base642bin(buf1, sizeof buf1, "ka*w*=*", (size_t) 7U, "*~", NULL, NULL, + sodium_base64_VARIANT_ORIGINAL) == 0); + for (i = 0; i < 1000; i++) { assert(sizeof buf1 >= 100); bin_len = (size_t) randombytes_uniform(100);