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-2021 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 
47 class CertificateContainer : noncopyable
48 {
49 public:
51  {
52  public:
53  using iterator_category = std::forward_iterator_tag;
54  using value_type = const Certificate;
55  using difference_type = std::ptrdiff_t;
56  using pointer = value_type*;
58 
60 
62  operator*();
63 
65  operator++();
66 
68  operator++(int);
69 
70  bool
71  operator==(const const_iterator& other) const;
72 
73  bool
74  operator!=(const const_iterator& other) const;
75 
76  private:
77  const_iterator(std::set<Name>::const_iterator it, const CertificateContainer& container);
78 
79  private:
80  std::set<Name>::const_iterator m_it;
81  const CertificateContainer* m_container;
82 
83  friend class CertificateContainer;
84  };
85 
87 
88 public:
90  begin() const;
91 
93  end() const;
94 
96  find(const Name& certName) const;
97 
98  size_t
99  size() const;
100 
105  void
106  add(const Certificate& certificate);
107 
112  void
113  remove(const Name& certName);
114 
121  get(const Name& certName) const;
122 
127  bool
128  isConsistent() const;
129 
135  CertificateContainer(const Name& keyName, shared_ptr<PibImpl> pibImpl);
136 
137  const std::set<Name>&
138  getCertNames() const
139  {
140  return m_certNames;
141  }
142 
143  const std::unordered_map<Name, Certificate>&
144  getCache() const
145  {
146  return m_certs;
147  }
148 
149 private:
150  Name m_keyName;
151  std::set<Name> m_certNames;
153  mutable std::unordered_map<Name, Certificate> m_certs;
154 
155  shared_ptr<PibImpl> m_pib;
156 
157 #ifndef DOXYGEN
158  friend detail::KeyImpl;
159 #endif
160 };
161 
162 } // namespace pib
163 
164 using pib::CertificateContainer;
165 
166 } // namespace security
167 } // namespace ndn
168 
169 #endif // NDN_CXX_SECURITY_PIB_CERTIFICATE_CONTAINER_HPP
Represents an absolute name.
Definition: name.hpp:46
Container of certificates of a key.
const_iterator find(const Name &certName) const
Certificate get(const Name &certName) const
Get a certificate with certName from the container.
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.
Represents an NDN certificate following the version 2.0 format.
Definition: certificate.hpp:61
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
Definition: data.cpp:25