diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-06-28 17:44:01 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-06-28 17:44:01 +0200 |
commit | a51036bf447a699511452da773dc4fad02192849 (patch) | |
tree | 116b9ec1d527e02db9023c836721bd046fe320ff /src/hash/md5/tests | |
parent | a93baa212f3c7b57a08cb9084d38994290195d78 (diff) | |
download | OFQT-a51036bf447a699511452da773dc4fad02192849.tar.gz OFQT-a51036bf447a699511452da773dc4fad02192849.zip |
add unit tests for vdf & md5, allow escaped quotesvdf-parser
Diffstat (limited to 'src/hash/md5/tests')
-rw-r--r-- | src/hash/md5/tests/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/hash/md5/tests/md5cmp.c | 38 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/hash/md5/tests/CMakeLists.txt b/src/hash/md5/tests/CMakeLists.txt new file mode 100644 index 0000000..8b03af4 --- /dev/null +++ b/src/hash/md5/tests/CMakeLists.txt @@ -0,0 +1,7 @@ + +add_executable(md5cmp md5cmp.c) +target_link_libraries(md5cmp md5) + +add_test(NAME md5_hash_test + COMMAND md5cmp ABCDEF 8827a41122a5028b9808c7bf84b9fcf6 + )
\ No newline at end of file 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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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 |