NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
signing-info.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 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 #ifndef NDN_SECURITY_SIGNING_INFO_HPP
23 #define NDN_SECURITY_SIGNING_INFO_HPP
24 
25 #include "ndn-cxx/name.hpp"
31 
32 namespace ndn {
33 namespace security {
34 
42 {
43 public:
44  class Error : public std::runtime_error
45  {
46  public:
47  using std::runtime_error::runtime_error;
48  };
49 
50  enum SignerType {
63  };
64 
65 public:
75  explicit
77  const Name& signerName = getEmptyName(),
78  const SignatureInfo& signatureInfo = getEmptySignatureInfo());
79 
83  explicit
84  SigningInfo(const Identity& identity);
85 
89  explicit
90  SigningInfo(const Key& key);
91 
105  explicit
106  SigningInfo(const std::string& signingStr);
107 
112  SigningInfo&
113  setSigningIdentity(const Name& identity);
114 
119  SigningInfo&
120  setSigningKeyName(const Name& keyName);
121 
126  SigningInfo&
127  setSigningCertName(const Name& certificateName);
128 
133  SigningInfo&
134  setSigningHmacKey(const std::string& hmacKey);
135 
140  SigningInfo&
142 
147  SigningInfo&
148  setPibIdentity(const Identity& identity);
149 
154  SigningInfo&
155  setPibKey(const Key& key);
156 
160  SignerType
162  {
163  return m_type;
164  }
165 
169  const Name&
171  {
172  return m_name;
173  }
174 
180  const Identity&
182  {
183  BOOST_ASSERT(m_type == SIGNER_TYPE_ID);
184  return m_identity;
185  }
186 
191  const Key&
192  getPibKey() const
193  {
194  BOOST_ASSERT(m_type == SIGNER_TYPE_KEY);
195  return m_key;
196  }
197 
198  shared_ptr<transform::PrivateKey>
199  getHmacKey() const
200  {
201  BOOST_ASSERT(m_type == SIGNER_TYPE_HMAC);
202  return m_hmacKey;
203  }
204 
208  SigningInfo&
210  {
211  m_digestAlgorithm = algorithm;
212  return *this;
213  }
214 
220  {
221  return m_digestAlgorithm;
222  }
223 
227  SigningInfo&
228  setSignatureInfo(const SignatureInfo& signatureInfo);
229 
233  const SignatureInfo&
235  {
236  return m_info;
237  }
238 
239 public:
240  static const Name&
241  getEmptyName();
242 
243  static const SignatureInfo&
245 
249  static const Name&
251 
255  static const Name&
256  getHmacIdentity();
257 
258 private: // non-member operators
259  // NOTE: the following "hidden friend" operators are available via
260  // argument-dependent lookup only and must be defined inline.
261 
262  friend bool
263  operator==(const SigningInfo& lhs, const SigningInfo& rhs)
264  {
265  return !(lhs != rhs);
266  }
267 
268  friend bool
269  operator!=(const SigningInfo& lhs, const SigningInfo& rhs)
270  {
271  return lhs.m_type != rhs.m_type ||
272  lhs.m_name != rhs.m_name ||
273  lhs.m_digestAlgorithm != rhs.m_digestAlgorithm ||
274  lhs.m_info != rhs.m_info;
275  }
276 
277 private:
278  SignerType m_type;
279  Name m_name;
280  Identity m_identity;
281  Key m_key;
282  shared_ptr<transform::PrivateKey> m_hmacKey;
283  DigestAlgorithm m_digestAlgorithm;
284  SignatureInfo m_info;
285 };
286 
287 std::ostream&
288 operator<<(std::ostream& os, const SigningInfo& si);
289 
290 } // namespace security
291 } // namespace ndn
292 
293 #endif // NDN_SECURITY_SIGNING_INFO_HPP
ndn::security::SigningInfo::SigningInfo
SigningInfo(SignerType signerType=SIGNER_TYPE_NULL, const Name &signerName=getEmptyName(), const SignatureInfo &signatureInfo=getEmptySignatureInfo())
Constructor.
Definition: signing-info.cpp:61
key.hpp
ndn::security::SigningInfo::SignerType
SignerType
Definition: signing-info.hpp:50
identity.hpp
ndn::security::SigningInfo::setSigningIdentity
SigningInfo & setSigningIdentity(const Name &identity)
Set signer as an identity with name identity.
Definition: signing-info.cpp:123
ndn::security::SigningInfo::getPibIdentity
const Identity & getPibIdentity() const
Definition: signing-info.hpp:181
signature-info.hpp
security-common.hpp
ndn::security::SigningInfo
Signing parameters passed to KeyChain.
Definition: signing-info.hpp:42
ndn::security::SigningInfo::getHmacIdentity
static const Name & getHmacIdentity()
A localhost identity to indicate that the signature is generated using an HMAC key.
Definition: signing-info.cpp:55
name.hpp
ndn::DigestAlgorithm
DigestAlgorithm
Definition: security-common.hpp:96
ndn::security::SigningInfo::setSigningHmacKey
SigningInfo & setSigningHmacKey(const std::string &hmacKey)
Set signer to a base64-encoded HMAC key.
Definition: signing-info.cpp:149
ndn::security::SigningInfo::Error
Definition: signing-info.hpp:45
ndn::security::SigningInfo::setDigestAlgorithm
SigningInfo & setDigestAlgorithm(const DigestAlgorithm &algorithm)
Set the digest algorithm for signing operations.
Definition: signing-info.hpp:209
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::security::SigningInfo::setSha256Signing
SigningInfo & setSha256Signing()
Set SHA-256 as the signing method.
Definition: signing-info.cpp:168
ndn::security::SigningInfo::getEmptyName
static const Name & getEmptyName()
Definition: signing-info.cpp:34
ndn::security::SigningInfo::setSigningCertName
SigningInfo & setSigningCertName(const Name &certificateName)
Set signer as a certificate with name certificateName.
Definition: signing-info.cpp:141
ndn::security::SigningInfo::SIGNER_TYPE_ID
@ SIGNER_TYPE_ID
Signer is an identity, use its default key and default certificate.
Definition: signing-info.hpp:54
ndn::security::SigningInfo::setPibIdentity
SigningInfo & setPibIdentity(const Identity &identity)
Set signer as a PIB identity handler identity.
Definition: signing-info.cpp:176
private-key.hpp
ndn::security::operator<<
std::ostream & operator<<(std::ostream &os, const SigningInfo &si)
Definition: signing-info.cpp:201
ndn::SignatureInfo
Represents a SignatureInfo TLV element.
Definition: signature-info.hpp:35
ndn::security::SigningInfo::SIGNER_TYPE_KEY
@ SIGNER_TYPE_KEY
Signer is a key, use its default certificate.
Definition: signing-info.hpp:56
ndn::security::SigningInfo::setSignatureInfo
SigningInfo & setSignatureInfo(const SignatureInfo &signatureInfo)
Set a semi-prepared SignatureInfo;.
Definition: signing-info.cpp:194
ndn::security::SigningInfo::operator!=
friend bool operator!=(const SigningInfo &lhs, const SigningInfo &rhs)
Definition: signing-info.hpp:269
ndn::security::SigningInfo::getSignerType
SignerType getSignerType() const
Definition: signing-info.hpp:161
ndn::security::SigningInfo::getPibKey
const Key & getPibKey() const
Definition: signing-info.hpp:192
ndn::security::SigningInfo::getSignatureInfo
const SignatureInfo & getSignatureInfo() const
Definition: signing-info.hpp:234
ndn::security::SigningInfo::getSignerName
const Name & getSignerName() const
Definition: signing-info.hpp:170
ndn::security::SigningInfo::getHmacKey
shared_ptr< transform::PrivateKey > getHmacKey() const
Definition: signing-info.hpp:199
ndn::security::pib::Key
A frontend handle of a key instance.
Definition: key.hpp:50
ndn::security::SigningInfo::getEmptySignatureInfo
static const SignatureInfo & getEmptySignatureInfo()
Definition: signing-info.cpp:41
ndn::security::SigningInfo::operator==
friend bool operator==(const SigningInfo &lhs, const SigningInfo &rhs)
Definition: signing-info.hpp:263
ndn::security::SigningInfo::SIGNER_TYPE_CERT
@ SIGNER_TYPE_CERT
Signer is a certificate, use it directly.
Definition: signing-info.hpp:58
ndn::security::SigningInfo::setPibKey
SigningInfo & setPibKey(const Key &key)
Set signer as a PIB key handler key.
Definition: signing-info.cpp:185
ndn::security::SigningInfo::SIGNER_TYPE_HMAC
@ SIGNER_TYPE_HMAC
Signer is a HMAC key.
Definition: signing-info.hpp:62
ndn::security::SigningInfo::setSigningKeyName
SigningInfo & setSigningKeyName(const Name &keyName)
Set signer as a key with name keyName.
Definition: signing-info.cpp:132
ndn::security::pib::Identity
A frontend handle of an Identity.
Definition: identity.hpp:43
ndn::security::SigningInfo::getDigestAlgorithm
DigestAlgorithm getDigestAlgorithm() const
Definition: signing-info.hpp:219
ndn::security::SigningInfo::getDigestSha256Identity
static const Name & getDigestSha256Identity()
A localhost identity to indicate that the signature is generated using SHA-256.
Definition: signing-info.cpp:48
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::security::SigningInfo::SIGNER_TYPE_NULL
@ SIGNER_TYPE_NULL
No signer is specified, use default setting or follow the trust schema.
Definition: signing-info.hpp:52
ndn::security::SigningInfo::SIGNER_TYPE_SHA256
@ SIGNER_TYPE_SHA256
Use a SHA-256 digest only, no signer needs to be specified.
Definition: signing-info.hpp:60