Browse Source

- added support for sha512

- fixed result-length for sha256
master
art1pirat 2 years ago
parent
commit
57946bf91b
  1. 1
      src/include/checksum.hpp
  2. 13
      src/lib/checksum.cpp

1
src/include/checksum.hpp

@ -38,6 +38,7 @@ SequentialEnum(checksum_algorithms,
md5,
sha1,
sha256,
sha512,
);
string string_of_algorithm( checksum_algorithms alg);

13
src/lib/checksum.cpp

@ -25,6 +25,7 @@ string string_of_algorithm( checksum_algorithms alg) {
case md5: return string("md5");
case sha1: return string("sha1");
case sha256: return string("sha256");
case sha512: return string("sha512");
}
return string("");
}
@ -58,13 +59,22 @@ string Checksum::checksum_of_file(const string& filepath, checksum_algorithms al
break;
}
case sha256: {
unsigned char result[SHA_DIGEST_LENGTH];
unsigned char result[SHA256_DIGEST_LENGTH];
SHA256( memBlock, fileSize, result);
for (unsigned char i : result) {
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i);
}
break;
}
case sha512: {
unsigned char result[SHA512_DIGEST_LENGTH];
SHA512( memBlock, fileSize, result);
for (unsigned char i : result) {
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i);
}
break;
}
}
delete[] memBlock;
@ -104,6 +114,7 @@ oxum_t Checksum::oxum_of_filelist( list<string> files) {
}
return oxum;
}
void Checksum::get_logstream( stringstream & log ) {
log << this->log.rdbuf();
}

Loading…
Cancel
Save