NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
sha256.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2017 Regents of the University of California.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*/
21
22
#ifndef NDN_UTIL_SHA256_HPP
23
#define NDN_UTIL_SHA256_HPP
24
25
#include "../encoding/block.hpp"
26
#include "../encoding/buffer-stream.hpp"
27
#include "../security/transform/step-source.hpp"
28
29
namespace
ndn
{
30
namespace
util {
31
44
class
Sha256
45
{
46
public
:
47
class
Error
:
public
std::runtime_error
48
{
49
public
:
50
explicit
51
Error
(
const
std::string& what)
52
:
std
::runtime_error(what)
53
{
54
}
55
};
56
60
static
const
size_t
DIGEST_SIZE
= 32;
61
65
Sha256
();
66
70
explicit
71
Sha256
(std::istream& is);
72
78
bool
79
empty
()
const
80
{
81
return
m_isEmpty;
82
}
83
87
void
88
reset
();
89
93
ConstBufferPtr
94
computeDigest
();
95
100
bool
101
operator==
(
Sha256
& digest);
102
107
bool
108
operator!=
(
Sha256
& digest)
109
{
110
return
!(*
this
== digest);
111
}
112
122
Sha256
&
123
operator<<
(
Sha256
& src);
124
129
Sha256
&
130
operator<<
(
const
std::string& str);
131
136
Sha256
&
137
operator<<
(
const
Block
& block);
138
143
Sha256
&
144
operator<<
(uint64_t value);
145
152
void
153
update
(
const
uint8_t* buffer,
size_t
size);
154
159
std::string
160
toString
();
161
168
static
ConstBufferPtr
169
computeDigest
(
const
uint8_t* buffer,
size_t
size);
170
171
private
:
172
unique_ptr<security::transform::StepSource> m_input;
173
unique_ptr<OBufferStream> m_output;
174
bool
m_isEmpty;
175
bool
m_isFinalized;
176
};
177
178
std::ostream&
179
operator<<
(std::ostream& os, Sha256& digest);
180
181
}
// namespace util
182
}
// namespace ndn
183
184
#endif // NDN_UTIL_SHA256_HPP
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::util::Sha256
Provides stateful SHA-256 digest calculation.
Definition:
sha256.hpp:44
ndn::util::Sha256::DIGEST_SIZE
static const size_t DIGEST_SIZE
Length in bytes of a SHA-256 digest.
Definition:
sha256.hpp:60
ndn::util::Sha256::operator==
bool operator==(Sha256 &digest)
Check if the supplied digest is equal to this digest.
Definition:
sha256.cpp:75
std
STL namespace.
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:42
ndn::util::Sha256::toString
std::string toString()
Convert digest to std::string.
Definition:
sha256.cpp:129
ndn::util::Sha256::Sha256
Sha256()
Create an empty SHA-256 digest.
Definition:
sha256.cpp:34
ndn::util::Sha256::update
void update(const uint8_t *buffer, size_t size)
Add a raw buffer to the digest calculation.
Definition:
sha256.cpp:118
ndn::util::Sha256::operator!=
bool operator!=(Sha256 &digest)
Check if the supplied digest is not equal to this digest.
Definition:
sha256.hpp:108
ndn::util::Sha256::reset
void reset()
Discard the current state and start a new digest calculation.
Definition:
sha256.cpp:50
ndn::util::Sha256::Error::Error
Error(const std::string &what)
Definition:
sha256.hpp:51
ndn::util::Sha256::Error
Definition:
sha256.hpp:47
ndn::util::Sha256::computeDigest
ConstBufferPtr computeDigest()
Finalize and return the digest based on all previously supplied inputs.
Definition:
sha256.cpp:63
ndn::util::Sha256::operator<<
Sha256 & operator<<(Sha256 &src)
Add existing digest to the digest calculation.
Definition:
sha256.cpp:89
ndn::util::operator<<
std::ostream & operator<<(std::ostream &os, Sha256 &digest)
Definition:
sha256.cpp:144
ndn::util::Sha256::empty
bool empty() const
Check if digest is empty.
Definition:
sha256.hpp:79
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition:
buffer.hpp:89
ndnSIM
ndn-cxx
src
util
sha256.hpp
Generated on Tue Aug 7 2018 16:19:17 for ndnSIM by
1.8.14