Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [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 | |
| 22 | #include "pib.hpp" |
| 23 | #include "pib-impl.hpp" |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace security { |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame^] | 27 | namespace pib { |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 28 | |
| 29 | Pib::Pib(const std::string scheme, const std::string& location, shared_ptr<PibImpl> impl) |
| 30 | : m_scheme(scheme) |
| 31 | , m_location(location) |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 32 | , m_hasDefaultIdentity(false) |
| 33 | , m_needRefreshIdentities(true) |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 34 | , m_impl(impl) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | Pib::~Pib() |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | std::string |
| 43 | Pib::getPibLocator() const |
| 44 | { |
| 45 | return m_scheme + ":" + m_location; |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | Pib::setTpmLocator(const std::string& tpmLocator) |
| 50 | { |
| 51 | m_impl->setTpmLocator(tpmLocator); |
| 52 | } |
| 53 | |
| 54 | std::string |
| 55 | Pib::getTpmLocator() const |
| 56 | { |
| 57 | return m_impl->getTpmLocator(); |
| 58 | } |
| 59 | |
| 60 | Identity |
| 61 | Pib::addIdentity(const Name& identity) |
| 62 | { |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 63 | if (!m_needRefreshIdentities && m_identities.find(identity) == m_identities.end()) { |
| 64 | // if we have already loaded all the identities, but the new identity is not one of them |
| 65 | // the IdentityContainer should be refreshed |
| 66 | m_needRefreshIdentities = true; |
| 67 | } |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 68 | return Identity(identity, m_impl, true); |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | Pib::removeIdentity(const Name& identity) |
| 73 | { |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 74 | if (m_hasDefaultIdentity && m_defaultIdentity.getName() == identity) |
| 75 | m_hasDefaultIdentity = false; |
| 76 | |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 77 | m_impl->removeIdentity(identity); |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 78 | m_needRefreshIdentities = true; |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | Identity |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 82 | Pib::getIdentity(const Name& identity) const |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 83 | { |
| 84 | return Identity(identity, m_impl, false); |
| 85 | } |
| 86 | |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 87 | const IdentityContainer& |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 88 | Pib::getIdentities() const |
| 89 | { |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 90 | if (m_needRefreshIdentities) { |
Alexander Afanasyev | 66ca203 | 2015-12-04 13:17:02 -0800 | [diff] [blame] | 91 | m_identities = IdentityContainer(m_impl->getIdentities(), m_impl); |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 92 | m_needRefreshIdentities = false; |
| 93 | } |
| 94 | |
| 95 | return m_identities; |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 98 | Identity& |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 99 | Pib::setDefaultIdentity(const Name& identityName) |
| 100 | { |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 101 | m_defaultIdentity = addIdentity(identityName); |
| 102 | m_hasDefaultIdentity = true; |
| 103 | |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 104 | m_impl->setDefaultIdentity(identityName); |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 105 | return m_defaultIdentity; |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 108 | Identity& |
| 109 | Pib::getDefaultIdentity() const |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 110 | { |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 111 | if (!m_hasDefaultIdentity) { |
Alexander Afanasyev | 66ca203 | 2015-12-04 13:17:02 -0800 | [diff] [blame] | 112 | m_defaultIdentity = Identity(m_impl->getDefaultIdentity(), m_impl, false); |
Yingdi Yu | c820989 | 2015-06-19 17:47:56 -0700 | [diff] [blame] | 113 | m_hasDefaultIdentity = true; |
| 114 | } |
| 115 | |
| 116 | return m_defaultIdentity; |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame^] | 119 | } // namespace pib |
Yingdi Yu | b8f8b34 | 2015-04-27 11:06:42 -0700 | [diff] [blame] | 120 | } // namespace security |
| 121 | } // namespace ndn |