implement basic unit testing

This commit is contained in:
2025-03-10 21:21:03 -04:00
parent 60996e3de2
commit 7258ef5810
4 changed files with 85 additions and 17 deletions

View File

@@ -20,7 +20,7 @@
#include <errno.h>
#include <libconfig.h>
#include <locale.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -669,7 +669,7 @@ print_hash(uchar *hash, uint length)
*
*/
int
/*int
stash_hash(uchar *stored_hash, uchar *hash, uint length)
{
if (sizeof(stored_hash) != 32 && LG_VERBOSE == 1) {
@@ -693,7 +693,7 @@ stash_hash(uchar *stored_hash, uchar *hash, uint length)
}
return 0;
}
} */
/*
* hash_file
@@ -704,8 +704,8 @@ stash_hash(uchar *stored_hash, uchar *hash, uint length)
*
*/
int
hash_file(const char *filename, uchar *destination_string)
unsigned char
hash_file(const char *filename)
{
FILE *data = fopen(filename, "rb");
if (! data && LG_VERBOSE == 1) {
@@ -749,20 +749,19 @@ hash_file(const char *filename, uchar *destination_string)
fclose(data);
if (sizeof(destination_hash) != EVP_MAX_MD_SIZE && LG_VERBOSE == 1) {
errlog("in hash_file()");
errlog("destination hash is invalid size");
errlog("ensure hash is declared with size EVP_MAX_MD_SIZE");
return 5;
}
else if (sizeof(destination_hash) != EVP_MAX_MD_SIZE) {
return 5;
}
uchar hash[EVP_MAX_MD_SIZE];
uint hash_length;
if (EVP_DigestFinal_ex(context, destination_hash, &hash_length) != 1) {
if (EVP_DigestFinal_ex(context, hash, &hash_length) != 1) {
if (LG_VERBOSE == 1) {
errlog("in hash_file()");
errlog("error finalizing digest");
}
EVP_MD_CTX_free(context);
return 6;
return 5;
}
EVP_MD_CTX_free(context);
return *hash;
}