All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
pib-key.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_PIB_KEY_HPP
24 #define NDN_PIB_KEY_HPP
25 
26 #include <ndn-cpp/security/security-common.hpp>
27 #include "pib-certificate-container.hpp"
28 
29 // Give friend access to the tests.
30 class TestKeyChain_Management_Test;
31 
32 namespace ndn {
33 
34 class PibKeyImpl;
35 
43 class PibKey {
44 public:
45  /*
46  * Get the key name.
47  * @return The key name.
48  * @throws std::domain_error if the backend implementation instance is invalid.
49  */
50  const Name&
51  getName();
52 
58  const Name&
60 
66  KeyType
67  getKeyType();
68 
74  const Blob&
75  getPublicKey();
76 
85  ptr_lib::shared_ptr<CertificateV2>
86  getCertificate(const Name& certificateName);
87 
94  ptr_lib::shared_ptr<CertificateV2>&
96 
103  static Name
104  constructKeyName(const Name& identityName, const Name::Component& keyId);
105 
111  static bool
112  isValidKeyName(const Name& keyName);
113 
119  static Name
120  extractIdentityFromKeyName(const Name& keyName);
121 
122 private:
123  friend class PibKeyContainer;
124  friend class KeyChain;
125  // Give friend access to the tests.
126  friend TestKeyChain_Management_Test;
127 
132  PibKey(ptr_lib::weak_ptr<PibKeyImpl> impl);
133 
144  void
145  addCertificate(const CertificateV2& certificate);
146 
155  void
156  removeCertificate(const Name& certificateName);
157 
168  const ptr_lib::shared_ptr<CertificateV2>&
169  setDefaultCertificate(const Name& certificateName);
170 
181  const ptr_lib::shared_ptr<CertificateV2>&
182  setDefaultCertificate(const CertificateV2& certificate);
183 
189  getCertificates();
190 
192  getCertificates() const { return const_cast<PibKey*>(this)->getCertificates(); }
193 
199  ptr_lib::shared_ptr<PibKeyImpl>
200  lock() const;
201 
202  // Disable the copy constructor and assignment operator.
203  PibKey(const PibKey& other);
204  PibKey& operator=(const PibKey& other);
205 
206  ptr_lib::weak_ptr<PibKeyImpl> impl_;
207 };
208 
209 }
210 
211 #endif
A PibCertificateContainer is used to search/enumerate the certificates of a key.
Definition: pib-certificate-container.hpp:44
ptr_lib::shared_ptr< CertificateV2 > getCertificate(const Name &certificateName)
Get the certificate with name certificateName.
Definition: pib-key.cpp:49
static bool isValidKeyName(const Name &keyName)
Check if keyName follows the naming conventions for a key name.
Definition: pib-key.cpp:82
ptr_lib::shared_ptr< CertificateV2 > & getDefaultCertificate()
Get the default certificate for this Key.
Definition: pib-key.cpp:55
CertificateV2 represents a certificate following the certificate format naming convention.
Definition: certificate-v2.hpp:81
static Name constructKeyName(const Name &identityName, const Name::Component &keyId)
Construct a key name based on the appropriate naming conventions.
Definition: pib-key.cpp:73
A Name::Component holds a read-only name component value.
Definition: name.hpp:45
KeyType
Definition: security-common.hpp:50
The PibKey class provides access to a key at the second level in the PIB's Identity-Key-Certificate h...
Definition: pib-key.hpp:43
KeyChain is the main class of the security library.
Definition: key-chain.hpp:53
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
static Name extractIdentityFromKeyName(const Name &keyName)
Extract the identity namespace from keyName.
Definition: pib-key.cpp:90
const Name & getIdentityName()
Get the name of the identity this key belongs to.
Definition: pib-key.cpp:40
const Blob & getPublicKey()
Get the public key encoding.
Definition: pib-key.cpp:46
A PibKeyContainer is used to search/enumerate the keys of an identity.
Definition: pib-key-container.hpp:42
KeyType getKeyType()
Get the key type.
Definition: pib-key.cpp:43