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-2022 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 <iterator>
28 #include <set>
29 #include <unordered_map>
30 
31 namespace ndn {
32 namespace security {
33 namespace pib {
34 
35 class PibImpl;
36 
37 namespace detail {
38 class KeyImpl;
39 } // namespace detail
40 
49 class CertificateContainer : noncopyable
50 {
51 private:
52  using NameSet = std::set<Name>;
53 
54 public:
56  {
57  public:
58  using iterator_category = std::forward_iterator_tag;
59  using value_type = const Certificate;
60  using difference_type = std::ptrdiff_t;
61  using pointer = value_type*;
63 
64  const_iterator() = default;
65 
67  operator*();
68 
71  {
72  ++m_it;
73  return *this;
74  }
75 
78  {
79  const_iterator it(*this);
80  ++m_it;
81  return it;
82  }
83 
84  bool
85  operator==(const const_iterator& other) const;
86 
87  bool
88  operator!=(const const_iterator& other) const
89  {
90  return !this->operator==(other);
91  }
92 
93  private:
94  const_iterator(NameSet::const_iterator it, const CertificateContainer& container) noexcept;
95 
96  private:
97  NameSet::const_iterator m_it;
98  const CertificateContainer* m_container = nullptr;
99 
100  friend CertificateContainer;
101  };
102 
104 
105 public:
107  begin() const noexcept
108  {
109  return {m_certNames.begin(), *this};
110  }
111 
112  const_iterator
113  end() const noexcept
114  {
115  return {};
116  }
117 
118  const_iterator
119  find(const Name& certName) const;
120 
124  NDN_CXX_NODISCARD bool
125  empty() const noexcept
126  {
127  return m_certNames.empty();
128  }
129 
133  size_t
134  size() const noexcept
135  {
136  return m_certNames.size();
137  }
138 
143  void
144  add(const Certificate& certificate);
145 
150  void
151  remove(const Name& certName);
152 
159  get(const Name& certName) const;
160 
165  bool
166  isConsistent() const;
167 
168 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // private interface for KeyImpl
173  CertificateContainer(const Name& keyName, shared_ptr<PibImpl> pibImpl);
174 
176  // cache of loaded certificates
177  mutable std::unordered_map<Name, Certificate> m_certs;
178 
179 private:
180  NameSet m_certNames;
181  const Name m_keyName;
182  const shared_ptr<PibImpl> m_pib;
183 
184  friend detail::KeyImpl;
185 };
186 
187 } // namespace pib
188 } // namespace security
189 } // namespace ndn
190 
191 #endif // NDN_CXX_SECURITY_PIB_CERTIFICATE_CONTAINER_HPP
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
Represents an absolute name.
Definition: name.hpp:44
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.
Represents an NDN certificate.
Definition: certificate.hpp:60
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
Definition: data.cpp:25