|
|
@ -23,37 +23,41 @@ string Checksum::checksum_of_file(string filepath, checksum_algorithms alg) { |
|
|
|
char * memBlock; |
|
|
|
fileSize = file.tellg(); |
|
|
|
memBlock = new char[fileSize]; |
|
|
|
file.seekg(0,ios::beg); |
|
|
|
file.read(memBlock, fileSize); |
|
|
|
switch ( alg ) { |
|
|
|
case md5: { |
|
|
|
unsigned char result[MD5_DIGEST_LENGTH]; |
|
|
|
MD5((unsigned char*) memBlock, fileSize, result); |
|
|
|
for (int i=0; i<MD5_DIGEST_LENGTH; i++) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << (int) result[i]; |
|
|
|
if (NULL != memBlock) { |
|
|
|
file.seekg(0,ios::beg); |
|
|
|
file.read(memBlock, fileSize); |
|
|
|
switch ( alg ) { |
|
|
|
case md5: { |
|
|
|
unsigned char result[MD5_DIGEST_LENGTH]; |
|
|
|
MD5((unsigned char*) memBlock, fileSize, result); |
|
|
|
for (int i=0; i<MD5_DIGEST_LENGTH; i++) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << (int) result[i]; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case sha1: { |
|
|
|
unsigned char result[SHA_DIGEST_LENGTH]; |
|
|
|
SHA1((unsigned char*) memBlock, fileSize, result); |
|
|
|
for (int i=0; i<SHA_DIGEST_LENGTH; i++) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << (int) result[i]; |
|
|
|
case sha1: { |
|
|
|
unsigned char result[SHA_DIGEST_LENGTH]; |
|
|
|
SHA1((unsigned char*) memBlock, fileSize, result); |
|
|
|
for (int i=0; i<SHA_DIGEST_LENGTH; i++) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << (int) result[i]; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case sha256: { |
|
|
|
unsigned char result[SHA_DIGEST_LENGTH]; |
|
|
|
SHA256((unsigned char*) memBlock, fileSize, result); |
|
|
|
for (int i=0; i<SHA_DIGEST_LENGTH; i++) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << (int) result[i]; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case sha256: { |
|
|
|
unsigned char result[SHA_DIGEST_LENGTH]; |
|
|
|
SHA256((unsigned char*) memBlock, fileSize, result); |
|
|
|
for (int i=0; i<SHA_DIGEST_LENGTH; i++) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << (int) result[i]; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
delete memBlock[]; |
|
|
|
// cout << "# # CHECKSUM for filepath '" << filepath << "' " << hex_result.str() << endl;
|
|
|
|
}else { |
|
|
|
cout << "could not alloc memory" << endl; |
|
|
|
} |
|
|
|
delete memBlock; |
|
|
|
// cout << "# # CHECKSUM for filepath '" << filepath << "' " << hex_result.str() << endl;
|
|
|
|
file.close(); |
|
|
|
} else { |
|
|
|
cout << "file '"<< filepath << "' could not be opened" << endl; |
|
|
@ -78,10 +82,10 @@ oxum_t Checksum::oxum_of_file(string filepath) { |
|
|
|
} |
|
|
|
|
|
|
|
oxum_t Checksum::oxum_of_filelist( list<string> files) { |
|
|
|
oxum_t oxum; |
|
|
|
oxum.octetcount=0; |
|
|
|
oxum.streamcount=0; |
|
|
|
list<string>::iterator i; |
|
|
|
oxum_t oxum; |
|
|
|
oxum.octetcount=0; |
|
|
|
oxum.streamcount=0; |
|
|
|
list<string>::iterator i; |
|
|
|
for (i=files.begin(); i!= files.end(); i++) { |
|
|
|
oxum_t tmp = this->oxum_of_file( *i ); |
|
|
|
oxum.octetcount+= tmp.octetcount; |
|
|
|