obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
75 lines
1.8 KiB
C++
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
|