2016-07-26 15:53:52 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include "minunit.h"
|
|
|
|
|
2016-07-31 14:42:29 +00:00
|
|
|
#include "mh/errors.h"
|
2016-07-26 15:53:52 +00:00
|
|
|
#include "mh/hashes.h"
|
|
|
|
|
|
|
|
char error_buf[256];
|
|
|
|
|
|
|
|
static char *test_all_hashes_have_lengths(void) {
|
|
|
|
int i = 0;
|
2016-07-31 14:42:29 +00:00
|
|
|
int length = 0;
|
2016-07-26 15:53:52 +00:00
|
|
|
for (; i < MH_H_COUNT; i++) {
|
2016-07-31 18:31:19 +00:00
|
|
|
length = mh_hash_default_length(mh_all_hashes[i]);
|
2016-07-27 09:45:53 +00:00
|
|
|
sprintf(error_buf, "mh_hash_default_length: hash %d"
|
|
|
|
" returned invalid (%d) default length",
|
|
|
|
i, length);
|
|
|
|
mu_assert(error_buf, length > 0);
|
2016-07-26 15:53:52 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-31 14:42:29 +00:00
|
|
|
static char *test_error_when_out_of_bands(void) {
|
|
|
|
mu_assert("out of bands index should give error",
|
|
|
|
mh_hash_default_length(1 << 20) == MH_E_UNKNOWN_CODE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *test_lengths_are_correct_for_known_codes(void) {
|
|
|
|
#define hlen mh_hash_default_length
|
|
|
|
mu_assert("sha1 has valid length", hlen(MH_H_SHA1) == 20);
|
|
|
|
mu_assert("sha3-512 has valid length", hlen(MH_H_SHA3_256) == 32);
|
|
|
|
mu_assert("shake-128 has valid length", hlen(MH_H_SHAKE_128) == 16);
|
|
|
|
|
|
|
|
#undef hlen
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-26 15:53:52 +00:00
|
|
|
static char *mu_all_tests(void) {
|
|
|
|
mu_run_test(test_all_hashes_have_lengths);
|
2016-07-31 14:42:29 +00:00
|
|
|
mu_run_test(test_error_when_out_of_bands);
|
|
|
|
mu_run_test(test_lengths_are_correct_for_known_codes);
|
2016-07-26 15:53:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|