Provides stateful SHA-256 digest calculation. More...
#include <sha256.hpp>
Classes | |
class | Error |
Public Member Functions | |
Sha256 () | |
Create an empty SHA-256 digest. More... | |
Sha256 (std::istream &is) | |
Calculate SHA-256 digest of the input stream is . More... | |
bool | empty () const |
Check if digest is empty. More... | |
void | reset () |
Discard the current state and start a new digest calculation. More... | |
ConstBufferPtr | computeDigest () |
Finalize and return the digest based on all previously supplied inputs. More... | |
bool | operator== (Sha256 &digest) |
Check if the supplied digest is equal to this digest. More... | |
bool | operator!= (Sha256 &digest) |
Check if the supplied digest is not equal to this digest. More... | |
Sha256 & | operator<< (Sha256 &src) |
Add existing digest to the digest calculation. More... | |
Sha256 & | operator<< (const std::string &str) |
Add a string to the digest calculation. More... | |
Sha256 & | operator<< (uint64_t value) |
Add a uint64_t value to the digest calculation. More... | |
Sha256 & | operator<< (span< const uint8_t > bytes) |
Add a contiguous range of arbitrary bytes to the digest calculation. More... | |
void | update (span< const uint8_t > buffer) |
Add a byte buffer to the digest calculation. More... | |
std::string | toString () |
Convert digest to std::string. More... | |
Static Public Member Functions | |
static ConstBufferPtr | computeDigest (span< const uint8_t > buffer) |
Stateless SHA-256 digest calculation. More... | |
Static Public Attributes | |
static const size_t | DIGEST_SIZE = 32 |
Length in bytes of a SHA-256 digest. More... | |
Provides stateful SHA-256 digest calculation.
Example:
Definition at line 44 of file sha256.hpp.
ndn::util::Sha256::Sha256 | ( | ) |
|
explicit |
Calculate SHA-256 digest of the input stream is
.
Definition at line 39 of file sha256.cpp.
References ndn::security::transform::digestFilter(), ndn::SHA256, and ndn::security::transform::streamSink().
|
inline |
Check if digest is empty.
An empty digest means nothing has been taken into calculation.
Definition at line 75 of file sha256.hpp.
References computeDigest(), operator==(), and reset().
void ndn::util::Sha256::reset | ( | ) |
Discard the current state and start a new digest calculation.
Definition at line 50 of file sha256.cpp.
References ndn::security::transform::digestFilter(), ndn::SHA256, and ndn::security::transform::streamSink().
ConstBufferPtr ndn::util::Sha256::computeDigest | ( | ) |
Finalize and return the digest based on all previously supplied inputs.
Definition at line 63 of file sha256.cpp.
Referenced by computeDigest(), empty(), ndn::Data::getFullName(), operator!=(), operator<<(), ndn::util::operator<<(), operator==(), and toString().
bool ndn::util::Sha256::operator== | ( | Sha256 & | digest | ) |
Check if the supplied digest is equal to this digest.
Definition at line 75 of file sha256.cpp.
References computeDigest().
Referenced by empty().
|
inline |
Check if the supplied digest is not equal to this digest.
Definition at line 104 of file sha256.hpp.
References computeDigest(), operator<<(), toString(), and update().
Add existing digest to the digest calculation.
src | digest to combine with |
The result of this combination is sha256(sha256(...))
src
, finalizing the digest. Error | the digest has already been finalized |
Definition at line 89 of file sha256.cpp.
References computeDigest(), and update().
Referenced by operator!=().
Sha256 & ndn::util::Sha256::operator<< | ( | const std::string & | str | ) |
Add a string to the digest calculation.
Error | the digest has already been finalized |
Definition at line 96 of file sha256.cpp.
References update().
Sha256 & ndn::util::Sha256::operator<< | ( | uint64_t | value | ) |
Add a uint64_t value to the digest calculation.
Error | the digest has already been finalized |
Definition at line 103 of file sha256.cpp.
References update().
Sha256 & ndn::util::Sha256::operator<< | ( | span< const uint8_t > | bytes | ) |
Add a contiguous range of arbitrary bytes to the digest calculation.
Error | the digest has already been finalized |
Definition at line 110 of file sha256.cpp.
References update().
void ndn::util::Sha256::update | ( | span< const uint8_t > | buffer | ) |
Add a byte buffer to the digest calculation.
Error | the digest has already been finalized |
Definition at line 117 of file sha256.cpp.
References NDN_THROW.
Referenced by computeDigest(), operator!=(), and operator<<().
std::string ndn::util::Sha256::toString | ( | ) |
Convert digest to std::string.
Definition at line 128 of file sha256.cpp.
References computeDigest(), and ndn::toHex().
Referenced by operator!=().
|
static |
Stateless SHA-256 digest calculation.
Definition at line 135 of file sha256.cpp.
References computeDigest(), and update().
|
static |
Length in bytes of a SHA-256 digest.
Definition at line 56 of file sha256.hpp.
Referenced by ndn::name::Component::isImplicitSha256Digest(), and ndn::name::Component::isParametersSha256Digest().