NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
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-2017 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_SECURITY_V2_TRUST_ANCHOR_CONTAINER_HPP
23 #define NDN_SECURITY_V2_TRUST_ANCHOR_CONTAINER_HPP
24 
25 #include "trust-anchor-group.hpp"
26 #include "certificate.hpp"
27 #include "../../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 {
35 namespace security {
36 namespace v2 {
37 
55 class TrustAnchorContainer : noncopyable
56 {
57 public:
58  class Error : public std::runtime_error
59  {
60  public:
61  explicit
62  Error(const std::string& what)
63  : std::runtime_error(what)
64  {
65  }
66  };
67 
79  void
80  insert(const std::string& groupId, Certificate&& cert);
81 
94  void
95  insert(const std::string& groupId, const boost::filesystem::path& path,
96  time::nanoseconds refreshPeriod, bool isDir = false);
97 
101  void
102  clear();
103 
111  const Certificate*
112  find(const Name& keyName) const;
113 
125  const Certificate*
126  find(const Interest& interest) const;
127 
133  getGroup(const std::string& groupId) const;
134 
138  size_t
139  size() const;
140 
141 private:
142  void
143  refresh();
144 
145 private:
146  using AnchorContainerBase = boost::multi_index::multi_index_container<
147  Certificate,
148  boost::multi_index::indexed_by<
149  boost::multi_index::ordered_unique<
150  boost::multi_index::const_mem_fun<Data, const Name&, &Data::getName>
151  >
152  >
153  >;
154 
155  class AnchorContainer : public CertContainerInterface,
156  public AnchorContainerBase
157  {
158  public:
159  void
160  add(Certificate&& cert) final;
161 
162  void
163  remove(const Name& certName) final;
164 
165  void
166  clear();
167  };
168 
169  using GroupContainer = boost::multi_index::multi_index_container<
170  shared_ptr<TrustAnchorGroup>,
171  boost::multi_index::indexed_by<
172  boost::multi_index::hashed_unique<
173  boost::multi_index::const_mem_fun<TrustAnchorGroup, const std::string&, &TrustAnchorGroup::getId>
174  >
175  >
176  >;
177 
178  GroupContainer m_groups;
179  AnchorContainer m_anchors;
180 };
181 
182 } // namespace v2
183 } // namespace security
184 } // namespace ndn
185 
186 #endif // NDN_SECURITY_V2_TRUST_ANCHOR_CONTAINER_HPP
Copyright (c) 2011-2015 Regents of the University of California.
The certificate following the certificate format naming convention.
Definition: certificate.hpp:81
const Certificate * find(const Name &keyName) const
Search for certificate across all groups (longest prefix match)
size_t size() const
Get number of trust anchors across all groups.
void insert(const std::string &groupId, Certificate &&cert)
Insert a static trust anchor.
STL namespace.
represents an Interest packet
Definition: interest.hpp:42
Catch-all error for security policy errors that don&#39;t fit in other categories.
Definition: base.hpp:79
TrustAnchorGroup & getGroup(const std::string &groupId) const
Get trusted anchor group.
represents a container for trust anchors.
Represents an absolute name.
Definition: name.hpp:42
void clear()
Remove all static or dynamic anchors.