Files
MicrOBU/microbu-esp32c5/external/vanetza-idf/vanetza/security/v2/serialization.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

66 lines
1.5 KiB
C++

#include <vanetza/security/v2/length_coding.hpp>
#include <vanetza/security/v2/serialization.hpp>
#include <cassert>
#include <limits>
#include <stdexcept>
#include <type_traits>
namespace vanetza
{
namespace security
{
namespace v2
{
template<typename T>
std::size_t trim_size_impl(T in, typename std::enable_if<std::is_same<T, std::size_t>::value>::type* = nullptr)
{
return in;
}
template<typename T>
std::size_t trim_size_impl(T in, typename std::enable_if<!std::is_same<T, std::size_t>::value>::type* = nullptr)
{
if (in > std::numeric_limits<std::size_t>::max()) {
throw std::overflow_error("given size exceeds limits of std::size_t");
}
return static_cast<std::size_t>(in);
}
std::size_t trim_size(std::uintmax_t in)
{
return trim_size_impl(in);
}
void serialize_length(OutputArchive& ar, std::uintmax_t length)
{
ByteBuffer buf;
buf = encode_length(length);
for (auto it = buf.begin(); it != buf.end(); it++) {
ar << *it;
}
}
std::uintmax_t deserialize_length(InputArchive& ar)
{
ByteBuffer buf(1);
ar >> buf[0];
const size_t leading = count_leading_ones(buf[0]);
buf.resize(leading + 1);
for (size_t c = 1; c <= leading; ++c) {
ar >> buf[c];
}
auto tup = decode_length(buf);
if (std::get<0>(tup) != buf.begin()) {
return std::get<1>(tup);
} else {
ar.fail(InputArchive::ErrorCode::ConstraintViolation);
return 0;
}
}
} // namespace v2
} // namespace security
} // namespace vanetza