45 lines
936 B
C++
45 lines
936 B
C++
#ifndef FORTUNA_UTIL_H
|
|
#define FORTUNA_UTIL_H
|
|
|
|
#include <cryptopp/filters.h>
|
|
#include <cryptopp/hex.h>
|
|
#include <cryptopp/sha3.h>
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
|
|
namespace fortuna {
|
|
|
|
class Util final {
|
|
public:
|
|
static constexpr const std::size_t gen_block_size{32}; // 256 bits
|
|
|
|
static auto do_sha(const std::string& str_to_hash) -> const std::string {
|
|
// do sha256
|
|
std::string digest;
|
|
|
|
// no reason not to go for Keccak
|
|
CryptoPP::SHA3_256 sha3_256;
|
|
|
|
CryptoPP::StringSource str_src(str_to_hash, true,
|
|
new CryptoPP::HashFilter (
|
|
sha3_256, new CryptoPP::HexEncoder(
|
|
new CryptoPP::StringSink(digest), false))
|
|
);
|
|
|
|
return digest;
|
|
}
|
|
|
|
static auto current_time() -> std::chrono::time_point<std::chrono::system_clock,
|
|
std::chrono::duration<long, std::ratio<1, 1000000000>>> {
|
|
return std::chrono::system_clock::now();
|
|
}
|
|
|
|
Util() = delete;
|
|
~Util() noexcept;
|
|
|
|
}; // class Util
|
|
|
|
} // namespace fortuna
|
|
|
|
#endif//FORTUNA_UTIL_H
|