NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2
/*
3
* Copyright (c) 2013-2019 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
22
#include "
ndn-cxx/security/pib/pib.hpp
"
23
#include "
ndn-cxx/security/pib/pib-impl.hpp
"
24
#include "
ndn-cxx/util/logger.hpp
"
25
26
namespace
ndn
{
27
namespace
security {
28
namespace
pib {
29
30
NDN_LOG_INIT
(
ndn
.
security
.
pib
.
Pib
);
31
32
Pib::Pib
(
const
std::string& scheme,
const
std::string& location, shared_ptr<PibImpl> impl)
33
: m_scheme(scheme)
34
, m_location(location)
35
, m_isDefaultIdentityLoaded(false)
36
, m_identities(impl)
37
, m_impl(std::
move
(impl))
38
{
39
BOOST_ASSERT(m_impl !=
nullptr
);
40
}
41
42
Pib::~Pib
() =
default
;
43
44
std::string
45
Pib::getPibLocator
()
const
46
{
47
return
m_scheme
+
":"
+
m_location
;
48
}
49
50
void
51
Pib::setTpmLocator
(
const
std::string& tpmLocator)
52
{
53
if
(tpmLocator ==
m_impl
->getTpmLocator()) {
54
return
;
55
}
56
reset
();
57
m_impl
->setTpmLocator(tpmLocator);
58
}
59
60
std::string
61
Pib::getTpmLocator
()
const
62
{
63
std::string tpmLocator =
m_impl
->getTpmLocator();
64
if
(tpmLocator.empty()) {
65
NDN_THROW
(
Pib::Error
(
"TPM info does not exist"
));
66
}
67
return
tpmLocator;
68
}
69
70
void
71
Pib::reset
()
72
{
73
m_impl
->clearIdentities();
74
m_impl
->setTpmLocator(
""
);
75
m_isDefaultIdentityLoaded
=
false
;
76
m_identities
.
reset
();
77
}
78
79
Identity
80
Pib::addIdentity
(
const
Name
& identity)
81
{
82
BOOST_ASSERT(
m_identities
.
isConsistent
());
83
84
return
m_identities
.
add
(identity);
85
}
86
87
void
88
Pib::removeIdentity
(
const
Name
& identity)
89
{
90
BOOST_ASSERT(
m_identities
.
isConsistent
());
91
92
if
(
m_isDefaultIdentityLoaded
&&
m_defaultIdentity
.
getName
() == identity) {
93
m_isDefaultIdentityLoaded
=
false
;
94
}
95
96
m_identities
.
remove
(identity);
97
}
98
99
Identity
100
Pib::getIdentity
(
const
Name
& identity)
const
101
{
102
BOOST_ASSERT(
m_identities
.
isConsistent
());
103
104
return
m_identities
.
get
(identity);
105
}
106
107
const
IdentityContainer
&
108
Pib::getIdentities
()
const
109
{
110
BOOST_ASSERT(
m_identities
.
isConsistent
());
111
112
return
m_identities
;
113
}
114
115
const
Identity
&
116
Pib::setDefaultIdentity
(
const
Name
& identityName)
117
{
118
BOOST_ASSERT(
m_identities
.
isConsistent
());
119
120
m_defaultIdentity
=
m_identities
.
add
(identityName);
121
m_isDefaultIdentityLoaded
=
true
;
122
NDN_LOG_DEBUG
(
"Default identity is set to "
<< identityName);
123
124
m_impl
->setDefaultIdentity(identityName);
125
return
m_defaultIdentity
;
126
}
127
128
const
Identity
&
129
Pib::getDefaultIdentity
()
const
130
{
131
BOOST_ASSERT(
m_identities
.
isConsistent
());
132
133
if
(!
m_isDefaultIdentityLoaded
) {
134
m_defaultIdentity
=
m_identities
.
get
(
m_impl
->getDefaultIdentity());
135
m_isDefaultIdentityLoaded
=
true
;
136
NDN_LOG_DEBUG
(
"Default identity is "
<<
m_defaultIdentity
.
getName
());
137
}
138
139
BOOST_ASSERT(
m_impl
->getDefaultIdentity() ==
m_defaultIdentity
.
getName
());
140
141
return
m_defaultIdentity
;
142
}
143
144
}
// namespace pib
145
}
// namespace security
146
}
// namespace ndn
ndn::security::pib::Pib::m_impl
shared_ptr< PibImpl > m_impl
Definition:
pib.hpp:175
ndn::security::pib::Pib::getDefaultIdentity
const Identity & getDefaultIdentity() const
Get the default identity.
Definition:
pib.cpp:129
NDN_LOG_INIT
#define NDN_LOG_INIT(name)
declare a log module
Definition:
logger.hpp:81
ndn::security::pib::IdentityContainer::remove
void remove(const Name &identity)
Remove identity from the container.
Definition:
identity-container.cpp:125
nonstd::optional_lite::std11::move
T & move(T &t)
Definition:
optional.hpp:421
ndn::security::pib::Pib::setDefaultIdentity
const Identity & setDefaultIdentity(const Name &identity)
Set an identity as the default identity.
Definition:
pib.cpp:116
ndn::security::pib::IdentityContainer::get
Identity get(const Name &identity) const
Get identity from the container.
Definition:
identity-container.cpp:133
ndn::security::pib::Pib::getIdentities
const IdentityContainer & getIdentities() const
Get all the identities.
Definition:
pib.cpp:108
ndn::security::pib::Pib
ndn security pib Pib
Definition:
pib.cpp:30
ndn::security::pib::Pib::m_location
std::string m_location
Definition:
pib.hpp:168
ndn::security::pib::Pib::getPibLocator
std::string getPibLocator() const
Get PIB Locator.
Definition:
pib.cpp:45
ndn::security::pib::Pib
represents the PIB
Definition:
pib.hpp:53
ndn::security::pib::Identity::getName
const Name & getName() const
Get the name of the identity.
Definition:
identity.cpp:37
ndn::security::pib::Pib::m_defaultIdentity
Identity m_defaultIdentity
Definition:
pib.hpp:171
ndn::security::pib::Pib::addIdentity
Identity addIdentity(const Name &identity)
Add an identity.
Definition:
pib.cpp:80
ndn::security::pib::Pib::setTpmLocator
void setTpmLocator(const std::string &tpmLocator)
Set the corresponding TPM information to tpmLocator.
Definition:
pib.cpp:51
ndn::Name
Represents an absolute name.
Definition:
name.hpp:44
ndn::security::pib::Pib::removeIdentity
void removeIdentity(const Name &identity)
Remove an identity.
Definition:
pib.cpp:88
ndn::security::pib::Pib::~Pib
~Pib()
ndn::security::pib
Definition:
certificate-container.cpp:28
ndn::security::pib::IdentityContainer::reset
void reset()
Reset state of the container.
Definition:
identity-container.cpp:149
ndn::security::pib::IdentityContainer::add
Identity add(const Name &identityName)
Add identity into the container.
Definition:
identity-container.cpp:115
ndn::security::pib::Pib::m_identities
IdentityContainer m_identities
Definition:
pib.hpp:173
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
ndn::security::pib::Pib::Error
represents a semantic error
Definition:
pib.hpp:57
ndn::security::pib::Pib::getTpmLocator
std::string getTpmLocator() const
Get TPM Locator.
Definition:
pib.cpp:61
ndn::security::pib::Pib::m_scheme
std::string m_scheme
Definition:
pib.hpp:167
logger.hpp
pib.hpp
NDN_LOG_DEBUG
#define NDN_LOG_DEBUG(expression)
Definition:
logger.hpp:99
ndn::security
Definition:
dummy-keychain.cpp:28
ndn::security::pib::IdentityContainer
Container of identities of a Pib.
Definition:
identity-container.hpp:48
ndn::security::pib::Pib::m_isDefaultIdentityLoaded
bool m_isDefaultIdentityLoaded
Definition:
pib.hpp:170
ndn::security::pib::Identity
A frontend handle of an Identity.
Definition:
identity.hpp:43
ndn::security::pib::Pib::reset
void reset()
Reset content in PIB, including reset of the TPM locator.
Definition:
pib.cpp:71
ndn::security::pib::Pib::getIdentity
Identity getIdentity(const Name &identityName) const
Get an identity with name identityName.
Definition:
pib.cpp:100
ndn::security::pib::IdentityContainer::isConsistent
bool isConsistent() const
Check if the container is consistent with the backend storage.
Definition:
identity-container.cpp:156
pib-impl.hpp
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndnSIM
ndn-cxx
ndn-cxx
security
pib
pib.cpp
Generated on Mon Jun 1 2020 22:32:15 for ndnSIM by
1.8.18