26 template<
typename Algo = CryptoPP::SHA256>
27 static std::array<byte, Algo::DIGESTSIZE>
bytes(
const byte *buffer,
const std::size_t buffSize) {
28 std::array<byte, Algo::DIGESTSIZE> out{};
30 const CryptoPP::ArraySource vs(buffer, buffSize,
true,
new CryptoPP::HashFilter(algo,
new CryptoPP::ArraySink(out.data(), out.size())));
34 template<
typename Algo = CryptoPP::SHA256>
35 static std::array<byte, Algo::DIGESTSIZE>
bytes(
const std::vector<byte>& buffer) {
36 return bytes<Algo>(buffer.data(), buffer.size());
39 template<
typename Algo = CryptoPP::SHA256>
40 static std::string
str(
const std::vector<byte>& buffer,
const bool uppercase =
false) {
43 const CryptoPP::VectorSource vs(buffer,
true,
new CryptoPP::HashFilter(algo,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(out), uppercase)));
47 template<
typename Algo = CryptoPP::SHA256>
48 static std::array<byte, Algo::DIGESTSIZE>
fileBytes(
const fs::path& filename) {
50 std::array<byte, Algo::DIGESTSIZE> out{};
52 std::ifstream file{filename, std::ios::binary};
56 const CryptoPP::FileSource fs(file,
58 new CryptoPP::HashFilter(algo,
new CryptoPP::ArraySink(out.data(), out.size())));
63 std::array<byte, Algo::DIGESTSIZE> out{};
64 const CryptoPP::FileSource fileSource(filename.string().c_str(),
true,
65 new CryptoPP::HashFilter(
67 new CryptoPP::ArraySink(out.data(), out.size())));
70 std::array<byte, Algo::DIGESTSIZE> out{};
73 algo.Update(chunk.data(), chunk.size());
76 algo.Final(out.data());
81 template<
typename Algo = CryptoPP::SHA256>
82 static std::string
fileStr(
const fs::path& filename,
const bool uppercase =
false) {
85 std::ifstream file{filename, std::ios::binary};
88 const CryptoPP::FileSource fs(file,
true,
new CryptoPP::HashFilter(Algo(),
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(out), uppercase)));
95 const CryptoPP::FileSource fileSource(filename.string().c_str(),
true,
96 new CryptoPP::HashFilter(
98 new CryptoPP::HexEncoder(
99 new CryptoPP::StringSink(out),
103 return stringify<Algo>(fileBytes<Algo>(filename), uppercase);
107 template<
typename Algo = CryptoPP::SHA256>
108 static std::string
stringify(
const std::array<byte, Algo::DIGESTSIZE>& hash,
const bool uppercase =
false) {
109 std::ostringstream out{};
111 out << std::uppercase;
112 for (
const byte digest : hash) {
113 out << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(digest);
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
#define ENIGMA_ASSERT_OR_THROW(x, msg)
static void ReadChunks(const fs::path &filename, const std::size_t max_chunk_size, const std::function< bool(std::vector< byte > &&)> &callback)
static std::array< byte, Algo::DIGESTSIZE > fileBytes(const fs::path &filename)
static std::string stringify(const std::array< byte, Algo::DIGESTSIZE > &hash, const bool uppercase=false)
static std::array< byte, Algo::DIGESTSIZE > bytes(const std::vector< byte > &buffer)
static std::array< byte, Algo::DIGESTSIZE > bytes(const byte *buffer, const std::size_t buffSize)
static std::string str(const std::vector< byte > &buffer, const bool uppercase=false)
static std::string fileStr(const fs::path &filename, const bool uppercase=false)