Files
MicrOBU/microbu-esp32c5/external/vanetza-idf/vanetza/security/secured_message.cpp
T
Ashin Walpola 0e9525162d Keep the colleague's microbu-esp32c5 tree in this repository
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).
2026-09-23 17:46:40 +02:00

131 lines
2.9 KiB
C++

#include <vanetza/security/secured_message.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
namespace vanetza
{
namespace security
{
SecuredMessageView::SecuredMessageView(const SecuredMessage& msg) :
m_variant(msg)
{
}
struct ItsAidVisitor : boost::static_visitor<ItsAid>
{
ItsAid operator()(const v2::SecuredMessage& msg) const
{
return get_its_aid(msg);
}
ItsAid operator()(const v3::SecuredMessage& msg) const
{
return msg.its_aid();
}
};
ItsAid get_its_aid(const SecuredMessage& msg)
{
return boost::apply_visitor(ItsAidVisitor(), msg);
}
ItsAid get_its_aid(const SecuredMessageView& msg)
{
return boost::apply_visitor(ItsAidVisitor(), msg);
}
std::size_t get_size(const SecuredMessage& msg)
{
struct Visitor : boost::static_visitor<std::size_t>
{
std::size_t operator()(const v2::SecuredMessage& msg) const
{
return get_size(msg);
}
std::size_t operator()(const v3::SecuredMessage& msg) const
{
return msg.size();
}
};
return boost::apply_visitor(Visitor(), msg);
}
struct SerializeVisitor : boost::static_visitor<void>
{
OutputArchive& m_archive;
SerializeVisitor(OutputArchive& ar) : m_archive(ar) {}
void operator()(const v2::SecuredMessage& msg)
{
serialize(m_archive, msg);
}
void operator()(const v3::SecuredMessage& msg)
{
serialize(m_archive, msg);
}
};
void serialize(OutputArchive& ar, const SecuredMessage& msg)
{
SerializeVisitor visitor { ar };
boost::apply_visitor(visitor, msg);
}
void serialize(OutputArchive& ar, const SecuredMessageView& msg)
{
SerializeVisitor visitor { ar };
boost::apply_visitor(visitor, msg);
}
std::size_t deserialize(InputArchive& ar, SecuredMessage& msg)
{
struct Visitor : boost::static_visitor<std::size_t>
{
InputArchive& m_archive;
Visitor(InputArchive& ar) : m_archive(ar) {}
std::size_t operator()(v2::SecuredMessage& msg)
{
return deserialize(m_archive, msg);
}
std::size_t operator()(v3::SecuredMessage& msg)
{
return deserialize(m_archive, msg);
}
};
Visitor visitor(ar);
return boost::apply_visitor(visitor, msg);
}
struct PayloadCopyVisitor : boost::static_visitor<PacketVariant>
{
PacketVariant operator()(const v2::SecuredMessage& msg) const
{
return msg.payload.data;
}
PacketVariant operator()(const v3::SecuredMessage& msg) const
{
return msg.payload();
}
};
PacketVariant get_payload_copy(const SecuredMessage& msg)
{
return boost::apply_visitor(PayloadCopyVisitor(), msg);
}
PacketVariant get_payload_copy(const SecuredMessageView& msg)
{
return boost::apply_visitor(PayloadCopyVisitor(), msg);
}
} // namespace security
} // namespace vanetza