NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
key.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 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_PIB_KEY_HPP
23 #define NDN_SECURITY_PIB_KEY_HPP
24 
27 
28 namespace ndn {
29 namespace security {
30 
31 namespace v2 {
32 class KeyChain;
33 } // namespace v2
34 
35 namespace pib {
36 
37 namespace detail {
38 class KeyImpl;
39 } // namespace detail
40 
49 class Key
50 {
51 public:
70  Key();
71 
77  explicit
78  Key(weak_ptr<detail::KeyImpl> impl);
79 
83  const Name&
84  getName() const;
85 
89  const Name&
90  getIdentity() const;
91 
95  KeyType
96  getKeyType() const;
97 
101  const Buffer&
102  getPublicKey() const;
103 
110  getCertificate(const Name& certName) const;
111 
115  const CertificateContainer&
116  getCertificates() const;
117 
122  const v2::Certificate&
123  getDefaultCertificate() const;
124 
128  explicit
129  operator bool() const;
130 
131 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // write operations should be private
139  void
140  addCertificate(const v2::Certificate& certificate) const;
141 
146  void
147  removeCertificate(const Name& certName) const;
148 
155  const v2::Certificate&
156  setDefaultCertificate(const Name& certName) const;
157 
163  const v2::Certificate&
164  setDefaultCertificate(const v2::Certificate& certificate) const;
165 
166 private:
172  shared_ptr<detail::KeyImpl>
173  lock() const;
174 
175 private:
176  weak_ptr<detail::KeyImpl> m_impl;
177 
178  friend class v2::KeyChain;
179  friend bool operator!=(const Key&, const Key&);
180 };
181 
182 bool
183 operator!=(const Key& lhs, const Key& rhs);
184 
185 inline bool
186 operator==(const Key& lhs, const Key& rhs)
187 {
188  return !(lhs != rhs);
189 }
190 
191 std::ostream&
192 operator<<(std::ostream& os, const Key& key);
193 
194 } // namespace pib
195 
196 using pib::Key;
197 
198 namespace v2 {
199 
203 Name
204 constructKeyName(const Name& identity, const name::Component& keyId);
205 
209 bool
210 isValidKeyName(const Name& keyName);
211 
215 Name
216 extractIdentityFromKeyName(const Name& keyName);
217 
218 } // namespace v2
219 
220 } // namespace security
221 } // namespace ndn
222 
223 #endif // NDN_SECURITY_PIB_KEY_HPP
std::ostream & operator<<(std::ostream &os, const Identity &id)
Definition: identity.cpp:107
Copyright (c) 2011-2015 Regents of the University of California.
The certificate following the certificate format naming convention.
Definition: certificate.hpp:81
The interface of signing key management.
Definition: key-chain.hpp:46
bool operator==(const Identity &lhs, const Identity &rhs)
Definition: identity.hpp:162
KeyType getKeyType() const
Get key type.
Definition: key.cpp:50
bool isValidKeyName(const Name &keyName)
Check if keyName follow the naming conventions for the key name.
Definition: key.cpp:153
KeyType
The type of a cryptographic key.
Container of certificates of a key.
A frontend handle of a key instance.
Definition: key.hpp:49
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
Represents an absolute name.
Definition: name.hpp:43
const Name & getName() const
Get key name.
Definition: key.cpp:38
const v2::Certificate & setDefaultCertificate(const Name &certName) const
Set an existing certificate with certName as the default certificate.
Definition: key.cpp:86
Represents a name component.
Name constructKeyName(const Name &identity, const name::Component &keyId)
Construct key name based on the appropriate naming conventions.
Definition: key.cpp:143
const v2::Certificate & getDefaultCertificate() const
Get the default certificate for this Key.
Definition: key.cpp:98
bool operator!=(const Identity &lhs, const Identity &rhs)
Definition: identity.cpp:101
const Buffer & getPublicKey() const
Get public key bits.
Definition: key.cpp:56
v2::Certificate getCertificate(const Name &certName) const
Get a certificate with certName.
Definition: key.cpp:74
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
Definition: key.cpp:160
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:40
void removeCertificate(const Name &certName) const
Remove a certificate with certName.
Definition: key.cpp:68
Key()
Default Constructor.
friend bool operator!=(const Key &, const Key &)
Definition: key.cpp:121
const Name & getIdentity() const
Get the name of the belonging identity.
Definition: key.cpp:44
ndn security v2 KeyChain
Definition: key-chain.cpp:69
const CertificateContainer & getCertificates() const
Get all certificates for this key.
Definition: key.cpp:80