From a51036bf447a699511452da773dc4fad02192849 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Tue, 28 Jun 2022 17:44:01 +0200 Subject: add unit tests for vdf & md5, allow escaped quotes --- src/hash/md5/tests/md5cmp.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/hash/md5/tests/md5cmp.c (limited to 'src/hash/md5/tests/md5cmp.c') diff --git a/src/hash/md5/tests/md5cmp.c b/src/hash/md5/tests/md5cmp.c new file mode 100644 index 0000000..a34de3a --- /dev/null +++ b/src/hash/md5/tests/md5cmp.c @@ -0,0 +1,38 @@ +/** + * Compares the hash of a given string against a + * given hash + * + * Used for testing to ensure we don't run into + * Windows weirdness again + */ +#include +#include +#include + +#include "md5.h" + + +int main(int argc, char** argv) +{ + if (argc < 3) + { + puts("md5cmp input expected-hash"); + return 1; + } + + MD5_CTX context; + MD5_Init(&context); + MD5_Update(&context, argv[1], strlen(argv[1])); + + unsigned char digest[16]; + MD5_Final(digest, &context); + + char md5string[33]; + for(int i = 0; i < 16; ++i) + snprintf(&md5string[i*2], 3, "%02x", (unsigned int)digest[i]); + + if (!strncmp(md5string, argv[2], sizeof(md5string))) + return 0; + + return 1; +} \ No newline at end of file -- cgit v1.2.3