#include "common.hh" #include "hash_method.hh" #include namespace { class Sha256HashMethod : public HashMethod { public: Sha256HashMethod() { ctx_ = EVP_MD_CTX_new(); EVP_DigestInit_ex(ctx_, EVP_sha256(), nullptr); } ~Sha256HashMethod() override { EVP_MD_CTX_free(ctx_); } void update(void const* data, size_t count) override { EVP_DigestUpdate(ctx_, data, count); } std::string finish() override { uint8_t out[EVP_MAX_MD_SIZE]; unsigned int len; EVP_DigestFinal_ex(ctx_, out, &len); EVP_DigestInit_ex(ctx_, EVP_sha256(), nullptr); return to_string(out, len); } private: EVP_MD_CTX* ctx_; }; } // namespace std::unique_ptr HashMethod::sha256() { return std::make_unique(); }