Also added an SHA256 abstract class to core, with swappable implementation support.

This commit is contained in:
Relintai 2021-07-07 14:21:36 +02:00
parent 29496598c4
commit 95e54b3a41
3 changed files with 47 additions and 0 deletions

View File

@ -7,6 +7,7 @@ env.core_sources = []
env.add_source_files(env.core_sources, "*.cpp")
env.add_source_files(env.core_sources, "./html/*.cpp")
env.add_source_files(env.core_sources, "./http/*.cpp")
env.add_source_files(env.core_sources, "./hash/*.cpp")
env.add_source_files(env.core_sources, "./bry_http/*.cpp")
env.add_source_files(env.core_sources, "./database/*.cpp")

20
core/hash/sha256.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "sha256.h"
SHA256::SHA256() {
}
SHA256::~SHA256() {
}
SHA256 *SHA256::get() {
if (_sha_256_creation_func == nullptr) {
printf("Error: static SHA256 *get(): creation_func == nullptr\n");
return nullptr;
}
return _sha_256_creation_func();
}
SHA256 *(*SHA256::_sha_256_creation_func)(void) = nullptr;

26
core/hash/sha256.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef SHA256_H
#define SHA256_H
#include <string>
class SHA256 {
public:
virtual std::string compute(const void *data, size_t num_bytes) = 0;
virtual std::string compute(const std::string &text) = 0;
virtual void add(const void *data, size_t num_bytes) = 0;
virtual std::string get_hash() = 0;
virtual void get_hash(unsigned char *buffer, size_t buffer_len) = 0;
virtual void reset() = 0;
static SHA256 *get();
SHA256();
virtual ~SHA256();
protected:
static SHA256 *(*_sha_256_creation_func)(void);
};
#endif