NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::util::Digest< Hash > Class Template Reference

provides a digest calculation More...

#include <digest.hpp>

Classes

class  Error
 

Public Types

typedef Hash HashFunction
 

Public Member Functions

 Digest ()
 
 Digest (std::istream &is)
 Create digest of the input stream is. More...
 
void reset ()
 Discard the current state and start a new digest. More...
 
bool empty () const
 Check if digest is empty. More...
 
ConstBufferPtr computeDigest ()
 Obtain the digest. More...
 
bool operator== (Digest< Hash > &digest)
 Check if supplied digest equal to this digest. More...
 
bool operator!= (Digest< Hash > &digest)
 Check if supplied digest is not equal to this digest. More...
 
Digest< Hash > & operator<< (Digest< Hash > &src)
 Add existing digest to digest calculation. More...
 
Digest< Hash > & operator<< (const std::string &str)
 Add string to digest calculation. More...
 
Digest< Hash > & operator<< (const Block &block)
 Add block to digest calculation. More...
 
Digest< Hash > & operator<< (uint64_t value)
 Add uint64_t value to digest calculation. More...
 
void update (const uint8_t *buffer, size_t size)
 Add a buffer to 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...
 

Public Attributes

 Hashable< Hash >
 

Detailed Description

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

provides a digest calculation

Take SHA256 as an example:

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

See also
http://redmine.named-data.net/issues/1934

Definition at line 47 of file digest.hpp.

Member Typedef Documentation

◆ HashFunction

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

Definition at line 52 of file digest.hpp.

Constructor & Destructor Documentation

◆ Digest() [1/2]

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

Definition at line 30 of file digest.cpp.

Referenced by ndn::util::Digest< Hash >::Error::Error().

◆ Digest() [2/2]

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

Create digest of the input stream is.

Parameters
isinput stream

Definition at line 36 of file digest.cpp.

Member Function Documentation

◆ reset()

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

Discard the current state and start a new digest.

Definition at line 50 of file digest.cpp.

Referenced by ndn::util::Digest< Hash >::Error::Error().

◆ empty()

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 85 of file digest.hpp.

References ndn::util::Digest< Hash >::computeDigest(), and ndn::util::Digest< Hash >::operator==().

◆ computeDigest() [1/2]

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

Obtain the digest.

Note this digest is finalized once this method is invoked.

Definition at line 73 of file digest.cpp.

Referenced by ndn::util::Digest< Hash >::empty(), ndn::util::Digest< Hash >::operator!=(), ndn::util::Digest< Hash >::operator<<(), and ndn::util::Digest< Hash >::operator==().

◆ operator==()

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

Check if supplied digest equal to this digest.

Note that this method will invoke computeDigest(). Once this method is invoked, both this digest and the supplied digest are finalized.

Warning
This method cannot be used in security related context because it is vulnerable to timing attack

Definition at line 81 of file digest.cpp.

References ndn::util::Digest< Hash >::computeDigest().

Referenced by ndn::util::Digest< Hash >::empty().

◆ operator!=()

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

Check if supplied digest is not equal to this digest.

Note that this method will invoke computeDigest(). Once this method is invoked, both this digest and the supplied digest are finalized.

Warning
This method cannot be used in security related context because it is vulnerable to timing attack

Definition at line 120 of file digest.hpp.

References ndn::util::Digest< Hash >::computeDigest(), ndn::util::Digest< Hash >::operator<<(), ndn::util::Digest< Hash >::toString(), and ndn::util::Digest< Hash >::update().

◆ operator<<() [1/4]

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

Add existing digest to digest calculation.

Parameters
srcdigest to combine with

The result of this combination is hash (hash (...)) Note that this method will invoke computeDigest(). Once this method is invoked, the supplied digest is fixed.

Definition at line 88 of file digest.cpp.

References ndn::util::Digest< Hash >::computeDigest(), and ndn::util::Digest< Hash >::update().

Referenced by ndn::util::Digest< Hash >::operator!=().

◆ operator<<() [2/4]

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

Add string to digest calculation.

Parameters
strstring to put into digest

Definition at line 98 of file digest.cpp.

References ndn::util::Digest< Hash >::update().

◆ operator<<() [3/4]

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

Add block to digest calculation.

Parameters
blockto put into digest

Definition at line 107 of file digest.cpp.

References ndn::Block::size(), ndn::util::Digest< Hash >::update(), and ndn::Block::wire().

◆ operator<<() [4/4]

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

Add uint64_t value to digest calculation.

Parameters
valueuint64_t value to put into digest

Definition at line 116 of file digest.cpp.

References ndn::util::Digest< Hash >::update().

◆ update()

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

Add a buffer to digest calculation.

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

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

Definition at line 125 of file digest.cpp.

Referenced by ndn::util::Digest< Hash >::operator!=(), and ndn::util::Digest< Hash >::operator<<().

◆ computeDigest() [2/2]

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 HashAlgorithm

Definition at line 138 of file digest.cpp.

◆ toString()

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

Convert digest to std::string.

Note that this method will invoke computeDigest(). Once this method is invoked, the digest is finalized.

Definition at line 150 of file digest.cpp.

Referenced by ndn::util::Digest< Hash >::operator!=().

Member Data Documentation

◆ Hashable< Hash >

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

Definition at line 50 of file digest.hpp.


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