NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
command-interest-signer.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2018 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
#include "
ndn-cxx/security/command-interest-signer.hpp
"
23
#include "
ndn-cxx/util/random.hpp
"
24
25
namespace
ndn
{
26
namespace
security {
27
28
CommandInterestPreparer::CommandInterestPreparer
()
29
: m_lastUsedTimestamp(0)
30
{
31
}
32
33
Name
34
CommandInterestPreparer::prepareCommandInterestName
(
Name
name
)
35
{
36
time::milliseconds timestamp =
time::toUnixTimestamp
(
time::system_clock::now
());
37
if
(timestamp <= m_lastUsedTimestamp) {
38
timestamp = m_lastUsedTimestamp + 1_ms;
39
}
40
m_lastUsedTimestamp = timestamp;
41
42
name
43
.append(
name::Component::fromNumber
(timestamp.count()))
44
.append(
name::Component::fromNumber
(
random::generateWord64
()))
// nonce
45
;
46
47
return
name
;
48
}
49
50
CommandInterestSigner::CommandInterestSigner
(
KeyChain
& keyChain)
51
: m_keyChain(keyChain)
52
{
53
}
54
55
Interest
56
CommandInterestSigner::makeCommandInterest
(
const
Name
&
name
,
const
SigningInfo
& params)
57
{
58
Interest
commandInterest(
prepareCommandInterestName
(
name
));
59
commandInterest.
setCanBePrefix
(
false
);
60
m_keyChain.
sign
(commandInterest, params);
61
return
commandInterest;
62
}
63
64
}
// namespace security
65
}
// namespace ndn
ndn::name::Component::fromNumber
static Component fromNumber(uint64_t number, uint32_t type=tlv::GenericNameComponent)
Create a component encoded as nonNegativeInteger.
Definition:
name-component.cpp:341
ndn::security::CommandInterestPreparer::prepareCommandInterestName
Name prepareCommandInterestName(Name name)
Prepare name of the CommandInterest.
Definition:
command-interest-signer.cpp:34
ndn::security::SigningInfo
Signing parameters passed to KeyChain.
Definition:
signing-info.hpp:42
random.hpp
ndn::time::system_clock::now
static time_point now() noexcept
Definition:
time.cpp:46
ndn::Name
Represents an absolute name.
Definition:
name.hpp:44
ndn::security::CommandInterestSigner::CommandInterestSigner
CommandInterestSigner(KeyChain &keyChain)
Definition:
command-interest-signer.cpp:50
ndn::security::v2::KeyChain
The interface of signing key management.
Definition:
key-chain.hpp:47
ndn::Interest::setCanBePrefix
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
Definition:
interest.hpp:164
ndn::Interest
Represents an Interest packet.
Definition:
interest.hpp:44
command-interest-signer.hpp
ndn::random::generateWord64
uint64_t generateWord64()
Generate a non-cryptographically-secure random integer in the range [0, 2^64)
Definition:
random.cpp:73
ndn::security::CommandInterestSigner::makeCommandInterest
Interest makeCommandInterest(const Name &name, const SigningInfo ¶ms=KeyChain::getDefaultSigningInfo())
Create CommandInterest.
Definition:
command-interest-signer.cpp:56
ndn::name
Definition:
name-component-types.hpp:33
ndn::time::toUnixTimestamp
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition:
time.cpp:113
ndn::security::CommandInterestPreparer::CommandInterestPreparer
CommandInterestPreparer()
Definition:
command-interest-signer.cpp:28
ndn::security::v2::KeyChain::sign
void sign(Data &data, const SigningInfo ¶ms=getDefaultSigningInfo())
Sign data according to the supplied signing information.
Definition:
key-chain.cpp:450
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndnSIM
ndn-cxx
ndn-cxx
security
command-interest-signer.cpp
Generated on Mon Jun 1 2020 22:32:14 for ndnSIM by
1.8.18