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

#include <genesis/utils/math/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() 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 55 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 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...
 

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 48 of file sha1.cpp.

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

Member Function Documentation

SHA1::DigestType final_digest ( )

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

Definition at line 106 of file sha1.cpp.

std::string final_hex ( )

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

Definition at line 88 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 155 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 144 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 176 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 166 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 60 of file sha1.cpp.

void update ( std::istream &  is)

Add the contents of a stream to the hash digest.

Definition at line 69 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 74 of file sha1.hpp.

Member Data Documentation

const size_t BlockBytes = BlockInts * 4
static

Definition at line 65 of file sha1.hpp.

const size_t BlockInts = 16
static

Definition at line 64 of file sha1.hpp.


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