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