NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-command-options.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nfd-command-options.hpp"
23 
24 #ifdef NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
25 #include "../security/identity-certificate.hpp"
26 #include "../security/signing-helpers.hpp"
27 #endif // NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
28 
29 namespace ndn {
30 namespace nfd {
31 
32 const time::milliseconds CommandOptions::DEFAULT_TIMEOUT(10000);
33 const Name CommandOptions::DEFAULT_PREFIX("ndn:/localhost/nfd");
34 
36  : m_timeout(DEFAULT_TIMEOUT)
37  , m_prefix(DEFAULT_PREFIX)
38 {
39 }
40 
42 CommandOptions::setTimeout(const time::milliseconds& timeout)
43 {
44  if (timeout <= time::milliseconds::zero()) {
45  BOOST_THROW_EXCEPTION(std::out_of_range("Timeout must be positive"));
46  }
47 
48  m_timeout = timeout;
49  return *this;
50 }
51 
54 {
55  m_prefix = prefix;
56  return *this;
57 }
58 
61 {
62  m_signingInfo = signingInfo;
63  return *this;
64 }
65 
66 #ifdef NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
67 
69 CommandOptions::getSigningParamsKind() const
70 {
71  switch (m_signingInfo.getSignerType()) {
78  default:
79  BOOST_THROW_EXCEPTION(std::out_of_range("SigningInfo::SignerType is not convertible to "
80  "CommandOptions::SigningParamsKind"));
81  }
82 }
83 
84 const Name&
85 CommandOptions::getSigningIdentity() const
86 {
87  BOOST_ASSERT(m_signingInfo.getSignerType() == security::SigningInfo::SIGNER_TYPE_ID);
88  return m_signingInfo.getSignerName();
89 }
90 
91 const Name&
92 CommandOptions::getSigningCertificate() const
93 {
94  BOOST_ASSERT(m_signingInfo.getSignerType() == security::SigningInfo::SIGNER_TYPE_CERT);
95  return m_signingInfo.getSignerName();
96 }
97 
98 CommandOptions&
99 CommandOptions::setSigningDefault()
100 {
101  m_signingInfo = security::SigningInfo();
102  return *this;
103 }
104 
105 CommandOptions&
106 CommandOptions::setSigningIdentity(const Name& identityName)
107 {
108  m_signingInfo = security::signingByIdentity(identityName);
109  return *this;
110 }
111 
112 static security::SigningInfo
114 {
115  // A valid IdentityCertificate has at least 4 name components,
116  // as it follows `<...>/KEY/<...>/<key-id>/ID-CERT/<version>` naming model.
117  if (certificateName.size() < 4) {
118  BOOST_THROW_EXCEPTION(std::invalid_argument("Certificate is invalid"));
119  }
120 
121  return security::signingByCertificate(certificateName);
122 }
123 
124 CommandOptions&
125 CommandOptions::setSigningCertificate(const Name& certificateName)
126 {
127  m_signingInfo = makeSigningInfoFromIdentityCertificate(certificateName);
128  return *this;
129 }
130 
131 CommandOptions&
132 CommandOptions::setSigningCertificate(const IdentityCertificate& certificate)
133 {
134  m_signingInfo = makeSigningInfoFromIdentityCertificate(certificate.getName());
135  return *this;
136 }
137 
138 #endif // NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS
139 
140 } // namespace nfd
141 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
CommandOptions()
constructs CommandOptions
static security::SigningInfo makeSigningInfoFromIdentityCertificate(const Name &certificateName)
picks the default certificate of a specific identity Name
static const Name DEFAULT_PREFIX
gives the default command prefix: ndn:/localhost/nfd
Signing parameters passed to KeyChain.
SigningInfo signingByCertificate(const Name &certName)
CommandOptions & setTimeout(const time::milliseconds &timeout)
sets command timeout
const Name & getSignerName() const
contains options for ControlCommand execution
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
no signer is specified, use default setting or follow the trust schema
SigningInfo signingByIdentity(const Name &identity)
Name abstraction to represent an absolute name.
Definition: name.hpp:46
signer is a certificate, use it directly
CommandOptions & setSigningInfo(const security::SigningInfo &signingInfo)
sets signing parameters
size_t size() const
Get the number of components.
Definition: name.hpp:408
picks the default signing identity and certificate
static const time::milliseconds DEFAULT_TIMEOUT
gives the default command timeout: 10000ms
SigningParamsKind
indicates the selection of signing parameters
signer is an identity, use its default key and default certificate
CommandOptions & setPrefix(const Name &prefix)
sets command prefix
SignerType getSignerType() const