19 virtual void add(
const uint8_t *data,
size_t len) = 0;
20 void add(
const char *data,
size_t len) { this->
add((
const uint8_t *) data,
len); }
30 for (
size_t i = 0; i < this->
get_size(); i++) {
31 uint8_t
byte = this->
digest_[i];
Base class for hash algorithms.
void get_hex(char *output)
Retrieve the hash as hex characters.
virtual ~HashBase()=default
bool equals_hex(const char *expected)
Compare the hash against a provided hex-encoded hash.
virtual void calculate()=0
Compute the hash based on provided data.
virtual void init()=0
Initialize a new hash computation.
bool equals_bytes(const uint8_t *expected)
Compare the hash against a provided byte-encoded hash.
virtual size_t get_size() const =0
Get the size of the hash in bytes (16 for MD5, 32 for SHA256)
void add(const char *data, size_t len)
virtual void add(const uint8_t *data, size_t len)=0
Add bytes of data for the hash.
void get_bytes(uint8_t *output)
Retrieve the hash as bytes.
Providing packet encoding functions for exchanging data with a remote host.
size_t parse_hex(const char *str, size_t length, uint8_t *data, size_t count)
Parse bytes from a hex-encoded string into a byte array.
char format_hex_char(uint8_t v)
Convert a nibble (0-15) to lowercase hex char.