diff options
| -rw-r--r-- | src/functions.hpp | 21 | ||||
| -rw-r--r-- | src/main.cpp | 8 |
2 files changed, 16 insertions, 13 deletions
diff --git a/src/functions.hpp b/src/functions.hpp index 97ec8b2..123f4ab 100644 --- a/src/functions.hpp +++ b/src/functions.hpp @@ -5,18 +5,27 @@ #ifndef T_FUNCTIONS_HPP #define T_FUNCTIONS_HPP +#include "sha256/picosha2.h" + std::string <rim(std::string &str, const std::string &chars = "\t\n\v\f\r ") { - str.erase(0, str.find_first_not_of(chars)); - return str; + str.erase(0, str.find_first_not_of(chars)); + return str; } std::string &rtrim(std::string &str, const std::string &chars = "\t\n\v\f\r ") { - str.erase(str.find_last_not_of(chars) + 1); - return str; + str.erase(str.find_last_not_of(chars) + 1); + return str; } std::string &trim(std::string &str, const std::string &chars = "\t\n\v\f\r ") { - return ltrim(rtrim(str, chars), chars); + return ltrim(rtrim(str, chars), chars); } -#endif //T_FUNCTIONS_HPP +std::string sha256_hash(std::string text) { + std::vector<unsigned char> hash(picosha2::k_digest_size); + picosha2::hash256(text.begin(), text.end(), hash.begin(), hash.end()); + + std::string hex_str = picosha2::bytes_to_hex_string(hash.begin(), hash.end()); + return hex_str; +} +#endif // T_FUNCTIONS_HPP diff --git a/src/main.cpp b/src/main.cpp index c5ffd45..cc1144f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #include "functions.hpp" #include "opts/cxxopts.hpp" -#include "sha256/picosha2.h" using namespace std; @@ -38,12 +37,7 @@ int main(int argc, char *argv[]) { str += s + " "; } auto src_str = trim(str); - std::vector<unsigned char> hash(picosha2::k_digest_size); - picosha2::hash256(src_str.begin(), src_str.end(), hash.begin(), hash.end()); - - std::string hex_str = - picosha2::bytes_to_hex_string(hash.begin(), hash.end()); - cout << "sha256('" << str << "'): " << hex_str << endl; + cout << "sha256('" << str << "'): " << sha256_hash(str) << endl; } std::string taskdir; if (result.count("taskdir")) { |