Vanetza
 
Loading...
Searching...
No Matches
certificate_cache.hpp
1#ifndef VANETZA_CERTIFICATE_CACHE_HPP
2#define VANETZA_CERTIFICATE_CACHE_HPP
3
4#include <vanetza/common/clock.hpp>
5#include <vanetza/common/runtime.hpp>
6#include <vanetza/security/v2/certificate.hpp>
7#include <boost/heap/binomial_heap.hpp>
8#include <list>
9#include <map>
10
11namespace vanetza
12{
13namespace security
14{
15namespace v2
16{
17
18/**
19 * CertificateCache remembers validated certificates for some time.
20 * This is necessary for certificate lookup when only its digest is known.
21 */
23{
24public:
25 CertificateCache(const Runtime& rt);
26
27 /**
28 * Puts a (validated) certificate into the cache.
29 *
30 * \param certificate certificate to add to the cache
31 */
32 void insert(const Certificate& certificate);
33
34 /**
35 * Lookup certificates based on the passed HashedId8.
36 *
37 * \param id hash identifier of the certificate
38 * \param type type of certificate to lookup
39 * \return all stored certificates matching the passed identifier and type
40 */
41 std::list<Certificate> lookup(const HashedId8& id, SubjectType type);
42
43 /**
44 * Number of currently stored certificates
45 * \return cache size
46 */
47 std::size_t size() const { return m_certificates.size(); }
48
49private:
50 struct CachedCertificate;
51 using map_type = std::multimap<HashedId8, CachedCertificate>;
52
53 struct Expiry : public Clock::time_point
54 {
55 Expiry(Clock::time_point, map_type::iterator);
56 const map_type::iterator certificate;
57 };
58
59 using heap_type = boost::heap::binomial_heap<Expiry, boost::heap::compare<std::greater<Expiry>>>;
60
62 {
63 Certificate certificate;
64 heap_type::handle_type handle;
65 };
66
67 const Runtime& m_runtime;
68 heap_type m_expiries;
69 map_type m_certificates;
70
71 void drop_expired();
72 bool is_expired(const Expiry&) const;
73 void refresh(heap_type::handle_type&, Clock::duration);
74};
75
76} // namespace v2
77} // namespace security
78} // namespace vanetza
79
80#endif /* VANETZA_CERTIFICATE_CACHE_HPP */
void insert(const Certificate &certificate)
std::list< Certificate > lookup(const HashedId8 &id, SubjectType type)
described in TS 103 097 v1.2.1 (2015-06), section 6.1
Definition: certificate.hpp:28