summaryrefslogtreecommitdiffstats
path: root/twinstall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'twinstall.cpp')
-rw-r--r--twinstall.cpp50
1 files changed, 33 insertions, 17 deletions
diff --git a/twinstall.cpp b/twinstall.cpp
index 75d9a489e..752957638 100644
--- a/twinstall.cpp
+++ b/twinstall.cpp
@@ -40,7 +40,9 @@
#include "variables.h"
#include "data.hpp"
#include "partitions.hpp"
-#include "twrpDigest.hpp"
+#include "twrpDigestDriver.hpp"
+#include "twrpDigest/twrpDigest.hpp"
+#include "twrpDigest/twrpMD5.hpp"
#include "twrp-functions.hpp"
#include "gui/gui.hpp"
#include "gui/pages.hpp"
@@ -317,22 +319,36 @@ extern "C" int TWinstall_zip(const char* path, int* wipe_cache) {
gui_msg(Msg("installing_zip=Installing zip file '{1}'")(path));
if (strlen(path) < 9 || strncmp(path, "/sideload", 9) != 0) {
- gui_msg("check_for_md5=Checking for MD5 file...");
- twrpDigest md5sum;
- md5sum.setfn(path);
- 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;
+ string digest_str;
+ string Full_Filename = path;
+ string digest_file = path;
+ digest_file += ".md5";
+
+ gui_msg("check_for_digest=Checking for Digest file...");
+ if (!TWFunc::Path_Exists(digest_file)) {
+ gui_msg("no_digest=Skipping Digest check: no Digest file found");
+ }
+ else {
+ if (TWFunc::read_file(digest_file, digest_str) != 0) {
+ LOGERR("Skipping MD5 check: MD5 file unreadable\n");
+ }
+ else {
+ twrpDigest *digest = new twrpMD5();
+ if (!twrpDigestDriver::stream_file_to_digest(Full_Filename, digest)) {
+ delete digest;
+ return INSTALL_CORRUPT;
+ }
+ string digest_check = digest->return_digest_string();
+ if (digest_str == digest_check) {
+ gui_msg(Msg("digest_matched=Digest matched for '{1}'.")(path));
+ }
+ else {
+ LOGERR("Aborting zip install: Digest verification failed\n");
+ delete digest;
+ return INSTALL_CORRUPT;
+ }
+ delete digest;
+ }
}
}