From c79f8a942740ec85af61103024b649174913f126 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Tue, 2 Oct 2012 17:19:08 +0000 Subject: [PATCH] Set hash tests to auto calculate number of tests --- t/md5.c | 24 ++++-------------------- t/sha1.c | 26 ++++---------------------- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/t/md5.c b/t/md5.c index 570e613..5087605 100644 --- a/t/md5.c +++ b/t/md5.c @@ -12,25 +12,6 @@ #include "pduuid.h" #include "ctap.h" -static int strbytes(char *s, unsigned char *d) { - unsigned int byte; - int i = 0; - - if (!s) return 0; - if (*s == 0) return 0; - - while (*s) { - if (*s == '-' || *s == ':') s++; - - if (sscanf(s, "%02x", &byte) != 1) { - return 0; - } - s += 2; - d[i++] = byte & 0xff; - } - return i; -} - void ufmt(pd_uuid_t *uuid, char *s) { int i; for (i=0;i<4;i++) { @@ -65,6 +46,7 @@ int main(int ac, char *av[]) { unsigned char tmp[16]; hash_state md; int i; + int n; static const struct { char *msg; @@ -94,7 +76,9 @@ int main(int ac, char *av[]) { { NULL, { 0 } } }; - plan(7); + for(n=0;tests[n].msg != NULL;n++); + + plan(n); for (i = 0; tests[i].msg != NULL; i++) { md5_init(&md); diff --git a/t/sha1.c b/t/sha1.c index 86ba412..4096552 100644 --- a/t/sha1.c +++ b/t/sha1.c @@ -18,33 +18,13 @@ static void bytestr(unsigned char *h, char *s, int len) { } } -#if 0 -static int strbytes(char *s, unsigned char *d) { - unsigned int byte; - int i = 0; - - if (!s) return 0; - if (*s == 0) return 0; - - while (*s) { - if (*s == '-' || *s == ':' || *s == ' ') s++; - - if (sscanf(s, "%02x", &byte) != 1) { - return 0; - } - s += 2; - d[i++] = byte & 0xff; - } - return i; -} -#endif - int main(int ac, char *av[]) { unsigned char tmp[20]; hash_state md; int i, j; char want[64]; char have[64]; + int n; static struct { char *msg; @@ -72,7 +52,9 @@ int main(int ac, char *av[]) { { NULL, 0, { 0 } } }; - plan(8); + for (n=0;tests[n].msg != NULL; n++); + + plan(2*n); for (i = 0; tests[i].msg != NULL; i++) { sha1_init(&md); -- 2.40.0