certificate-cache.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_CERTIFICATE_CACHE_HPP
23 #define NDN_CXX_SECURITY_CERTIFICATE_CACHE_HPP
24 
25 #include "ndn-cxx/interest.hpp"
27 
28 #include <boost/multi_index_container.hpp>
29 #include <boost/multi_index/ordered_index.hpp>
30 #include <boost/multi_index/mem_fun.hpp>
31 #include <boost/multi_index/member.hpp>
32 
33 namespace ndn {
34 namespace security {
35 inline namespace v2 {
36 
43 class CertificateCache : noncopyable
44 {
45 public:
51  explicit
53 
62  void
63  insert(const Certificate& cert);
64 
68  void
69  clear();
70 
78  const Certificate*
79  find(const Name& certPrefix) const;
80 
88  const Certificate*
89  find(const Interest& interest) const;
90 
91 private:
92  class Entry
93  {
94  public:
95  Entry(const Certificate& cert, const time::system_clock::TimePoint& removalTime)
96  : cert(cert)
97  , removalTime(removalTime)
98  {
99  }
100 
101  const Name&
102  getCertName() const
103  {
104  return cert.getName();
105  }
106 
107  public:
108  Certificate cert;
109  time::system_clock::TimePoint removalTime;
110  };
111 
115  void
116  refresh();
117 
118 public:
119  static time::nanoseconds
121 
122 private:
124  typedef boost::multi_index::multi_index_container<
125  Entry,
126  boost::multi_index::indexed_by<
127  boost::multi_index::ordered_non_unique<
128  boost::multi_index::member<Entry, const time::system_clock::TimePoint, &Entry::removalTime>
129  >,
130  boost::multi_index::ordered_unique<
131  boost::multi_index::const_mem_fun<Entry, const Name&, &Entry::getCertName>
132  >
133  >
134  > CertIndex;
135 
136  typedef CertIndex::nth_index<0>::type CertIndexByTime;
137  typedef CertIndex::nth_index<1>::type CertIndexByName;
138  CertIndex m_certs;
139  CertIndexByTime& m_certsByTime;
140  CertIndexByName& m_certsByName;
141  time::nanoseconds m_maxLifetime;
142 };
143 
144 } // inline namespace v2
145 } // namespace security
146 } // namespace ndn
147 
148 #endif // NDN_CXX_SECURITY_CERTIFICATE_CACHE_HPP
const Name & getName() const noexcept
Get name.
Definition: data.hpp:127
Represents an Interest packet.
Definition: interest.hpp:50
Represents an absolute name.
Definition: name.hpp:46
Represents a container for verified certificates.
void insert(const Certificate &cert)
Insert certificate into cache.
CertificateCache(const time::nanoseconds &maxLifetime=getDefaultLifetime())
Create an object for certificate cache.
void clear()
Remove all certificates from cache.
static time::nanoseconds getDefaultLifetime()
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
Represents an NDN certificate following the version 2.0 format.
Definition: certificate.hpp:61
time_point TimePoint
Definition: time.hpp:203
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
Definition: data.cpp:25