Vanetza
Loading...
Searching...
No Matches
certificate_cache.cpp
1#include <vanetza/security/v3/certificate_cache.hpp>
2#include <boost/optional/optional.hpp>
3
4namespace vanetza
5{
6namespace security
7{
8namespace v3
9{
10
11const Certificate* CertificateCache::lookup(const HashedId8& digest) const
12{
13 auto found = m_storage.find(digest);
14 if (found != m_storage.end()) {
15 return &found->second;
16 } else {
17 return nullptr;
18 }
19}
20
21const Certificate* CertificateCache::lookup(const HashedId3& digest) const
22{
23 auto found = m_short_digests.find(digest);
24 if (found != m_short_digests.end()) {
25 return &found->second->second;
26 } else {
27 return nullptr;
28 }
29}
30
32{
33 auto maybe_hash = cert.calculate_digest();
34 if (maybe_hash) {
35 CertificateMap::iterator it;
36 bool inserted;
37 std::tie(it, inserted) = m_storage.emplace(*maybe_hash, std::move(cert));
38 if (inserted) {
39 m_short_digests.emplace(truncate(*maybe_hash), it);
40 m_digests.insert(*maybe_hash);
41 }
42 }
43}
44
45bool CertificateCache::announce(const HashedId8& digest)
46{
47 bool inserted = false;
48 std::tie(std::ignore, inserted) = m_digests.insert(digest);
49 return inserted;
50}
51
52bool CertificateCache::is_known(const HashedId8& digest) const
53{
54 return m_digests.find(digest) != m_digests.end();
55}
56
57} // namespace v3
58} // namespace security
59} // namespace vanetza
bool is_known(const HashedId8 &digest) const
bool announce(const HashedId8 &digest)
const Certificate * lookup(const HashedId8 &digest) const
boost::optional< HashedId8 > calculate_digest() const