Class thl::net::Sha256#
-
class Sha256#
SHA-256 (FIPS 180-4).
Implemented in plain C++ rather than against CommonCrypto / BCrypt / OpenSSL on purpose: it removes a whole platform matrix from a component that already needs one for HTTP, and it keeps the library free of a system crypto dependency. Throughput is a few hundred MB/s, which is irrelevant next to the download it verifies.
Not real-time safe and not intended to be — this runs on a worker thread after a transfer.
Public Types
-
using Digest = std::array<std::uint8_t, 32>#
Raw digest, 32 bytes.
Public Functions
-
Sha256()#
-
void update(const void *data, std::size_t size)#
Feed more bytes. May be called any number of times before finish().
-
Digest finish()#
Finish and return the digest.
The object must not be reused afterwards without reset().
-
void reset()#
Return to the initial state so the object can hash something else.
Public Static Functions
-
static std::string to_hex(const Digest &digest)#
Lowercase hex, 64 characters — the form the manifests use.
-
static FileResult of_file(const std::filesystem::path &path)#
-
struct FileResult#
Collaboration diagram for thl::net::Sha256::FileResult:
Convenience: hash a file in chunks, so size is bounded by the buffer and not by the file.
Returns an empty optional-shaped result — an all-zero digest with
ok == false— when the file cannot be read.
-
using Digest = std::array<std::uint8_t, 32>#