identity.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 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_IDENTITY_HPP
23 #define NDN_CXX_SECURITY_PIB_IDENTITY_HPP
24 
26 
27 namespace ndn {
28 namespace security {
29 
30 inline namespace v2 {
31 class KeyChain;
32 } // inline namespace v2
33 
34 namespace pib {
35 
36 class IdentityContainer;
37 
38 namespace detail {
39 class IdentityImpl;
40 } // namespace detail
41 
49 class Identity
50 {
51 public:
72  Identity() noexcept;
73 
77  const Name&
78  getName() const;
79 
85  Key
86  getKey(const Name& keyName) const;
87 
91  const KeyContainer&
92  getKeys() const;
93 
98  Key
99  getDefaultKey() const;
100 
104  explicit
105  operator bool() const noexcept;
106 
107 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // write operations are accessible only by KeyChain
117  Key
118  addKey(span<const uint8_t> key, const Name& keyName) const;
119 
124  void
125  removeKey(const Name& keyName) const;
126 
133  Key
134  setDefaultKey(const Name& keyName) const;
135 
141  Key
142  setDefaultKey(span<const uint8_t> key, const Name& keyName) const;
143 
144 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // private interface for IdentityContainer
145  explicit
146  Identity(weak_ptr<detail::IdentityImpl> impl) noexcept;
147 
148 private:
154  shared_ptr<detail::IdentityImpl>
155  lock() const;
156 
157  bool
158  equals(const Identity& other) const noexcept;
159 
160  // NOTE
161  // The following "hidden friend" non-member operators are available
162  // via argument-dependent lookup only and must be defined inline.
163 
164  friend bool
165  operator==(const Identity& lhs, const Identity& rhs)
166  {
167  return lhs.equals(rhs);
168  }
169 
170  friend bool
171  operator!=(const Identity& lhs, const Identity& rhs)
172  {
173  return !lhs.equals(rhs);
174  }
175 
176  friend std::ostream&
177  operator<<(std::ostream& os, const Identity& id)
178  {
179  return os << (id ? id.getName() : "(empty)");
180  }
181 
182 private:
183  weak_ptr<detail::IdentityImpl> m_impl;
184 
185  friend KeyChain;
186  friend IdentityContainer;
187 };
188 
189 } // namespace pib
190 
191 using pib::Identity;
192 
193 } // namespace security
194 } // namespace ndn
195 
196 #endif // NDN_CXX_SECURITY_PIB_IDENTITY_HPP
Represents an absolute name.
Definition: name.hpp:44
Container of identities of a PIB.
Frontend handle for an identity in the PIB.
Definition: identity.hpp:50
Key getDefaultKey() const
Return the default key for this identity.
Definition: identity.cpp:79
const KeyContainer & getKeys() const
Return all the keys of this identity.
Definition: identity.cpp:61
const Name & getName() const
Return the name of the identity.
Definition: identity.cpp:37
friend std::ostream & operator<<(std::ostream &os, const Identity &id)
Definition: identity.hpp:177
Key getKey(const Name &keyName) const
Obtain a handle to the key with the given name.
Definition: identity.cpp:55
Identity() noexcept
Default constructor.
friend bool operator!=(const Identity &lhs, const Identity &rhs)
Definition: identity.hpp:171
Container of keys of an identity.
Frontend handle for a key in the PIB.
Definition: key.hpp:51
The main interface for signing key management.
Definition: key-chain.hpp:87
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
Definition: data.cpp:25