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-2021 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_CXX_SECURITY_SIGNING_INFO_HPP
23 #define NDN_CXX_SECURITY_SIGNING_INFO_HPP
24 
25 #include "ndn-cxx/name.hpp"
31 
32 namespace ndn {
33 namespace security {
34 
41  V03,
43  V02,
44 };
45 
53 {
54 public:
55  class Error : public std::runtime_error
56  {
57  public:
58  using std::runtime_error::runtime_error;
59  };
60 
61  enum SignerType {
63  SIGNER_TYPE_NULL = 0,
65  SIGNER_TYPE_ID = 1,
67  SIGNER_TYPE_KEY = 2,
69  SIGNER_TYPE_CERT = 3,
71  SIGNER_TYPE_SHA256 = 4,
73  SIGNER_TYPE_HMAC = 5,
74  };
75 
76 public:
86  explicit
87  SigningInfo(SignerType signerType = SIGNER_TYPE_NULL,
88  const Name& signerName = Name(),
89  const SignatureInfo& signatureInfo = SignatureInfo());
90 
94  explicit
95  SigningInfo(const Identity& identity);
96 
100  explicit
101  SigningInfo(const Key& key);
102 
116  explicit
117  SigningInfo(const std::string& signingStr);
118 
123  SigningInfo&
124  setSigningIdentity(const Name& identity);
125 
130  SigningInfo&
131  setSigningKeyName(const Name& keyName);
132 
137  SigningInfo&
138  setSigningCertName(const Name& certificateName);
139 
144  SigningInfo&
145  setSigningHmacKey(const std::string& hmacKey);
146 
151  SigningInfo&
152  setSha256Signing();
153 
158  SigningInfo&
159  setPibIdentity(const Identity& identity);
160 
165  SigningInfo&
166  setPibKey(const Key& key);
167 
171  SignerType
173  {
174  return m_type;
175  }
176 
180  const Name&
182  {
183  return m_name;
184  }
185 
191  const Identity&
193  {
194  BOOST_ASSERT(m_type == SIGNER_TYPE_ID);
195  return m_identity;
196  }
197 
202  const Key&
203  getPibKey() const
204  {
205  BOOST_ASSERT(m_type == SIGNER_TYPE_KEY);
206  return m_key;
207  }
208 
209  shared_ptr<transform::PrivateKey>
210  getHmacKey() const
211  {
212  BOOST_ASSERT(m_type == SIGNER_TYPE_HMAC);
213  return m_hmacKey;
214  }
215 
219  SigningInfo&
221  {
222  m_digestAlgorithm = algorithm;
223  return *this;
224  }
225 
231  {
232  return m_digestAlgorithm;
233  }
234 
238  SigningInfo&
239  setSignatureInfo(const SignatureInfo& signatureInfo);
240 
244  const SignatureInfo&
246  {
247  return m_info;
248  }
249 
255  SigningInfo&
257  {
258  m_signedInterestFormat = signedInterestFormat;
259  return *this;
260  }
261 
269  {
270  return m_signedInterestFormat;
271  }
272 
273 public:
277  static const Name&
278  getDigestSha256Identity();
279 
283  static const Name&
284  getHmacIdentity();
285 
286 private: // non-member operators
287  // NOTE: the following "hidden friend" operators are available via
288  // argument-dependent lookup only and must be defined inline.
289 
290  friend bool
291  operator==(const SigningInfo& lhs, const SigningInfo& rhs)
292  {
293  return !(lhs != rhs);
294  }
295 
296  friend bool
297  operator!=(const SigningInfo& lhs, const SigningInfo& rhs)
298  {
299  return lhs.m_type != rhs.m_type ||
300  lhs.m_name != rhs.m_name ||
301  lhs.m_digestAlgorithm != rhs.m_digestAlgorithm ||
302  lhs.m_info != rhs.m_info ||
303  lhs.m_signedInterestFormat != rhs.m_signedInterestFormat;
304  }
305 
306 private:
307  SignerType m_type;
308  Name m_name;
309  Identity m_identity;
310  Key m_key;
311  shared_ptr<transform::PrivateKey> m_hmacKey;
312  DigestAlgorithm m_digestAlgorithm;
313  SignatureInfo m_info;
314  SignedInterestFormat m_signedInterestFormat;
315 };
316 
317 std::ostream&
318 operator<<(std::ostream& os, const SigningInfo& si);
319 
320 std::ostream&
321 operator<<(std::ostream& os, const SignedInterestFormat& format);
322 
323 } // namespace security
324 } // namespace ndn
325 
326 #endif // NDN_CXX_SECURITY_SIGNING_INFO_HPP
Sign Interest using Packet Specification v0.3 semantics.
Copyright (c) 2011-2015 Regents of the University of California.
Represents a SignatureInfo or InterestSignatureInfo TLV element.
const SignatureInfo & getSignatureInfo() const
DigestAlgorithm getDigestAlgorithm() const
friend bool operator!=(const SigningInfo &lhs, const SigningInfo &rhs)
const Key & getPibKey() const
SigningInfo & setDigestAlgorithm(const DigestAlgorithm &algorithm)
Set the digest algorithm for signing operations.
Sign Interest using Packet Specification v0.2 semantics.
shared_ptr< transform::PrivateKey > getHmacKey() const
Signing parameters passed to KeyChain.
const Name & getSignerName() const
A frontend handle of a key instance.
Definition: key.hpp:49
SignedInterestFormat getSignedInterestFormat() const
Represents an absolute name.
Definition: name.hpp:41
const Identity & getPibIdentity() const
friend bool operator==(const SigningInfo &lhs, const SigningInfo &rhs)
A frontend handle of an Identity.
Definition: identity.hpp:47
SigningInfo & setSignedInterestFormat(SignedInterestFormat signedInterestFormat)
Set signed Interest format.
std::ostream & operator<<(std::ostream &os, const SigningInfo &si)
SignerType getSignerType() const