trust-anchor-container.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 
105  const Certificate*
106  find(const Name& keyName) const;
107 
119  const Certificate*
120  find(const Interest& interest) const;
121 
127  getGroup(const std::string& groupId) const;
128 
132  size_t
133  size() const;
134 
135 private:
136  void
137  refresh();
138 
139 private:
140  using AnchorContainerBase = boost::multi_index::multi_index_container<
141  Certificate,
142  boost::multi_index::indexed_by<
143  boost::multi_index::ordered_unique<
144  boost::multi_index::const_mem_fun<Data, const Name&, &Data::getName>
145  >
146  >
147  >;
148 
149  class AnchorContainer : public CertContainerInterface,
150  public AnchorContainerBase
151  {
152  public:
153  void
154  add(Certificate&& cert) final;
155 
156  void
157  remove(const Name& certName) final;
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 v2
174 } // namespace security
175 } // namespace ndn
176 
177 #endif // NDN_SECURITY_V2_TRUST_ANCHOR_CONTAINER_HPP
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
The certificate following the certificate format naming convention.
const Certificate * find(const Name &keyName) const
Search for certificate across all groups (longest prefix match)
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:98
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
TrustAnchorGroup & getGroup(const std::string &groupId) const
Get trusted anchor group.
represents a container for trust anchors.
Name abstraction to represent an absolute name.
Definition: name.hpp:46