diff --git a/include/wxex/crypto.h b/include/wxex/crypto.h index 1dc79f7..051767b 100644 --- a/include/wxex/crypto.h +++ b/include/wxex/crypto.h @@ -22,6 +22,7 @@ #include "common.h" #include +#include #include #include @@ -152,6 +153,33 @@ public: } + /// + /// Hashes a file + /// + /// \param[in] fileName The path of the file to calculate hash of + /// + /// \returns + /// - true if hashing succeeded + /// - false otherwise + /// + inline bool HashFile(const wxString &fileName) + { + wxFFile file(fileName, wxT("rb")); + if (file.IsOpened()) { + wxMemoryBuffer buf(4*1024); + char *data = (char*)buf.GetData(); + size_t nBlock = buf.GetBufSize(); + while (!file.Eof()) + Hash(data, file.Read(data, nBlock)); + + return true; + } else { + wxLogError(wxT("Can not open %s file for reading."), fileName.c_str()); + return false; + } + } + + /// /// Finish hashing and return hash data. ///