MD5 verification sanity

We can use switches and enums to make things more understandable
and work with results in a more sensible manner.

PS2: Move file MD5 verification and error handling into
     a separate function to reduce code.

PS3: Default to false in Check_Restore_File_MD5 function

Change-Id: Id3ee0bb444cf13be67bb5dec2c43f7c26a86b954
(cherry picked from commit 5c3950716e5c7c6279efd5f3f338d6d22e5215e2)
This commit is contained in:
James Christopher Adduono
2016-10-25 02:18:32 -04:00
committed by Dees Troy
parent 9059499ccd
commit 79ae093c82
22 changed files with 75 additions and 57 deletions
+12 -3
View File
@@ -296,9 +296,18 @@ extern "C" int TWinstall_zip(const char* path, int* wipe_cache) {
gui_msg("check_for_md5=Checking for MD5 file...");
twrpDigest md5sum;
md5sum.setfn(path);
int md5_return = md5sum.verify_md5digest();
if (md5_return == -2) { // md5 did not match
LOGERR("Aborting zip install\n");
switch (md5sum.verify_md5digest()) {
case MD5_OK:
gui_msg(Msg("md5_matched=MD5 matched for '{1}'.")(path));
break;
case MD5_NOT_FOUND:
gui_msg("no_md5=Skipping MD5 check: no MD5 file found");
break;
case MD5_FILE_UNREADABLE:
LOGERR("Skipping MD5 check: MD5 file unreadable\n");
break;
case MD5_MATCH_FAIL: // md5 did not match
LOGERR("Aborting zip install: MD5 verification failed\n");
return INSTALL_CORRUPT;
}
}