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; -*- */
23 #include "pib-impl.hpp"
24 #include "util/concepts.hpp"
25 
26 namespace ndn {
27 namespace security {
28 namespace pib {
29 
31 
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 
46 {
47  BOOST_ASSERT(m_container != nullptr);
48  return m_container->get(*m_it);
49 }
50 
53 {
54  ++m_it;
55  return *this;
56 }
57 
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
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
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 
93 {
94  return const_iterator(m_certNames.begin(), *this);
95 }
96 
99 {
100  return const_iterator();
101 }
102 
104 CertificateContainer::find(const Name& certName) const
105 {
106  return const_iterator(m_certNames.find(certName), *this);
107 }
108 
109 size_t
111 {
112  return m_certNames.size();
113 }
114 
115 void
117 {
118  if (m_keyName != certificate.getKeyName())
119  BOOST_THROW_EXCEPTION(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
130 {
131  if (!v2::Certificate::isValidName(certName) ||
132  v2::extractKeyNameFromCertName(certName) != m_keyName) {
133  BOOST_THROW_EXCEPTION(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 
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  BOOST_THROW_EXCEPTION(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
162 {
163  return m_certNames == m_pib->getCertificatesOfKey(m_keyName);
164 }
165 
166 } // namespace pib
167 } // namespace security
168 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
std::string toUri() const
Get URI representation of the name.
Definition: name.cpp:122
The certificate following the certificate format naming convention.
Definition: certificate.hpp:81
void remove(const Name &certName)
Remove a certificate with certName from the container.
const Name & getName() const
Get name.
Definition: data.hpp:121
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE shared_ptr< PibImpl > pibImpl
Name extractKeyNameFromCertName(const Name &certName)
Extract key name from the certificate name certName.
bool isConsistent() const
Check if the container is consistent with the backend storage.
STL namespace.
v2::Certificate get(const Name &certName) const
Get a certificate with certName from the container.
NDN_CXX_ASSERT_FORWARD_ITERATOR(CertificateContainer::const_iterator)
Container of certificates of a key.
Name getKeyName() const
Get key name.
Definition: certificate.cpp:81
Represents an absolute name.
Definition: name.hpp:42
void add(const v2::Certificate &certificate)
Add certificate into the container.
static bool isValidName(const Name &certName)
Check if the specified name follows the naming convention for the certificate.
const_iterator find(const Name &certName) const