blob: 08884cb649f10de7f53de22f48d283a42bc862b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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>();
}
|