Files
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

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