// SHA-256 (FIPS 180-4), dependency-free, for provenance hashes of inputs/artifacts. #pragma once #include #include #include #include #include namespace raid { class Sha256 { public: Sha256(); void update(const void* data, std::size_t len); void update(std::string_view s) { update(s.data(), s.size()); } std::array digest(); std::string hex(); static std::string of(std::string_view s) { Sha256 h; h.update(s); return h.hex(); } static std::string of_file(const std::string& path); template static std::string of_span(std::span x) { Sha256 h; h.update(x.data(), x.size_bytes()); return h.hex(); } private: void transform(const std::uint8_t* chunk); std::array h_; std::array buf_{}; std::size_t buf_len_{0}; std::uint64_t total_{0}; }; } // namespace raid