blob: 36f7a3f28cf1e447b8e427a161f192c29f4cb0e9 [file] [log] [blame]
Yingdi Yucbe72b02015-11-25 17:35:37 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento19442812018-11-23 14:00:04 -05002/*
Davide Pesavento56cc0d72022-04-29 23:00:23 -04003 * Copyright (c) 2013-2022 Regents of the University of California.
Yingdi Yucbe72b02015-11-25 17:35:37 -08004 *
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 Pesavento09904412021-03-24 16:40:53 -040022#ifndef NDN_CXX_SECURITY_PIB_IMPL_IDENTITY_IMPL_HPP
23#define NDN_CXX_SECURITY_PIB_IMPL_IDENTITY_IMPL_HPP
Yingdi Yucbe72b02015-11-25 17:35:37 -080024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/security/pib/key-container.hpp"
Yingdi Yucbe72b02015-11-25 17:35:37 -080026
27namespace ndn {
28namespace security {
29namespace pib {
30
31class PibImpl;
32
33namespace detail {
34
35/**
Davide Pesavento56cc0d72022-04-29 23:00:23 -040036 * @brief Backend instance of Identity.
Yingdi Yucbe72b02015-11-25 17:35:37 -080037 *
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 Pesavento56cc0d72022-04-29 23:00:23 -040041 * @throw PibImpl::Error When the underlying implementation has a non-semantic error.
42 * @sa Identity
Yingdi Yucbe72b02015-11-25 17:35:37 -080043 */
44class IdentityImpl : noncopyable
45{
46public:
47 /**
Davide Pesavento56cc0d72022-04-29 23:00:23 -040048 * @brief Create an identity with name @p identityName.
Yingdi Yucbe72b02015-11-25 17:35:37 -080049 *
Davide Pesavento56cc0d72022-04-29 23:00:23 -040050 * @param identityName The name of the identity.
Davide Pesavento50f66752017-05-15 20:57:12 -040051 * @param pibImpl The PIB backend implementation.
Davide Pesavento8618c1e2022-05-05 15:20:02 -040052 * @pre The identity must exist in the backend.
Yingdi Yucbe72b02015-11-25 17:35:37 -080053 */
Davide Pesavento8618c1e2022-05-05 15:20:02 -040054 IdentityImpl(const Name& identityName, shared_ptr<PibImpl> pibImpl);
Yingdi Yucbe72b02015-11-25 17:35:37 -080055
Davide Pesavento56cc0d72022-04-29 23:00:23 -040056 // See security::pib::Identity for the documentation of the following methods
57
Yingdi Yucbe72b02015-11-25 17:35:37 -080058 const Name&
59 getName() const
60 {
61 return m_name;
62 }
63
Yingdi Yucbe72b02015-11-25 17:35:37 -080064 Key
Davide Pesavento765abc92021-12-27 00:44:04 -050065 addKey(span<const uint8_t> key, const Name& keyName);
Yingdi Yucbe72b02015-11-25 17:35:37 -080066
Yingdi Yucbe72b02015-11-25 17:35:37 -080067 void
68 removeKey(const Name& keyName);
69
Yingdi Yucbe72b02015-11-25 17:35:37 -080070 Key
Davide Pesavento56cc0d72022-04-29 23:00:23 -040071 getKey(const Name& keyName) const
72 {
73 BOOST_ASSERT(m_keys.isConsistent());
74 return m_keys.get(keyName);
75 }
Yingdi Yucbe72b02015-11-25 17:35:37 -080076
Yingdi Yucbe72b02015-11-25 17:35:37 -080077 const KeyContainer&
Davide Pesavento56cc0d72022-04-29 23:00:23 -040078 getKeys() const
79 {
80 BOOST_ASSERT(m_keys.isConsistent());
81 return m_keys;
82 }
Yingdi Yucbe72b02015-11-25 17:35:37 -080083
Davide Pesavento56cc0d72022-04-29 23:00:23 -040084 Key
85 setDefaultKey(const Name& keyName)
86 {
87 return setDefaultKey(m_keys.get(keyName));
88 }
Yingdi Yucbe72b02015-11-25 17:35:37 -080089
Davide Pesavento56cc0d72022-04-29 23:00:23 -040090 Key
91 setDefaultKey(span<const uint8_t> key, const Name& keyName)
92 {
93 return setDefaultKey(m_keys.add(key, keyName));
94 }
Yingdi Yucbe72b02015-11-25 17:35:37 -080095
Davide Pesavento56cc0d72022-04-29 23:00:23 -040096 Key
Yingdi Yucbe72b02015-11-25 17:35:37 -080097 getDefaultKey() const;
98
99private:
Davide Pesavento56cc0d72022-04-29 23:00:23 -0400100 Key
101 setDefaultKey(Key key);
Yingdi Yucbe72b02015-11-25 17:35:37 -0800102
Davide Pesavento56cc0d72022-04-29 23:00:23 -0400103private:
104 const Name m_name;
105
106 const shared_ptr<PibImpl> m_pib;
Davide Pesavento50f66752017-05-15 20:57:12 -0400107
108 KeyContainer m_keys;
Yingdi Yucbe72b02015-11-25 17:35:37 -0800109 mutable Key m_defaultKey;
Yingdi Yucbe72b02015-11-25 17:35:37 -0800110};
111
112} // namespace detail
113} // namespace pib
114} // namespace security
115} // namespace ndn
116
Davide Pesavento09904412021-03-24 16:40:53 -0400117#endif // NDN_CXX_SECURITY_PIB_IMPL_IDENTITY_IMPL_HPP