diff options
Diffstat (limited to 'src/hash_method_openssl.cc')
| -rw-r--r-- | src/hash_method_openssl.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/hash_method_openssl.cc b/src/hash_method_openssl.cc new file mode 100644 index 0000000..08884cb --- /dev/null +++ b/src/hash_method_openssl.cc @@ -0,0 +1,34 @@ +#include "common.hh" + +#include "hash_method.hh" + +#include <openssl/sha.h> + +namespace { + +class Sha256HashMethod : public HashMethod { +public: + Sha256HashMethod() { + SHA256_Init(&ctx_); + } + + void update(void const* data, size_t count) override { + SHA256_Update(&ctx_, data, count); + } + + std::string finish() override { + uint8_t out[SHA256_DIGEST_LENGTH]; + SHA256_Final(out, &ctx_); + SHA256_Init(&ctx_); + return to_string(out, sizeof(out)); + } + +private: + SHA256_CTX ctx_; +}; + +} // namespace + +std::unique_ptr<HashMethod> HashMethod::sha256() { + return std::make_unique<Sha256HashMethod>(); +} |
