trust-anchor-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-2024 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_TRUST_ANCHOR_CONTAINER_HPP
23 #define NDN_CXX_SECURITY_TRUST_ANCHOR_CONTAINER_HPP
24 
25 #include "ndn-cxx/interest.hpp"
28 
29 #include <boost/multi_index_container.hpp>
30 #include <boost/multi_index/hashed_index.hpp>
31 #include <boost/multi_index/ordered_index.hpp>
32 #include <boost/multi_index/mem_fun.hpp>
33 
34 namespace ndn::security {
35 
53 class TrustAnchorContainer : noncopyable
54 {
55 public:
56  class Error : public std::runtime_error
57  {
58  public:
59  using std::runtime_error::runtime_error;
60  };
61 
73  void
74  insert(const std::string& groupId, Certificate&& cert);
75 
88  void
89  insert(const std::string& groupId, const std::filesystem::path& path,
90  time::nanoseconds refreshPeriod, bool isDir = false);
91 
95  void
96  clear();
97 
105  const Certificate*
106  find(const Name& keyName) const;
107 
116  const Certificate*
117  find(const Interest& interest) const;
118 
124  getGroup(const std::string& groupId) const;
125 
129  size_t
130  size() const;
131 
132 private:
133  void
134  refresh();
135 
136 private:
137  using AnchorContainerBase = boost::multi_index::multi_index_container<
138  Certificate,
139  boost::multi_index::indexed_by<
140  boost::multi_index::ordered_unique<
141  boost::multi_index::const_mem_fun<Data, const Name&, &Data::getName>
142  >
143  >
144  >;
145 
146  class AnchorContainer : public CertContainerInterface,
147  public AnchorContainerBase
148  {
149  public:
150  void
151  add(Certificate&& cert) final;
152 
153  void
154  remove(const Name& certName) final;
155 
156  void
157  clear();
158  };
159 
160  using GroupContainer = boost::multi_index::multi_index_container<
161  shared_ptr<TrustAnchorGroup>,
162  boost::multi_index::indexed_by<
163  boost::multi_index::hashed_unique<
164  boost::multi_index::const_mem_fun<TrustAnchorGroup, const std::string&, &TrustAnchorGroup::getId>
165  >
166  >
167  >;
168 
169  GroupContainer m_groups;
170  AnchorContainer m_anchors;
171 };
172 
173 } // namespace ndn::security
174 
175 #endif // NDN_CXX_SECURITY_TRUST_ANCHOR_CONTAINER_HPP
Represents an Interest packet.
Definition: interest.hpp:50
Represents an absolute name.
Definition: name.hpp:45
Represents an NDN certificate.
Definition: certificate.hpp:58
const Certificate * find(const Name &keyName) const
Search for certificate across all groups (longest prefix match).
void insert(const std::string &groupId, Certificate &&cert)
Insert a static trust anchor.
size_t size() const
Get number of trust anchors across all groups.
TrustAnchorGroup & getGroup(const std::string &groupId) const
Get trusted anchor group.
void clear()
Remove all static or dynamic anchors.
Contains the ndn-cxx security framework.
::boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:54