NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
digest.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_DIGEST_HPP
23 #define NDN_UTIL_DIGEST_HPP
24 
25 #include "../encoding/buffer.hpp"
26 #include "../encoding/block.hpp"
27 #include "../security/cryptopp.hpp"
28 #include "concepts.hpp"
29 
30 namespace ndn {
31 namespace util {
32 
46 template<typename Hash>
47 class Digest
48 {
49 public:
50  BOOST_CONCEPT_ASSERT((Hashable<Hash>));
51 
52  typedef Hash HashFunction;
53 
54  class Error : public std::runtime_error
55  {
56  public:
57  explicit
58  Error(const std::string& what)
59  : std::runtime_error(what)
60  {
61  }
62  };
63 
64  Digest();
65 
70  explicit
71  Digest(std::istream& is);
72 
76  void
77  reset();
78 
84  bool
85  empty() const
86  {
87  return !m_isInProcess;
88  }
89 
96  computeDigest();
97 
107  bool
108  operator==(Digest<Hash>& digest);
109 
119  bool
121  {
122  return !(*this == digest);
123  }
124 
133  Digest<Hash>&
134  operator<<(Digest<Hash>& src);
135 
140  Digest<Hash>&
141  operator<<(const std::string& str);
142 
147  Digest<Hash>&
148  operator<<(const Block& block);
149 
154  Digest<Hash>&
155  operator<<(uint64_t value);
156 
167  void
168  update(const uint8_t* buffer, size_t size);
169 
176  static ConstBufferPtr
177  computeDigest(const uint8_t* buffer, size_t size);
178 
185  std::string
186  toString();
187 
188 private:
194  void
195  finalize();
196 
197 private:
198  Hash m_hash;
199  BufferPtr m_buffer;
200  bool m_isInProcess;
201  bool m_isFinalized;
202 };
203 
204 template<typename Hash>
205 std::ostream&
206 operator<<(std::ostream& os, Digest<Hash>& digest);
207 
212 
213 } // namespace util
214 } // namespace ndn
215 
216 #endif // NDN_UTIL_DIGEST_HPP
Copyright (c) 2011-2015 Regents of the University of California.
void reset()
Discard the current state and start a new digest.
Definition: digest.cpp:50
shared_ptr< Buffer > BufferPtr
Definition: buffer.hpp:35
STL namespace.
bool operator!=(Digest< Hash > &digest)
Check if supplied digest is not equal to this digest.
Definition: digest.hpp:120
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
provides a digest calculation
Definition: digest.hpp:47
bool empty() const
Check if digest is empty.
Definition: digest.hpp:85
Digest< Hash > & operator<<(Digest< Hash > &src)
Add existing digest to digest calculation.
Definition: digest.cpp:88
Digest< CryptoPP::SHA256 > Sha256
A digest using SHA256 as the hash function.
Definition: digest.hpp:211
Error(const std::string &what)
Definition: digest.hpp:58
void update(const uint8_t *buffer, size_t size)
Add a buffer to digest calculation.
Definition: digest.cpp:125
ConstBufferPtr computeDigest()
Obtain the digest.
Definition: digest.cpp:73
bool operator==(Digest< Hash > &digest)
Check if supplied digest equal to this digest.
Definition: digest.cpp:81
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
std::string toString()
Convert digest to std::string.
Definition: digest.cpp:150
a concept check for CryptoPP hash algorithm
Definition: concepts.hpp:84