SOIL C++
C++ Unified Device Interface
SIGN::Hasher Class Reference

SHA256 Hasher. More...

#include <Hasher.h>

Public Member Functions

 Hasher ()
 Constructor. More...
 
 ~Hasher ()
 Destructor. More...
 
template<typename T >
void push_back (T x)
 Add data. More...
 
std::vector< unsigned char > hash ()
 Hash the data buffer. More...
 
void reset ()
 Reset data buffer. More...
 
size_t size (void)
 Digest size. More...
 

Static Public Member Functions

static std::string print (std::vector< unsigned char > bytes, bool uppercase=true)
 Print Bytestring. More...
 
static std::vector< unsigned char > sha256 (const unsigned char *data, size_t length)
 SHA256 hash. More...
 

Detailed Description

Class which provides an convenient interface for calculating SHA256 hashes. The underlying methods are taken from OpenSSL.

Definition at line 14 of file Hasher.h.

Constructor & Destructor Documentation

◆ Hasher()

SIGN::Hasher::Hasher ( )

Default constructor, no special effort here.

Definition at line 19 of file Hasher.cpp.

◆ ~Hasher()

SIGN::Hasher::~Hasher ( )

Default destructor, no special effort here.

Definition at line 24 of file Hasher.cpp.

Member Function Documentation

◆ hash()

std::vector< unsigned char > SIGN::Hasher::hash ( )

Calculate the SHA256 hash of the current data buffer and return it as standard vector of bytes. Internally calls the static SHA256 function

Postcondition
The output of this function can be used in the signer.
Returns
Hash result as sequenxe of bytes.

Definition at line 28 of file Hasher.cpp.

◆ print()

std::string SIGN::Hasher::print ( std::vector< unsigned char >  bytes,
bool  uppercase = true 
)
static

Convenience function to pretty-print bytestrings in HEX format.

Parameters
[in]bytesData to print
[in]uppercaseBoolean flag whether to print uppercase
Returns
String with print result.

Definition at line 43 of file Hasher.cpp.

◆ push_back()

template<typename T >
void SIGN::Hasher::push_back ( x)
inline

Push back data to the internal buffer which eventually gets hashed. This function is implemented using templates, underneath it copies the raw bytes after casting.

Template Parameters
TOriginal type of the item to add to the buffer
Parameters
[in]xItem to add to the buffer

Definition at line 99 of file Hasher.h.

◆ reset()

void SIGN::Hasher::reset ( )

Clear the internal data buffer (i.e. to start with new data)

Definition at line 33 of file Hasher.cpp.

◆ sha256()

std::vector< unsigned char > SIGN::Hasher::sha256 ( const unsigned char *  data,
size_t  length 
)
static

Calculate the SHA256 hash of the given input data. Be careful to no pass invalid pointers here, there is a risk of memory leaks.

Parameters
data[in] Pointer to the memory block to read from
length[in] Length of the data to consume
Returns
SHA256 hash as vector of bytes

Definition at line 8 of file Hasher.cpp.

◆ size()

size_t SIGN::Hasher::size ( void  )

Convenience function to get the digest size, which is often needed when handling raw bytes.

Returns
SHA256 digest length

Definition at line 38 of file Hasher.cpp.


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