diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
| commit | 6232d13f5321b87ddf12a1aa36b4545da45f173d (patch) | |
| tree | 23f3316470a14136debd9d02f9e920ca2b06f4cc /src/hash_method_openssl.cc | |
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in
memroy.
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>(); +} |
