ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
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-2023 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
27namespace ndn::security {
28
29class KeyChain;
30
31namespace pib {
32
33class IdentityContainer;
34class IdentityImpl;
35
43class Identity : private boost::equality_comparable<Identity>
44{
45public:
66 Identity() noexcept;
67
71 const Name&
72 getName() const;
73
79 Key
80 getKey(const Name& keyName) const;
81
85 const KeyContainer&
86 getKeys() const;
87
92 Key
93 getDefaultKey() const;
94
98 explicit
99 operator bool() const noexcept;
100
101NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // write operations are accessible only by KeyChain
111 Key
112 addKey(span<const uint8_t> key, const Name& keyName) const;
113
118 void
119 removeKey(const Name& keyName) const;
120
127 Key
128 setDefaultKey(const Name& keyName) const;
129
135 Key
136 setDefaultKey(span<const uint8_t> key, const Name& keyName) const;
137
138NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // private interface for IdentityContainer
139 explicit
140 Identity(weak_ptr<IdentityImpl> impl) noexcept;
141
142private:
148 shared_ptr<IdentityImpl>
149 lock() const;
150
151 bool
152 equals(const Identity& other) const noexcept;
153
154 // NOTE
155 // The following "hidden friend" non-member operators are available
156 // via argument-dependent lookup only and must be defined inline.
157 // boost::equality_comparable provides != operator.
158
159 friend bool
160 operator==(const Identity& lhs, const Identity& rhs) noexcept
161 {
162 return lhs.equals(rhs);
163 }
164
165 friend std::ostream&
166 operator<<(std::ostream& os, const Identity& id)
167 {
168 if (id)
169 return os << id.getName();
170 else
171 return os << "(empty)";
172 }
173
174private:
175 weak_ptr<IdentityImpl> m_impl;
176
177 friend KeyChain;
178 friend IdentityContainer;
179};
180
181} // namespace pib
182
183using pib::Identity;
184
185} // namespace ndn::security
186
187#endif // NDN_CXX_SECURITY_PIB_IDENTITY_HPP
Represents an absolute name.
Definition name.hpp:45
The main interface for signing key management.
Definition key-chain.hpp:87
Container of identities of a PIB.
Frontend handle for an identity in the PIB.
Definition identity.hpp:44
Key getDefaultKey() const
Return the default key for this identity.
Definition identity.cpp:77
const KeyContainer & getKeys() const
Return all the keys of this identity.
Definition identity.cpp:59
const Name & getName() const
Return the name of the identity.
Definition identity.cpp:35
Key getKey(const Name &keyName) const
Obtain a handle to the key with the given name.
Definition identity.cpp:53
Identity() noexcept
Default constructor.
friend std::ostream & operator<<(std::ostream &os, const Identity &id)
Definition identity.hpp:166
Container of keys of an identity.
Frontend handle for a key in the PIB.
Definition key.hpp:45
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition common.hpp:49
Contains the ndn-cxx security framework.