Files
MicrOBU/obu-firmware/external/vanetza-idf/vanetza/security/backend.cpp
T
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
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.
2026-09-24 10:56:05 +02:00

75 lines
1.8 KiB
C++

#include <vanetza/common/factory.hpp>
#include <vanetza/security/backend.hpp>
#include <cassert>
#include <stdexcept>
namespace
{
static vanetza::Factory<vanetza::security::Backend> backend_factory;
template<typename T>
class BackendRegistrar
{
public:
BackendRegistrar(const std::string& name)
{
auto f = []() { return std::unique_ptr<vanetza::security::Backend> { new T() }; };
bool success = backend_factory.add(name, f) && backend_factory.configure_default(name);
assert(success);
}
};
} // namespace
// order of VANETZA_REGISTER_CRYPTO_BACKEND invocation defines priority: last registered one will be default
#define VANETZA_REGISTER_CRYPTO_BACKEND(clazz) \
namespace { \
using namespace vanetza::security; \
static const BackendRegistrar<clazz> clazz##Factory(clazz::backend_name); \
}
#include <vanetza/security/backend_null.hpp>
VANETZA_REGISTER_CRYPTO_BACKEND(BackendNull)
#ifdef VANETZA_WITH_CRYPTOPP
# include <vanetza/security/backend_cryptopp.hpp>
VANETZA_REGISTER_CRYPTO_BACKEND(BackendCryptoPP)
#endif
#ifdef VANETZA_WITH_OPENSSL
# include <vanetza/security/backend_openssl.hpp>
VANETZA_REGISTER_CRYPTO_BACKEND(BackendOpenSsl)
#endif
namespace vanetza
{
namespace security
{
const Factory<Backend>& builtin_backends()
{
return backend_factory;
}
std::unique_ptr<Backend> create_backend(const std::string& name, const Factory<Backend>& factory)
{
if (name == "default") {
return factory.create();
} else {
return factory.create(name);
}
}
std::unique_ptr<Backend> create_backend_or_throw(const std::string& name)
{
auto backend = create_backend(name);
if (!backend) {
throw std::runtime_error("security backend unavailable");
}
return backend;
}
} // namespace security
} // namespace vanetza