diff --git a/Implementierung/lib/io.h b/Implementierung/lib/io.h index 4d0ee2f..f780a77 100644 --- a/Implementierung/lib/io.h +++ b/Implementierung/lib/io.h @@ -14,10 +14,9 @@ * @brief reads a file at a path * * @param path the filepath - * @param data where to store the pointer to the data * @param size a pointer where the size of the result should be stored - * @return the raw data + * @return pointer to the raw data or NULL on errors */ -bool read_file(const char* path, uint8_t** data, size_t* size); +uint8_t* read_file(const char* path, size_t* size); #endif // IO_H \ No newline at end of file diff --git a/Implementierung/lib/md2.h b/Implementierung/lib/md2.h index 5fd07d3..a692a12 100644 --- a/Implementierung/lib/md2.h +++ b/Implementierung/lib/md2.h @@ -25,6 +25,12 @@ void md2_hash(size_t len, const uint8_t buf[], uint8_t out[16]); */ void md2_checksum(size_t len, uint8_t* buf); +/** + * @brief Takes a uint8_t array and converts it into a string + * + * @param hash the array containing the hash + * @param stringHash pointer to store the string, has to have 32 bytes space + */ void encodeHash(uint8_t hash[16], char* stringHash); #endif // MD2_H \ No newline at end of file diff --git a/Implementierung/src/io.c b/Implementierung/src/io.c index cd7bee3..dedb5ce 100644 --- a/Implementierung/src/io.c +++ b/Implementierung/src/io.c @@ -1,13 +1,13 @@ #include "../lib/io.h" -bool read_file(const char* path, uint8_t** data, size_t* size) { +uint8_t* read_file(const char* path, size_t* size) { // Read the contents of the file specified by path into a heap-allocated // buffer and return a pointer to that buffer. FILE* f = fopen(path, "r"); if (f == NULL) { printf("Fopen error: %d\n", errno); fclose(f); - return false; + return NULL; } struct stat statOfFile; @@ -15,28 +15,28 @@ bool read_file(const char* path, uint8_t** data, size_t* size) { if (status == -1) { printf("Fstat error: %d\n", errno); fclose(f); - return false; + return NULL; }; if ((statOfFile.st_mode & S_IFMT) != S_IFREG) { printf("File is not a regular file!\n"); fclose(f); - return false; + return NULL; } - (*data) = malloc(statOfFile.st_size); + uint8_t* data = malloc(statOfFile.st_size); size_t bytesRead = - fread((*data), statOfFile.st_blksize, statOfFile.st_blocks, f); + fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f); // size_t bytesRead = fread(data, sizeof(uint8_t), statOfFile.st_size, f); if (bytesRead != 0 && !feof(f)) { printf("Error reading file!\n"); fclose(f); - return false; + return NULL; } fclose(f); (*size) = statOfFile.st_size; - return true; + return data; } \ No newline at end of file diff --git a/Implementierung/src/main.c b/Implementierung/src/main.c index 4591802..811289d 100644 --- a/Implementierung/src/main.c +++ b/Implementierung/src/main.c @@ -67,11 +67,12 @@ int main(int argc, char** argv) { // runTests(); size_t len; - uint8_t* data; - if (!read_file(c.filename, &data, &len)) { + uint8_t* data = read_file(c.filename, &len); + if (data == NULL) { printf("Error reading file %s!", c.filename); return EXIT_FAILURE; } + printf("File read with size: %zu\n", len); printf("\n");