NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
key-container.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/key-container.hpp
"
23
#include "
ndn-cxx/security/pib/pib-impl.hpp
"
24
#include "
ndn-cxx/security/pib/impl/key-impl.hpp
"
25
#include "
ndn-cxx/util/concepts.hpp
"
26
27
namespace
ndn
{
28
namespace
security {
29
namespace
pib {
30
31
NDN_CXX_ASSERT_FORWARD_ITERATOR
(
KeyContainer::const_iterator
);
32
33
KeyContainer::const_iterator::const_iterator
()
34
: m_container(nullptr)
35
{
36
}
37
38
KeyContainer::const_iterator::const_iterator
(std::set<Name>::const_iterator it,
39
const
KeyContainer
& container)
40
: m_it(it)
41
, m_container(&container)
42
{
43
}
44
45
Key
46
KeyContainer::const_iterator::operator*
()
47
{
48
BOOST_ASSERT(m_container !=
nullptr
);
49
return
m_container->get(*m_it);
50
}
51
52
KeyContainer::const_iterator
&
53
KeyContainer::const_iterator::operator++
()
54
{
55
++m_it;
56
return
*
this
;
57
}
58
59
KeyContainer::const_iterator
60
KeyContainer::const_iterator::operator++
(
int
)
61
{
62
const_iterator
it(*
this
);
63
++m_it;
64
return
it;
65
}
66
67
bool
68
KeyContainer::const_iterator::operator==
(
const
const_iterator
& other)
69
{
70
bool
isThisEnd = m_container ==
nullptr
|| m_it == m_container->m_keyNames.end();
71
bool
isOtherEnd = other.m_container ==
nullptr
|| other.m_it == other.m_container->m_keyNames.end();
72
return
((isThisEnd || isOtherEnd) ?
73
(isThisEnd == isOtherEnd) :
74
m_container->m_pib == other.m_container->m_pib && m_it == other.m_it);
75
}
76
77
bool
78
KeyContainer::const_iterator::operator!=
(
const
const_iterator
& other)
79
{
80
return
!(*
this
== other);
81
}
82
83
KeyContainer::KeyContainer(
const
Name
& identity, shared_ptr<PibImpl>
pibImpl
)
84
: m_identity(identity)
85
, m_pib(std::
move
(
pibImpl
))
86
{
87
BOOST_ASSERT(m_pib !=
nullptr
);
88
m_keyNames = m_pib->getKeysOfIdentity(identity);
89
}
90
91
KeyContainer::const_iterator
92
KeyContainer::begin
()
const
93
{
94
return
const_iterator
(m_keyNames.begin(), *
this
);
95
}
96
97
KeyContainer::const_iterator
98
KeyContainer::end
()
const
99
{
100
return
const_iterator
();
101
}
102
103
KeyContainer::const_iterator
104
KeyContainer::find
(
const
Name
& keyName)
const
105
{
106
return
const_iterator
(m_keyNames.find(keyName), *
this
);
107
}
108
109
size_t
110
KeyContainer::size
()
const
111
{
112
return
m_keyNames.size();
113
}
114
115
Key
116
KeyContainer::add
(
const
uint8_t* key,
size_t
keyLen,
const
Name
& keyName)
117
{
118
if
(m_identity !=
v2::extractIdentityFromKeyName
(keyName)) {
119
NDN_THROW
(std::invalid_argument(
"Key name `"
+ keyName.
toUri
() +
"` does not match identity "
120
"`"
+ m_identity.
toUri
() +
"`"
));
121
}
122
123
m_keyNames.insert(keyName);
124
m_keys[keyName] = make_shared<detail::KeyImpl>(keyName, key, keyLen, m_pib);
125
126
return
get
(keyName);
127
}
128
129
void
130
KeyContainer::remove
(
const
Name
& keyName)
131
{
132
if
(m_identity !=
v2::extractIdentityFromKeyName
(keyName)) {
133
NDN_THROW
(std::invalid_argument(
"Key name `"
+ keyName.
toUri
() +
"` does not match identity "
134
"`"
+ m_identity.
toUri
() +
"`"
));
135
}
136
137
m_keyNames.erase(keyName);
138
m_keys.erase(keyName);
139
m_pib->removeKey(keyName);
140
}
141
142
Key
143
KeyContainer::get
(
const
Name
& keyName)
const
144
{
145
if
(m_identity !=
v2::extractIdentityFromKeyName
(keyName)) {
146
NDN_THROW
(std::invalid_argument(
"Key name `"
+ keyName.
toUri
() +
"` does not match identity "
147
"`"
+ m_identity.
toUri
() +
"`"
));
148
}
149
150
shared_ptr<detail::KeyImpl> key;
151
auto
it = m_keys.find(keyName);
152
153
if
(it != m_keys.end()) {
154
key = it->second;
155
}
156
else
{
157
key = make_shared<detail::KeyImpl>(keyName, m_pib);
158
m_keys[keyName] = key;
159
}
160
161
return
Key
(key);
162
}
163
164
bool
165
KeyContainer::isConsistent
()
const
166
{
167
return
m_keyNames == m_pib->getKeysOfIdentity(m_identity);
168
}
169
170
}
// namespace pib
171
}
// namespace security
172
}
// namespace ndn
ndn::security::pib::KeyContainer::const_iterator::operator*
Key operator*()
Definition:
key-container.cpp:46
ndn::security::pib::KeyContainer::add
Key add(const uint8_t *key, size_t keyLen, const Name &keyName)
Add key of keyLen bytes with keyName into the container.
Definition:
key-container.cpp:116
nonstd::optional_lite::std11::move
T & move(T &t)
Definition:
optional.hpp:421
ndn::security::pib::KeyContainer::const_iterator::operator++
const_iterator & operator++()
Definition:
key-container.cpp:53
ndn::security::v2::extractIdentityFromKeyName
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
Definition:
key.cpp:160
concepts.hpp
key-container.hpp
ndn::Name
Represents an absolute name.
Definition:
name.hpp:44
ndn::security::pib::KeyContainer::isConsistent
bool isConsistent() const
Check if the container is consistent with the backend storage.
Definition:
key-container.cpp:165
ndn::security::pib::KeyContainer::remove
void remove(const Name &keyName)
Remove a key with keyName from the container.
Definition:
key-container.cpp:130
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
ndn::security::pib::KeyContainer::size
size_t size() const
Definition:
key-container.cpp:110
ndn::security::pib::KeyContainer::const_iterator::operator!=
bool operator!=(const const_iterator &other)
Definition:
key-container.cpp:78
ndn::security::pib::KeyContainer::find
const_iterator find(const Name &keyName) const
Definition:
key-container.cpp:104
ndn::Name::toUri
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
Definition:
name.cpp:348
key-impl.hpp
ndn::security::pib::KeyContainer::end
const_iterator end() const
Definition:
key-container.cpp:98
ndn::security::pib::KeyContainer::const_iterator
Definition:
key-container.hpp:52
ndn::security::pib::Key
A frontend handle of a key instance.
Definition:
key.hpp:50
ndn::security::pib::KeyContainer::const_iterator::const_iterator
const_iterator()
Definition:
key-container.cpp:33
ndn::security::pib::KeyContainer
Container of keys of an identity.
Definition:
key-container.hpp:49
pib-impl.hpp
ndn::security::pib::KeyContainer::begin
const_iterator begin() const
Definition:
key-container.cpp:92
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::security::pib::KeyContainer::get
Key get(const Name &keyName) const
Get a key with keyName from the container.
Definition:
key-container.cpp:143
ndn::security::pib::KeyContainer::pibImpl
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE shared_ptr< PibImpl > pibImpl
Definition:
key-container.hpp:139
ndn::security::pib::NDN_CXX_ASSERT_FORWARD_ITERATOR
NDN_CXX_ASSERT_FORWARD_ITERATOR(CertificateContainer::const_iterator)
ndn::security::pib::KeyContainer::const_iterator::operator==
bool operator==(const const_iterator &other)
Definition:
key-container.cpp:68
ndnSIM
ndn-cxx
ndn-cxx
security
pib
key-container.cpp
Generated on Mon Jun 1 2020 22:32:15 for ndnSIM by
1.8.18