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-2016 Regents of the University of California.
Definition: common.hpp:74
The interface of signing key management.
Interest makeCommandInterest(const Name &name, const SigningInfo &params=v2::KeyChain::getDefaultSigningInfo())
Create CommandInterest.
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:45
Signing parameters passed to KeyChain.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
void sign(Data &data, const SigningInfo &params=getDefaultSigningInfo())
Sign data according to the supplied signing information.
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:118
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
Definition: name.hpp:140