sp
[ghsmtp.git] / Hash.hpp
blob81c7215ff1c48ee706f5a1bfee55e30b15aa349a
1 #ifndef HASH_DOT_HPP
2 #define HASH_DOT_HPP
4 #include <string>
5 #include <string_view>
7 #include <openssl/sha.h>
9 #include <glog/logging.h>
11 #include <cppcodec/base32_crockford.hpp>
13 class Hash {
14 public:
15 Hash() { CHECK_EQ(SHA256_Init(&c), 1); }
17 void update(std::string_view s)
19 CHECK_EQ(SHA256_Update(&c, s.data(), s.length()), 1);
22 std::string final()
24 unsigned char md[SHA256_DIGEST_LENGTH];
25 CHECK_EQ(SHA256_Final(md, &c), 1);
26 return cppcodec::base32_crockford::encode(md);
29 private:
30 SHA256_CTX c;
33 #endif // HASH_DOT_HPP