All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
signing-info.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_SIGNING_INFO_HPP
24 #define NDN_SIGNING_INFO_HPP
25 
26 #include "../name.hpp"
27 #include "../signature.hpp"
28 #include "pib/pib-identity.hpp"
29 #include "pib/pib-key.hpp"
30 #include "security-common.hpp"
31 
32 namespace ndn {
33 
39 class SigningInfo {
40 public:
41  enum SignerType {
52  };
53 
64  (SignerType signerType = SIGNER_TYPE_NULL, const Name& signerName = Name())
65  {
66  reset(signerType);
67  name_ = signerName;
68  digestAlgorithm_ = DIGEST_ALGORITHM_SHA256;
69  }
70 
78  SigningInfo(const ptr_lib::shared_ptr<PibIdentity>& identity)
79  {
80  digestAlgorithm_ = DIGEST_ALGORITHM_SHA256;
81  setPibIdentity(identity);
82  }
83 
91  SigningInfo(const ptr_lib::shared_ptr<PibKey>& key)
92  {
93  digestAlgorithm_ = DIGEST_ALGORITHM_SHA256;
94  setPibKey(key);
95  }
96 
114  SigningInfo(const std::string& signingString);
115 
122  SigningInfo&
123  setSigningIdentity(const Name& identityName)
124  {
125  reset(SIGNER_TYPE_ID);
126  name_ = identityName;
127  return *this;
128  }
129 
136  SigningInfo&
137  setSigningKeyName(const Name& keyName)
138  {
139  reset(SIGNER_TYPE_KEY);
140  name_ = keyName;
141  return *this;
142  }
143 
150  SigningInfo&
151  setSigningCertificateName(const Name& certificateName)
152  {
153  reset(SIGNER_TYPE_CERT);
154  name_ = certificateName;
155  return *this;
156  }
157 
163  SigningInfo&
165  {
166  reset(SIGNER_TYPE_SHA256);
167  digestAlgorithm_ = DIGEST_ALGORITHM_SHA256;
168  return *this;
169  }
170 
179  SigningInfo&
180  setPibIdentity(const ptr_lib::shared_ptr<PibIdentity>& identity)
181  {
182  reset(SIGNER_TYPE_ID);
183  name_ = identity ? identity->getName() : Name();
184  identity_ = identity;
185  return *this;
186  }
187 
196  SigningInfo&
197  setPibKey(const ptr_lib::shared_ptr<PibKey>& key)
198  {
199  reset(SIGNER_TYPE_KEY);
200  name_ = key ? key->getName() : Name();
201  key_ = key;
202  return *this;
203  }
204 
209  SignerType
210  getSignerType() const { return type_; }
211 
217  const Name&
218  getSignerName() const { return name_; }
219 
227  const ptr_lib::shared_ptr<PibIdentity>&
228  getPibIdentity() const;
229 
237  const ptr_lib::shared_ptr<PibKey>&
238  getPibKey() const;
239 
245  SigningInfo&
246  setDigestAlgorithm(DigestAlgorithm digestAlgorithm)
247  {
248  digestAlgorithm_ = digestAlgorithm;
249  return *this;
250  }
251 
256  DigestAlgorithm
257  getDigestAlgorithm() const { return digestAlgorithm_; }
258 
266  SigningInfo&
267  setValidityPeriod(const ValidityPeriod& validityPeriod)
268  {
269  validityPeriod_ = validityPeriod;
270  return *this;
271  }
272 
279  const ValidityPeriod&
280  getValidityPeriod() const { return validityPeriod_; }
281 
286  std::string
287  toString() const;
288 
294  static Name
295  getDigestSha256Identity() { return Name("/localhost/identity/digest-sha256"); }
296 
297 private:
303  void
304  reset(SignerType signerType);
305 
306  SignerType type_;
307  Name name_;
308  ptr_lib::shared_ptr<PibIdentity> identity_;
309  ptr_lib::shared_ptr<PibKey> key_;
310  DigestAlgorithm digestAlgorithm_;
311  ValidityPeriod validityPeriod_;
312 };
313 
314 inline std::ostream&
315 operator << (std::ostream& os, const SigningInfo& info)
316 {
317  os << info.toString();
318  return os;
319 }
320 
321 
322 }
323 
324 #endif
DigestAlgorithm getDigestAlgorithm() const
Get the digest algorithm for public key operations.
Definition: signing-info.hpp:257
const ptr_lib::shared_ptr< PibKey > & getPibKey() const
Get the PibKey of the signer.
Definition: signing-info.cpp:69
The signer is a key.
Definition: signing-info.hpp:47
std::string toString() const
Get the string representation of this SigningInfo.
Definition: signing-info.cpp:77
Use a SHA-256 digest.
Definition: signing-info.hpp:51
SigningInfo(const ptr_lib::shared_ptr< PibIdentity > &identity)
Create a SigningInfo of type SIGNER_TYPE_ID according to the given PibIdentity.
Definition: signing-info.hpp:78
SignerType
Definition: signing-info.hpp:41
A SigningInfo holds the signing parameters passed to the KeyChain.
Definition: signing-info.hpp:39
SigningInfo & setSigningKeyName(const Name &keyName)
Set this to type SIGNER_TYPE_KEY and a key with name keyName.
Definition: signing-info.hpp:137
SigningInfo & setDigestAlgorithm(DigestAlgorithm digestAlgorithm)
Set the digest algorithm for public key operations.
Definition: signing-info.hpp:246
SigningInfo & setSigningCertificateName(const Name &certificateName)
Set this to type SIGNER_TYPE_CERT and a certificate with name certificateName.
Definition: signing-info.hpp:151
SigningInfo & setValidityPeriod(const ValidityPeriod &validityPeriod)
Set the validity period for the signature info.
Definition: signing-info.hpp:267
static Name getDigestSha256Identity()
Get the localhost identity which indicates that the signature is generated using SHA-256.
Definition: signing-info.hpp:295
A ValidityPeriod is used in a Data packet's SignatureInfo and represents the begin and end times of a...
Definition: validity-period.hpp:37
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
SigningInfo & setPibIdentity(const ptr_lib::shared_ptr< PibIdentity > &identity)
Set this to type SIGNER_TYPE_ID according to the given PibIdentity.
Definition: signing-info.hpp:180
SigningInfo & setPibKey(const ptr_lib::shared_ptr< PibKey > &key)
Set this to type SIGNER_TYPE_KEY according to the given PibKey.
Definition: signing-info.hpp:197
SignerType getSignerType() const
Get the type of the signer.
Definition: signing-info.hpp:210
const ValidityPeriod & getValidityPeriod() const
Get the validity period for the signature info.
Definition: signing-info.hpp:280
const ptr_lib::shared_ptr< PibIdentity > & getPibIdentity() const
Get the PibIdentity of the signer.
Definition: signing-info.cpp:61
No signer is specified.
Definition: signing-info.hpp:43
SigningInfo & setSha256Signing()
Set this to type SIGNER_TYPE_SHA256, and set the digest algorithm to DIGEST_ALGORITHM_SHA256.
Definition: signing-info.hpp:164
The signer is an identity.
Definition: signing-info.hpp:45
const Name & getSignerName() const
Get the name of signer.
Definition: signing-info.hpp:218
SigningInfo & setSigningIdentity(const Name &identityName)
Set this to type SIGNER_TYPE_ID and an identity with name identityName.
Definition: signing-info.hpp:123
SigningInfo(SignerType signerType=SIGNER_TYPE_NULL, const Name &signerName=Name())
Create a SigningInfo with the optional signerType and signerName and other default values...
Definition: signing-info.hpp:64
The signer is a certificate.
Definition: signing-info.hpp:49
SigningInfo(const ptr_lib::shared_ptr< PibKey > &key)
Create a SigningInfo of type SIGNER_TYPE_KEY according to the given PibKey.
Definition: signing-info.hpp:91