obu-firmware builds against the vanetza-idf C-ITS library, which until now came from the colleague's microbu-esp32c5 tree beside the repository and was not tracked here, so a clone of this repository could not build the firmware it ships. The library alone is now part of obu-firmware, as obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from there by default; -DVANETZA_IDF_DIR still points the build elsewhere. The rest of the colleague's tree (their own VAM firmware, PKI tooling, station-link Python tools, the V2X2MAP bridge) stays out of this repository and gitignored; nothing is pushed to their repository. NOTES.md, docs/06, TODO.md and the pcap verifier's usage line point at the new location.
81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
#ifndef VANETZA_CERTIFICATE_CACHE_HPP
|
|
#define VANETZA_CERTIFICATE_CACHE_HPP
|
|
|
|
#include <vanetza/common/clock.hpp>
|
|
#include <vanetza/common/runtime.hpp>
|
|
#include <vanetza/security/v2/certificate.hpp>
|
|
#include <boost/heap/binomial_heap.hpp>
|
|
#include <list>
|
|
#include <map>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
namespace v2
|
|
{
|
|
|
|
/**
|
|
* CertificateCache remembers validated certificates for some time.
|
|
* This is necessary for certificate lookup when only its digest is known.
|
|
*/
|
|
class CertificateCache
|
|
{
|
|
public:
|
|
CertificateCache(const Runtime& rt);
|
|
|
|
/**
|
|
* Puts a (validated) certificate into the cache.
|
|
*
|
|
* \param certificate certificate to add to the cache
|
|
*/
|
|
void insert(const Certificate& certificate);
|
|
|
|
/**
|
|
* Lookup certificates based on the passed HashedId8.
|
|
*
|
|
* \param id hash identifier of the certificate
|
|
* \param type type of certificate to lookup
|
|
* \return all stored certificates matching the passed identifier and type
|
|
*/
|
|
std::list<Certificate> lookup(const HashedId8& id, SubjectType type);
|
|
|
|
/**
|
|
* Number of currently stored certificates
|
|
* \return cache size
|
|
*/
|
|
std::size_t size() const { return m_certificates.size(); }
|
|
|
|
private:
|
|
struct CachedCertificate;
|
|
using map_type = std::multimap<HashedId8, CachedCertificate>;
|
|
|
|
struct Expiry : public Clock::time_point
|
|
{
|
|
Expiry(Clock::time_point, map_type::iterator);
|
|
const map_type::iterator certificate;
|
|
};
|
|
|
|
using heap_type = boost::heap::binomial_heap<Expiry, boost::heap::compare<std::greater<Expiry>>>;
|
|
|
|
struct CachedCertificate
|
|
{
|
|
Certificate certificate;
|
|
heap_type::handle_type handle;
|
|
};
|
|
|
|
const Runtime& m_runtime;
|
|
heap_type m_expiries;
|
|
map_type m_certificates;
|
|
|
|
void drop_expired();
|
|
bool is_expired(const Expiry&) const;
|
|
void refresh(heap_type::handle_type&, Clock::duration);
|
|
};
|
|
|
|
} // namespace v2
|
|
} // namespace security
|
|
} // namespace vanetza
|
|
|
|
#endif /* VANETZA_CERTIFICATE_CACHE_HPP */
|