Hash
Hash
#include <icy/crypto/hash.h>Incremental cryptographic hash engine wrapping OpenSSL EVP digest functions.
Construct with an algorithm name recognized by OpenSSL (e.g. "sha256", "md5"). Feed data with one or more calls to update(), then call digest() or digestStr() to finalize and retrieve the result. Call reset() to reuse the engine for a new computation without reallocating the context.
Public Methods
| Return | Name | Description |
|---|---|---|
Hash | Constructs a Hash engine for the given algorithm. | |
~Hash | Destroys the Hash engine and releases OpenSSL resources. | |
void | update | Feeds a single character into the digest computation. |
void | update | Feeds a string view into the digest computation. |
void | update | Feeds a raw memory buffer into the digest computation. |
const ByteVec & | digest | Finalizes the digest computation and returns the raw binary result. |
std::string | digestStr | Finalizes the digest computation and returns the result as a raw binary string (not hex-encoded). Use icy::hex::encode() on digest() if you need a printable representation. |
void | reset | Resets the digest context and clears the cached result, allowing the engine to be reused for a new computation with the same algorithm. |
const std::string & | algorithm const | Returns the algorithm name this engine was constructed with. |
Hash
Hash(const std::string & algorithm)Constructs a Hash engine for the given algorithm.
Parameters
algorithmOpenSSL digest name (e.g. "sha256", "sha1", "md5").
Exceptions
std::runtime_errorif the algorithm is not recognized by OpenSSL.
~Hash
~Hash()Destroys the Hash engine and releases OpenSSL resources.
update
void update(char data)Feeds a single character into the digest computation.
Parameters
dataThe byte to hash.
update
void update(std::string_view data)Feeds a string view into the digest computation.
Parameters
dataThe data to hash.
update
void update(const void * data, size_t length)Feeds a raw memory buffer into the digest computation.
This method may be called multiple times for streaming large inputs.
Parameters
dataPointer to the input buffer.lengthNumber of bytes to hash fromdata.
digest
const ByteVec & digest()Finalizes the digest computation and returns the raw binary result.
The result is computed on the first call and cached; subsequent calls return the same value without recomputing. Call reset() before reusing the engine for a new computation.
Returns
Reference to the internal byte vector containing the digest.
digestStr
std::string digestStr()Finalizes the digest computation and returns the result as a raw binary string (not hex-encoded). Use icy::hex::encode() on digest() if you need a printable representation.
Returns
Binary digest as a std::string.
reset
void reset()Resets the digest context and clears the cached result, allowing the engine to be reused for a new computation with the same algorithm.
algorithm
const
const std::string & algorithm() constReturns the algorithm name this engine was constructed with.
Returns
OpenSSL digest name string (e.g. "sha256").
Protected Attributes
| Return | Name | Description |
|---|---|---|
EvpMdCtxPtr | _ctx | |
const EVP_MD * | _md | |
crypto::ByteVec | _digest | |
std::string | _algorithm |
_ctx
EvpMdCtxPtr _ctx_md
const EVP_MD * _md_digest
crypto::ByteVec _digest_algorithm
std::string _algorithm