ndn::util::Digest< Hash > Class Template Reference

provides a stateful digest calculation More...

#include <digest.hpp>

Data Structures

class  Error
 

Public Types

typedef Hash HashFunction
 

Public Member Functions

 Digest ()
 
 Digest (std::istream &is)
 Calculate digest of the input stream is. More...
 
void reset ()
 Discard the current state and start a new digest calculation. More...
 
bool empty () const
 Check if digest is empty. More...
 
ConstBufferPtr computeDigest ()
 Finalize and return the digest based on all previously supplied inputs. More...
 
bool operator== (Digest< Hash > &digest)
 Check if the supplied digest equals to this digest. More...
 
bool operator!= (Digest< Hash > &digest)
 Check if the supplied digest is not equal to this digest. More...
 
Digest< Hash > & operator<< (Digest< Hash > &src)
 Add existing digest to the digest calculation. More...
 
Digest< Hash > & operator<< (const std::string &str)
 Add string to the digest calculation. More...
 
Digest< Hash > & operator<< (const Block &block)
 Add block to the digest calculation. More...
 
Digest< Hash > & operator<< (uint64_t value)
 Add uint64_t value to the digest calculation. More...
 
void update (const uint8_t *buffer, size_t size)
 Add a buffer to the digest calculation. More...
 
std::string toString ()
 Convert digest to std::string. More...
 

Static Public Member Functions

static ConstBufferPtr computeDigest (const uint8_t *buffer, size_t size)
 Compute one-time digest. More...
 

Data Fields

 Hashable< Hash >
 

Detailed Description

template<typename Hash>
class ndn::util::Digest< Hash >

provides a stateful digest calculation

SHA256 example:

Digest<CryptoPP::SHA256> digest; digest.update(buf1, size1); digest.update(buf2, size2); ... ConstBufferPtr result = digest.computeDigest();

Definition at line 45 of file digest.hpp.

Member Typedef Documentation

template<typename Hash>
typedef Hash ndn::util::Digest< Hash >::HashFunction

Definition at line 50 of file digest.hpp.

Constructor & Destructor Documentation

template<typename Hash >
ndn::util::Digest< Hash >::Digest ( )

Definition at line 32 of file digest.cpp.

template<typename Hash >
ndn::util::Digest< Hash >::Digest ( std::istream &  is)
explicit

Calculate digest of the input stream is.

Parameters
isinput stream

Definition at line 38 of file digest.cpp.

Member Function Documentation

template<typename Hash >
ConstBufferPtr ndn::util::Digest< Hash >::computeDigest ( )

Finalize and return the digest based on all previously supplied inputs.

Definition at line 75 of file digest.cpp.

template<typename Hash >
ConstBufferPtr ndn::util::Digest< Hash >::computeDigest ( const uint8_t *  buffer,
size_t  size 
)
static

Compute one-time digest.

Parameters
bufferthe input buffer
sizethe size of the input buffer.
Returns
digest computed according to the Hash algorithm

Definition at line 148 of file digest.cpp.

template<typename Hash>
bool ndn::util::Digest< Hash >::empty ( ) const
inline

Check if digest is empty.

An empty digest means nothing has been taken into calculation.

Definition at line 83 of file digest.hpp.

template<typename Hash>
bool ndn::util::Digest< Hash >::operator!= ( Digest< Hash > &  digest)
inline

Check if the supplied digest is not equal to this digest.

Note
This method will invoke computeDigest(), finalizing the digest.

Definition at line 108 of file digest.hpp.

template<typename Hash >
Digest< Hash > & ndn::util::Digest< Hash >::operator<< ( const Block block)

Add block to the digest calculation.

Parameters
blockdata block to put into digest
Exceptions
Errorthe digest has been finalized.

Definition at line 117 of file digest.cpp.

template<typename Hash >
Digest< Hash > & ndn::util::Digest< Hash >::operator<< ( uint64_t  value)

Add uint64_t value to the digest calculation.

Parameters
valuethe integer value to put into digest
Exceptions
Errorthe digest has been finalized.

Definition at line 126 of file digest.cpp.

template<typename Hash >
Digest< Hash > & ndn::util::Digest< Hash >::operator<< ( const std::string &  str)

Add string to the digest calculation.

Parameters
strstring to put into digest

Definition at line 108 of file digest.cpp.

template<typename Hash >
Digest< Hash > & ndn::util::Digest< Hash >::operator<< ( Digest< Hash > &  src)

Add existing digest to the digest calculation.

Parameters
srcdigest to combine with

The result of this combination is digest(digest(...))

Note
This method will invoke computeDigest(), finalizing the digest.

Definition at line 98 of file digest.cpp.

template<typename Hash >
bool ndn::util::Digest< Hash >::operator== ( Digest< Hash > &  digest)

Check if the supplied digest equals to this digest.

Note
This method will invoke computeDigest(), finalizing the digest.

Definition at line 83 of file digest.cpp.

template<typename Hash >
void ndn::util::Digest< Hash >::reset ( )

Discard the current state and start a new digest calculation.

Definition at line 52 of file digest.cpp.

template<typename Hash >
std::string ndn::util::Digest< Hash >::toString ( )

Convert digest to std::string.

Note
This method will invoke computeDigest(), finalizing the digest.

Definition at line 160 of file digest.cpp.

template<typename Hash >
void ndn::util::Digest< Hash >::update ( const uint8_t *  buffer,
size_t  size 
)

Add a buffer to the digest calculation.

Update the state of the digest if it has not been finalized and mark the digest as InProcess.

Parameters
bufferthe input buffer
sizethe size of the input buffer.
Exceptions
Errorthe digest has been finalized.

Definition at line 135 of file digest.cpp.

Field Documentation

template<typename Hash>
ndn::util::Digest< Hash >::Hashable< Hash >

Definition at line 48 of file digest.hpp.