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 
23 #include "ndn-cxx/util/random.hpp"
24 
25 namespace ndn {
26 namespace security {
27 
29  : m_lastUsedTimestamp(0)
30 {
31 }
32 
33 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()))
45  ;
46 
47  return name;
48 }
49 
51  : m_keyChain(keyChain)
52 {
53 }
54 
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
static Component fromNumber(uint64_t number)
Create a component encoded as nonNegativeInteger.
Copyright (c) 2011-2015 Regents of the University of California.
The interface of signing key management.
Definition: key-chain.hpp:46
Represents an Interest packet.
Definition: interest.hpp:44
Name prepareCommandInterestName(Name name)
Prepare name of the CommandInterest.
static time_point now() noexcept
Definition: time.cpp:46
Signing parameters passed to KeyChain.
Interest makeCommandInterest(const Name &name, const SigningInfo &params=KeyChain::getDefaultSigningInfo())
Create CommandInterest.
Represents an absolute name.
Definition: name.hpp:43
void sign(Data &data, const SigningInfo &params=getDefaultSigningInfo())
Sign data according to the supplied signing information.
Definition: key-chain.cpp:430
uint64_t generateWord64()
Generate a non-cryptographically-secure random integer in the range [0, 2^64)
Definition: random.cpp:73
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:113
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
Definition: interest.hpp:187