pib.cpp
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 
24 #include "ndn-cxx/util/logger.hpp"
25 
26 namespace ndn::security::pib {
27 
29 
30 Pib::Pib(const std::string& locator, shared_ptr<PibImpl> impl)
31  : m_locator(locator)
32  , m_impl(std::move(impl))
33  , m_identities(m_impl)
34 {
35  BOOST_ASSERT(m_impl != nullptr);
36 }
37 
38 Pib::~Pib() = default;
39 
40 std::string
41 Pib::getTpmLocator() const
42 {
43  return m_impl->getTpmLocator();
44 }
45 
46 void
47 Pib::setTpmLocator(const std::string& tpmLocator)
48 {
49  if (tpmLocator == m_impl->getTpmLocator()) {
50  return;
51  }
52 
53  NDN_LOG_DEBUG("Resetting TPM locator to " << tpmLocator);
54  reset();
55  m_impl->setTpmLocator(tpmLocator);
56 }
57 
58 void
59 Pib::reset()
60 {
61  m_impl->setTpmLocator("");
62  m_impl->clearIdentities();
63  m_defaultIdentity = {};
64  m_identities.reset();
65 }
66 
68 Pib::addIdentity(const Name& identityName)
69 {
70  BOOST_ASSERT(m_identities.isConsistent());
71  return m_identities.add(identityName);
72 }
73 
74 void
75 Pib::removeIdentity(const Name& identityName)
76 {
77  BOOST_ASSERT(m_identities.isConsistent());
78 
79  if (m_defaultIdentity && m_defaultIdentity.getName() == identityName) {
80  NDN_LOG_DEBUG("Removing default identity " << identityName);
81  m_defaultIdentity = {};
82  }
83  m_identities.remove(identityName);
84 }
85 
86 Identity
87 Pib::getIdentity(const Name& identity) const
88 {
89  BOOST_ASSERT(m_identities.isConsistent());
90  return m_identities.get(identity);
91 }
92 
93 const IdentityContainer&
94 Pib::getIdentities() const
95 {
96  BOOST_ASSERT(m_identities.isConsistent());
97  return m_identities;
98 }
99 
100 Identity
101 Pib::setDefaultIdentity(const Name& identityName)
102 {
103  BOOST_ASSERT(m_identities.isConsistent());
104 
105  m_defaultIdentity = m_identities.add(identityName);
106  m_impl->setDefaultIdentity(identityName);
107  NDN_LOG_DEBUG("Default identity set to " << identityName);
108 
109  BOOST_ASSERT(m_defaultIdentity);
110  return m_defaultIdentity;
111 }
112 
113 Identity
114 Pib::getDefaultIdentity() const
115 {
116  BOOST_ASSERT(m_identities.isConsistent());
117 
118  if (!m_defaultIdentity) {
119  m_defaultIdentity = m_identities.get(m_impl->getDefaultIdentity());
120  NDN_LOG_DEBUG("Caching default identity " << m_defaultIdentity.getName());
121  }
122 
123  BOOST_ASSERT(m_defaultIdentity);
124  BOOST_ASSERT(m_defaultIdentity.getName() == m_impl->getDefaultIdentity());
125  return m_defaultIdentity;
126 }
127 
128 } // namespace ndn::security::pib
Represents an absolute name.
Definition: name.hpp:45
Container of identities of a PIB.
Frontend handle for an identity in the PIB.
Definition: identity.hpp:44
#define NDN_LOG_DEBUG(expression)
Log at DEBUG level.
Definition: logger.hpp:260
#define NDN_LOG_INIT(name)
Define a non-member log module.
Definition: logger.hpp:169
Contains the ndn-cxx security framework.
Definition: data.cpp:25