A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SHA1 Class Reference

#include <genesis/utils/tools/sha1.hpp>

Detailed Description

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 from_string() or from_file(), which are static shortcuts for the above.

The implementation is based on https://github.com/vog/sha1, which is 100% Public Domain, see also Acknowledgements.

Definition at line 60 of file sha1.hpp.

Public Member Functions

 SHA1 ()
 Initialize the object for use. More...
 
 SHA1 (SHA1 const &)=default
 
 SHA1 (SHA1 &&)=default
 
 ~SHA1 ()=default
 
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...
 
SHA1operator= (SHA1 const &)=default
 
SHA1operator= (SHA1 &&)=default
 
void update (std::string const &s)
 Add the contents of a string to the hash digest. More...
 
void update (std::istream &is)
 Add the contents of a stream to the hash digest. More...
 

Static Public Member Functions

static std::string digest_to_hex (DigestType const &digest)
 
static DigestType from_file_digest (std::string const &filename)
 Calculate the hash digest for the content of a file, given its path. More...
 
static std::string from_file_hex (std::string const &filename)
 Calculate the checksum for the content of a file, given its path. More...
 
static DigestType from_string_digest (std::string const &input)
 Calculate the hash digest for the content of a string. More...
 
static std::string from_string_hex (std::string const &input)
 Calculate the checksum for the content of a string. More...
 
static DigestType hex_to_digest (std::string const &hex)
 

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
 

Constructor & Destructor Documentation

SHA1 ( )

Initialize the object for use.

Definition at line 52 of file sha1.cpp.

~SHA1 ( )
default
SHA1 ( SHA1 const &  )
default
SHA1 ( SHA1 &&  )
default

Member Function Documentation

std::string digest_to_hex ( SHA1::DigestType const &  digest)
static

Definition at line 178 of file sha1.cpp.

SHA1::DigestType final_digest ( )

Finish the calculation, prepare the object for next use, and return the digest.

Definition at line 101 of file sha1.cpp.

std::string final_hex ( )

Finish the calculation, prepare the object for next use, and return the hash.

Definition at line 92 of file sha1.cpp.

SHA1::DigestType from_file_digest ( std::string const &  filename)
static

Calculate the hash digest for the content of a file, given its path.

Definition at line 150 of file sha1.cpp.

std::string from_file_hex ( std::string const &  filename)
static

Calculate the checksum for the content of a file, given its path.

Definition at line 139 of file sha1.cpp.

SHA1::DigestType from_string_digest ( std::string const &  input)
static

Calculate the hash digest for the content of a string.

Definition at line 171 of file sha1.cpp.

std::string from_string_hex ( std::string const &  input)
static

Calculate the checksum for the content of a string.

Definition at line 161 of file sha1.cpp.

SHA1::DigestType hex_to_digest ( std::string const &  hex)
static

Definition at line 190 of file sha1.cpp.

SHA1& operator= ( SHA1 const &  )
default
SHA1& operator= ( SHA1 &&  )
default
void update ( std::string const &  s)

Add the contents of a string to the hash digest.

Definition at line 64 of file sha1.cpp.

void update ( std::istream &  is)

Add the contents of a stream to the hash digest.

Definition at line 73 of file sha1.cpp.

Member Typedef Documentation

using DigestType = std::array< uint32_t, 5 >

Store a SHA1 digest.

This type can be used for storing hashes instead of the hex representation. It only needs 20 bytes instead of 40 bytes for the hex. As it is a std::array, this type can be compared using normal ==.

Definition at line 79 of file sha1.hpp.

Member Data Documentation

const size_t BlockBytes = BlockInts * 4
static

Definition at line 70 of file sha1.hpp.

const size_t BlockInts = 16
static

Definition at line 69 of file sha1.hpp.


The documentation for this class was generated from the following files: