ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
certificate-container.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2023 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#ifndef NDN_CXX_SECURITY_PIB_CERTIFICATE_CONTAINER_HPP
23#define NDN_CXX_SECURITY_PIB_CERTIFICATE_CONTAINER_HPP
24
26
27#include <set>
28#include <unordered_map>
29
30namespace ndn::security::pib {
31
32class PibImpl;
33
42class CertificateContainer : noncopyable
43{
44private:
45 using NameSet = std::set<Name>;
46
47public:
48 class const_iterator : public boost::forward_iterator_helper<const_iterator, const Certificate>
49 {
50 public:
51 const_iterator() = default;
52
54 operator*() const
55 {
56 BOOST_ASSERT(m_container != nullptr);
57 return m_container->get(*m_it);
58 }
59
62 {
63 ++m_it;
64 return *this;
65 }
66
67 friend bool
68 operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
69 {
70 return lhs.equals(rhs);
71 }
72
73 private:
74 const_iterator(NameSet::const_iterator it, const CertificateContainer& container) noexcept
75 : m_it(it)
76 , m_container(&container)
77 {
78 }
79
80 bool
81 equals(const const_iterator& other) const noexcept;
82
83 private:
84 NameSet::const_iterator m_it;
85 const CertificateContainer* m_container = nullptr;
86
88 };
89
91
92public:
94 begin() const noexcept
95 {
96 return {m_certNames.begin(), *this};
97 }
98
99 const_iterator
100 end() const noexcept
101 {
102 return {};
103 }
104
105 const_iterator
106 find(const Name& certName) const;
107
111 [[nodiscard]] bool
112 empty() const noexcept
113 {
114 return m_certNames.empty();
115 }
116
120 size_t
121 size() const noexcept
122 {
123 return m_certNames.size();
124 }
125
130 void
131 add(const Certificate& certificate);
132
137 void
138 remove(const Name& certName);
139
146 get(const Name& certName) const;
147
152 bool
153 isConsistent() const;
154
155NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // private interface for KeyImpl
160 CertificateContainer(const Name& keyName, shared_ptr<PibImpl> pibImpl);
161
163 // cache of loaded certificates
164 mutable std::unordered_map<Name, Certificate> m_certs;
165
166private:
167 NameSet m_certNames;
168 const Name m_keyName;
169 const shared_ptr<PibImpl> m_pib;
170
171 friend class KeyImpl;
172};
173
174} // namespace ndn::security::pib
175
176#endif // NDN_CXX_SECURITY_PIB_CERTIFICATE_CONTAINER_HPP
Represents an absolute name.
Definition name.hpp:45
Represents an NDN certificate.
friend bool operator==(const const_iterator &lhs, const const_iterator &rhs) noexcept
Container of certificates of a key.
const_iterator find(const Name &certName) const
bool empty() const noexcept
Check whether the container is empty.
Certificate get(const Name &certName) const
Return a certificate by name.
void remove(const Name &certName)
Remove a certificate with certName from the container.
bool isConsistent() const
Check if the container is consistent with the backend storage.
void add(const Certificate &certificate)
Add certificate into the container.
size_t size() const noexcept
Return the number of certificates in the container.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition common.hpp:49