Vanetza
Loading...
Searching...
No Matches
trust_store.cpp
1#include <vanetza/security/v3/trust_store.hpp>
2#include <boost/optional.hpp>
3#include <stdexcept>
4
5namespace vanetza
6{
7namespace security
8{
9namespace v3
10{
11
12void TrustStore::insert(const Certificate& certificate)
13{
14 if (!certificate.issuer_is_self()) {
15 throw std::runtime_error("Only root certificate authorities may be added to the trust store");
16 }
17
18 auto id = certificate.calculate_digest();
19 if (!id) {
20 throw std::runtime_error("Cannot calculate hash for certificate");
21 }
22 m_certificates.insert(std::make_pair(*id, certificate));
23}
24
25std::list<Certificate> TrustStore::lookup(HashedId8 id) const
26{
27 using iterator = std::multimap<HashedId8, Certificate>::const_iterator;
28 std::pair<iterator, iterator> range = m_certificates.equal_range(id);
29
30 std::list<Certificate> matches;
31 for (auto item = range.first; item != range.second; ++item) {
32 matches.push_back(item->second);
33 }
34 return matches;
35}
36
37} // namespace v3
38} // namespace security
39} // namespace vanetza
boost::optional< HashedId8 > calculate_digest() const
void insert(const Certificate &trusted_certificate)
std::list< Certificate > lookup(HashedId8 id) const