Skip to content

Instantly share code, notes, and snippets.

@thomasb9511
Last active May 21, 2023 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasb9511/f570ecad82055b34a27ec9e706f596c9 to your computer and use it in GitHub Desktop.
Save thomasb9511/f570ecad82055b34a27ec9e706f596c9 to your computer and use it in GitHub Desktop.
template<typename F>
std::string hash_file(std::string filename) {
F hash;
std::string digest;
CryptoPP::FileSource f(filename.c_str(), true,
new CryptoPP::HashFilter(hash, new CryptoPP::StringSink(digest)));
return digest;
}
template<typename F>
bool verify(const std::string &digest, const std::string &filename) {
/* // Create a verifier with DEFAULT_FLAGS
CryptoPP::byte result = 0;
{
CryptoPP::HashVerificationFilter verifier(hash,
new CryptoPP::ArraySink(&result, sizeof(result)));
// Wrap the data in sources
CryptoPP::StringSource ss(digest, true);
CryptoPP::FileSource fs(filename.c_str(), true);
// Add the data to the filter. The digest is added first due to HASH_AT_BEGIN
ss.TransferTo(verifier);
fs.TransferTo(verifier);
// Signal end of data. The verifier will finish calculating
// the digest, and compare the expected and calculated digests.
verifier.MessageEnd();
}*/
// Keeping the program memory under control.
return digest == hash_file<F>(filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment