1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-29 01:19:11 +00:00

(svn r11695) -Codechange: Converted the md5 algorithm to OOP

-Codechange: Adapt the md5 algorithm to the OpenTTD source
This commit is contained in:
skidd13
2007-12-25 13:59:21 +00:00
parent b3f6c0734b
commit 7963963d98
7 changed files with 240 additions and 312 deletions

View File

@@ -20,7 +20,7 @@
struct MD5File {
const char * filename; ///< filename
md5_byte_t hash[16]; ///< md5 sum of the file
uint8 hash[16]; ///< md5 sum of the file
};
struct FileList {
@@ -108,20 +108,19 @@ static bool FileMD5(const MD5File file)
FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size);
if (f != NULL) {
md5_state_t filemd5state;
md5_byte_t buffer[1024];
md5_byte_t digest[16];
Md5 checksum;
uint8 buffer[1024];
uint8 digest[16];
size_t len;
md5_init(&filemd5state);
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
size -= len;
md5_append(&filemd5state, buffer, len);
checksum.Append(buffer, len);
}
FioFCloseFile(f);
md5_finish(&filemd5state, digest);
checksum.Finish(digest);
return memcmp(file.hash, digest, sizeof(file.hash)) == 0;
} else { // file not found
return false;