command-interest-signer.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
23 #include "../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 + time::milliseconds(1);
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  m_keyChain.sign(commandInterest, params);
60  return commandInterest;
61 }
62 
63 } // namespace security
64 } // namespace ndn
static Component fromNumber(uint64_t number)
Create a component encoded as nonNegativeInteger.
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
represents an Interest packet
Definition: interest.hpp:42
Name prepareCommandInterestName(Name name)
Prepare name of the CommandInterest.
static time_point now() noexcept
Definition: time.cpp:46
Name & append(const Component &component)
Append a component.
Definition: name.hpp:256
Signing parameters passed to KeyChain.
Interest makeCommandInterest(const Name &name, const SigningInfo &params=KeyChain::getDefaultSigningInfo())
Create CommandInterest.
Represents an absolute name.
Definition: name.hpp:42
uint64_t generateWord64()
Generate a non-cryptographically-secure random integer in the range [0, 2^64)
Definition: random.cpp:70
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:119