Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 1944281 | 2018-11-23 14:00:04 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2022 Regents of the University of California. |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 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 | |
Davide Pesavento | 0990441 | 2021-03-24 16:40:53 -0400 | [diff] [blame] | 22 | #ifndef NDN_CXX_SECURITY_PIB_IMPL_IDENTITY_IMPL_HPP |
| 23 | #define NDN_CXX_SECURITY_PIB_IMPL_IDENTITY_IMPL_HPP |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 24 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 25 | #include "ndn-cxx/security/pib/key-container.hpp" |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace security { |
| 29 | namespace pib { |
| 30 | |
| 31 | class PibImpl; |
| 32 | |
| 33 | namespace detail { |
| 34 | |
| 35 | /** |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 36 | * @brief Backend instance of Identity. |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 37 | * |
| 38 | * An Identity has only one backend instance, but may have multiple frontend handles. |
| 39 | * Each frontend handle is associated with the only one backend IdentityImpl. |
| 40 | * |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 41 | * @throw PibImpl::Error When the underlying implementation has a non-semantic error. |
| 42 | * @sa Identity |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 43 | */ |
| 44 | class IdentityImpl : noncopyable |
| 45 | { |
| 46 | public: |
| 47 | /** |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 48 | * @brief Create an identity with name @p identityName. |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 49 | * |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 50 | * @param identityName The name of the identity. |
Davide Pesavento | 50f6675 | 2017-05-15 20:57:12 -0400 | [diff] [blame] | 51 | * @param pibImpl The PIB backend implementation. |
Davide Pesavento | 8618c1e | 2022-05-05 15:20:02 -0400 | [diff] [blame^] | 52 | * @pre The identity must exist in the backend. |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 53 | */ |
Davide Pesavento | 8618c1e | 2022-05-05 15:20:02 -0400 | [diff] [blame^] | 54 | IdentityImpl(const Name& identityName, shared_ptr<PibImpl> pibImpl); |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 55 | |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 56 | // See security::pib::Identity for the documentation of the following methods |
| 57 | |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 58 | const Name& |
| 59 | getName() const |
| 60 | { |
| 61 | return m_name; |
| 62 | } |
| 63 | |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 64 | Key |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 65 | addKey(span<const uint8_t> key, const Name& keyName); |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 66 | |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 67 | void |
| 68 | removeKey(const Name& keyName); |
| 69 | |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 70 | Key |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 71 | getKey(const Name& keyName) const |
| 72 | { |
| 73 | BOOST_ASSERT(m_keys.isConsistent()); |
| 74 | return m_keys.get(keyName); |
| 75 | } |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 76 | |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 77 | const KeyContainer& |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 78 | getKeys() const |
| 79 | { |
| 80 | BOOST_ASSERT(m_keys.isConsistent()); |
| 81 | return m_keys; |
| 82 | } |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 83 | |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 84 | Key |
| 85 | setDefaultKey(const Name& keyName) |
| 86 | { |
| 87 | return setDefaultKey(m_keys.get(keyName)); |
| 88 | } |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 89 | |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 90 | Key |
| 91 | setDefaultKey(span<const uint8_t> key, const Name& keyName) |
| 92 | { |
| 93 | return setDefaultKey(m_keys.add(key, keyName)); |
| 94 | } |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 95 | |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 96 | Key |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 97 | getDefaultKey() const; |
| 98 | |
| 99 | private: |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 100 | Key |
| 101 | setDefaultKey(Key key); |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 102 | |
Davide Pesavento | 56cc0d7 | 2022-04-29 23:00:23 -0400 | [diff] [blame] | 103 | private: |
| 104 | const Name m_name; |
| 105 | |
| 106 | const shared_ptr<PibImpl> m_pib; |
Davide Pesavento | 50f6675 | 2017-05-15 20:57:12 -0400 | [diff] [blame] | 107 | |
| 108 | KeyContainer m_keys; |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 109 | mutable Key m_defaultKey; |
Yingdi Yu | cbe72b0 | 2015-11-25 17:35:37 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace detail |
| 113 | } // namespace pib |
| 114 | } // namespace security |
| 115 | } // namespace ndn |
| 116 | |
Davide Pesavento | 0990441 | 2021-03-24 16:40:53 -0400 | [diff] [blame] | 117 | #endif // NDN_CXX_SECURITY_PIB_IMPL_IDENTITY_IMPL_HPP |