-
-
Save thomasb9511/f570ecad82055b34a27ec9e706f596c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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