Vanetza
Loading...
Searching...
No Matches
certificate_cache.hpp
1#pragma once
2#include <vanetza/security/hashed_id.hpp>
3#include <vanetza/security/v3/certificate.hpp>
4#include <unordered_map>
5#include <unordered_set>
6
7namespace vanetza
8{
9namespace security
10{
11namespace v3
12{
13
14/**
15 * CertificateCache stores validated v1.3.1 certificates for later lookup.
16 * Required for checking messages' signatures containing only a certificate digest.
17 */
19{
20public:
21 /**
22 * Lookup certificate based on given digest
23 * \param digest certificate digest
24 * \return certificate matching digest
25 */
26 const Certificate* lookup(const HashedId8& digest) const;
27 const Certificate* lookup(const HashedId3& digest) const;
28
29 /**
30 * Store a (pre-validated) certificate in cache
31 * \param cert certificate
32 */
33 void store(Certificate cert);
34
35 size_t size() const { return m_storage.size(); }
36
37 /**
38 * Announce a station with a given certificate digest.
39 * \param digest certificate digest
40 * \return true if digest was not known before
41 */
42 bool announce(const HashedId8& digest);
43
44 /**
45 * Test if a certificate digest is already known, i.e. either
46 * its certificate is stored or at least the digest has been announced.
47 * \param digest certificate digest
48 * \return true if digest is known
49 */
50 bool is_known(const HashedId8& digest) const;
51
52private:
53 using CertificateMap = std::unordered_map<HashedId8, Certificate>;
54 using ShortDigestMap = std::unordered_map<HashedId3, CertificateMap::iterator>;
55
56 // TODO add bounded capacity and automatic removal of expired certificates
57 CertificateMap m_storage;
58 ShortDigestMap m_short_digests;
59 std::unordered_set<HashedId8> m_digests;
60};
61
62} // namespace v3
63} // namespace security
64} // namespace vanetza
bool is_known(const HashedId8 &digest) const
bool announce(const HashedId8 &digest)
const Certificate * lookup(const HashedId8 &digest) const