summaryrefslogtreecommitdiffstats
path: root/twrpDigest.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--twrpDigest.cpp60
1 files changed, 43 insertions, 17 deletions
diff --git a/twrpDigest.cpp b/twrpDigest.cpp
index 0dd3ea904..ab8f456f5 100644
--- a/twrpDigest.cpp
+++ b/twrpDigest.cpp
@@ -48,13 +48,47 @@ void twrpDigest::setfn(const string& fn) {
md5fn = fn;
}
+void twrpDigest::initMD5(void) {
+ MD5Init(&md5c);
+ md5string = "";
+}
+
+int twrpDigest::updateMD5stream(unsigned char* stream, int len) {
+ if (md5fn.empty()) {
+ MD5Update(&md5c, stream, len);
+ }
+ else {
+ return -1;
+ }
+ return 0;
+}
+
+void twrpDigest::finalizeMD5stream() {
+ MD5Final(md5sum, &md5c);
+}
+
+string twrpDigest::createMD5string() {
+ int i;
+ char hex[3];
+
+ for (i = 0; i < 16; ++i) {
+ snprintf(hex, 3, "%02x", md5sum[i]);
+ md5string += hex;
+ }
+ if (!md5fn.empty()) {
+ md5string += " ";
+ md5string += basename((char*) md5fn.c_str());
+ md5string += + "\n";
+ }
+ return md5string;
+}
+
int twrpDigest::computeMD5(void) {
string line;
- struct MD5Context md5c;
FILE *file;
int len;
unsigned char buf[1024];
- MD5Init(&md5c);
+ initMD5();
file = fopen(md5fn.c_str(), "rb");
if (file == NULL)
return -1;
@@ -67,21 +101,13 @@ int twrpDigest::computeMD5(void) {
}
int twrpDigest::write_md5digest(void) {
- int i;
- string md5string, md5file;
- char hex[3];
+ string md5file, md5str;
md5file = md5fn + ".md5";
- for (i = 0; i < 16; ++i) {
- snprintf(hex, 3, "%02x", md5sum[i]);
- md5string += hex;
- }
- md5string += " ";
- md5string += basename((char*) md5fn.c_str());
- md5string += + "\n";
- TWFunc::write_file(md5file, md5string);
+ md5str = createMD5string();
+ TWFunc::write_file(md5file, md5str);
tw_set_default_metadata(md5file.c_str());
- LOGINFO("MD5 for %s: %s\n", md5fn.c_str(), md5string.c_str());
+ LOGINFO("MD5 for %s: %s\n", md5fn.c_str(), md5str.c_str());
return 0;
}
@@ -124,7 +150,7 @@ int twrpDigest::verify_md5digest(void) {
string buf;
char hex[3];
int i, ret;
- string md5string;
+ string md5str;
ret = read_md5digest();
if (ret != 0)
@@ -136,9 +162,9 @@ int twrpDigest::verify_md5digest(void) {
computeMD5();
for (i = 0; i < 16; ++i) {
snprintf(hex, 3, "%02x", md5sum[i]);
- md5string += hex;
+ md5str += hex;
}
- if (tokens.at(0) != md5string) {
+ if (tokens.at(0) != md5str) {
gui_err("md5_fail=MD5 does not match");
return -2;
}