NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
pib.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "pib.hpp"
23 #include "pib-impl.hpp"
24 
25 namespace ndn {
26 namespace security {
27 
28 Pib::Pib(const std::string scheme, const std::string& location, shared_ptr<PibImpl> impl)
29  : m_scheme(scheme)
30  , m_location(location)
31  , m_hasDefaultIdentity(false)
32  , m_needRefreshIdentities(true)
33  , m_impl(impl)
34 {
35 }
36 
38 {
39 }
40 
41 std::string
43 {
44  return m_scheme + ":" + m_location;
45 }
46 
47 void
48 Pib::setTpmLocator(const std::string& tpmLocator)
49 {
50  m_impl->setTpmLocator(tpmLocator);
51 }
52 
53 std::string
55 {
56  return m_impl->getTpmLocator();
57 }
58 
60 Pib::addIdentity(const Name& identity)
61 {
62  if (!m_needRefreshIdentities && m_identities.find(identity) == m_identities.end()) {
63  // if we have already loaded all the identities, but the new identity is not one of them
64  // the IdentityContainer should be refreshed
65  m_needRefreshIdentities = true;
66  }
67  return Identity(identity, m_impl, true);
68 }
69 
70 void
71 Pib::removeIdentity(const Name& identity)
72 {
73  if (m_hasDefaultIdentity && m_defaultIdentity.getName() == identity)
74  m_hasDefaultIdentity = false;
75 
76  m_impl->removeIdentity(identity);
77  m_needRefreshIdentities = true;
78 }
79 
81 Pib::getIdentity(const Name& identity) const
82 {
83  return Identity(identity, m_impl, false);
84 }
85 
86 const IdentityContainer&
88 {
89  if (m_needRefreshIdentities) {
90  m_identities = std::move(IdentityContainer(m_impl->getIdentities(), m_impl));
91  m_needRefreshIdentities = false;
92  }
93 
94  return m_identities;
95 }
96 
97 Identity&
98 Pib::setDefaultIdentity(const Name& identityName)
99 {
100  m_defaultIdentity = addIdentity(identityName);
101  m_hasDefaultIdentity = true;
102 
103  m_impl->setDefaultIdentity(identityName);
104  return m_defaultIdentity;
105 }
106 
107 Identity&
109 {
110  if (!m_hasDefaultIdentity) {
111  m_defaultIdentity = std::move(Identity(m_impl->getDefaultIdentity(), m_impl, false));
112  m_hasDefaultIdentity = true;
113  }
114 
115  return m_defaultIdentity;
116 }
117 
118 
119 } // namespace security
120 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
represents an identity
Definition: identity.hpp:44
virtual void addIdentity(const Name &identity) final
Add an identity.
Identity getIdentity(const Name &identityName) const
Get an identity with name identityName.
Definition: pib.cpp:81
void setTpmLocator(const std::string &tpmLocator)
Set the corresponding TPM information to tpmLocator.
Definition: pib.cpp:48
A handler to search or enumerate identities in PIB.
std::string getPibLocator() const
Get PIB Locator.
Definition: pib.cpp:42
void removeIdentity(const Name &identityName)
Definition: pib.cpp:71
Identity & setDefaultIdentity(const Name &identityName)
Set an identity with name identityName as the default identity.
Definition: pib.cpp:98
const IdentityContainer & getIdentities() const
Get all the identities.
Definition: pib.cpp:87
Identity & getDefaultIdentity() const
Get the default identity.
Definition: pib.cpp:108
Name abstraction to represent an absolute name.
Definition: name.hpp:46
std::string getTpmLocator() const
Get TPM Locator.
Definition: pib.cpp:54