#include #include #include #include #include #include namespace vanetza { namespace security { namespace v2 { template std::size_t trim_size_impl(T in, typename std::enable_if::value>::type* = nullptr) { return in; } template std::size_t trim_size_impl(T in, typename std::enable_if::value>::type* = nullptr) { if (in > std::numeric_limits::max()) { throw std::overflow_error("given size exceeds limits of std::size_t"); } return static_cast(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