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-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_PIB_KEY_HPP
23 #define NDN_CXX_SECURITY_PIB_KEY_HPP
24 
27 
28 namespace ndn {
29 namespace security {
30 
31 inline namespace v2 {
32 class KeyChain;
33 } // inline 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  span<const uint8_t>
102  getPublicKey() const;
103 
110  getCertificate(const Name& certName) const;
111 
115  const CertificateContainer&
116  getCertificates() const;
117 
122  const 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 Certificate& certificate) const;
141 
146  void
147  removeCertificate(const Name& certName) const;
148 
155  const Certificate&
156  setDefaultCertificate(const Name& certName) const;
157 
163  const Certificate&
164  setDefaultCertificate(const 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 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 inline 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 } // inline namespace v2
219 
220 } // namespace security
221 } // namespace ndn
222 
223 #endif // NDN_CXX_SECURITY_PIB_KEY_HPP
Represents an absolute name.
Definition: name.hpp:46
Represents a name component.
Container of certificates of a key.
A frontend handle of a key instance.
Definition: key.hpp:50
Key()
Default Constructor.
KeyType getKeyType() const
Get key type.
Definition: key.cpp:50
const Certificate & getDefaultCertificate() const
Get the default certificate for this Key.
Definition: key.cpp:98
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
span< const uint8_t > getPublicKey() const
Get public key bits.
Definition: key.cpp:56
Certificate getCertificate(const Name &certName) const
Get a certificate with certName.
Definition: key.cpp:74
const Name & getName() const
Get key name.
Definition: key.cpp:38
const CertificateContainer & getCertificates() const
Get all certificates for this key.
Definition: key.cpp:80
Represents an NDN certificate following the version 2.0 format.
Definition: certificate.hpp:61
The interface of signing key management.
Definition: key-chain.hpp:46
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
bool operator!=(const Identity &lhs, const Identity &rhs)
Definition: identity.cpp:101
bool operator==(const Identity &lhs, const Identity &rhs)
Definition: identity.hpp:167
std::ostream & operator<<(std::ostream &os, const Identity &id)
Definition: identity.cpp:107
bool isValidKeyName(const Name &keyName)
Check if keyName follow the naming conventions for the key name.
Definition: key.cpp:153
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
Definition: key.cpp:160
Name constructKeyName(const Name &identity, const name::Component &keyId)
Construct key name based on the appropriate naming conventions.
Definition: key.cpp:143
Definition: data.cpp:25
KeyType
The type of a cryptographic key.