#include <genesis/utils/tools/hash/sha1.hpp>
Calculate SHA1 hashes for strings and files.
After creating an object of this type, call update() with your input data as argument, as often as needed. Then, call final_hex() or final_digest() to obtain the hash and reset the object for reuse.
If you simply need the hash for a string or content of a file, use read_hex() or read_digest(), which are static shortcuts for the above using an input source. Use functions such as utils::from_file() and utils::from_string() to conveniently get an input source that can be used here.
The implementation is based on https://github.com/vog/sha1, which is 100% Public Domain, see also Acknowledgements.
Public Member Functions | |
| SHA1 () | |
| Initialize the object for use. More... | |
| SHA1 (SHA1 &&)=default | |
| SHA1 (SHA1 const &)=default | |
| ~SHA1 ()=default | |
| void | clear () |
| Reset to initial state, that is, delete any intermediate input from update() calls. More... | |
| DigestType | final_digest () |
| Finish the calculation, prepare the object for next use, and return the digest. More... | |
| std::string | final_hex () |
| Finish the calculation, prepare the object for next use, and return the hash. More... | |
| SHA1 & | operator= (SHA1 &&)=default |
| SHA1 & | operator= (SHA1 const &)=default |
| void | update (std::istream &is) |
| Add the contents of a stream to the hash digest. More... | |
| void | update (std::shared_ptr< BaseInputSource > source) |
| void | update (std::string const &s) |
| Add the contents of a string to the hash digest. More... | |
Static Public Member Functions | |
| static std::string | digest_to_hex (DigestType const &digest) |
| static DigestType | hex_to_digest (std::string const &hex) |
| static DigestType | read_digest (std::shared_ptr< BaseInputSource > source) |
| Calculate the hash digest for the content of an input source. More... | |
| static std::string | read_hex (std::shared_ptr< BaseInputSource > source) |
| Calculate the checksum for the content of an input source. More... | |
Public Types | |
| using | DigestType = std::array< uint32_t, 5 > |
| Store a SHA1 digest. More... | |
Static Public Attributes | |
| static const size_t | BlockBytes = BlockInts * 4 |
| static const size_t | BlockInts = 16 |
|
default |
| void clear | ( | ) |
|
static |
| SHA1::DigestType final_digest | ( | ) |
| std::string final_hex | ( | ) |
|
static |
|
static |
|
static |
| void update | ( | std::istream & | is | ) |
| void update | ( | std::shared_ptr< BaseInputSource > | source | ) |
| void update | ( | std::string const & | s | ) |
| using DigestType = std::array< uint32_t, 5 > |