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

81 lines
1.7 KiB
C++

#include <vanetza/security/hashed_id.hpp>
#include <boost/functional/hash.hpp>
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <sstream>
namespace vanetza
{
namespace security
{
HashedId3 truncate(const HashedId8& in)
{
HashedId3 out;
assert(out.size() <= in.size());
std::copy_n(in.rbegin(), out.size(), out.rbegin());
return out;
}
HashedId8 create_hashed_id8(const Sha256Digest& digest)
{
HashedId8 hashed;
std::copy(digest.end() - 8, digest.end(), hashed.data());
return hashed;
}
HashedId8 create_hashed_id8(const Sha384Digest& digest)
{
HashedId8 hashed;
std::copy(digest.end() - 8, digest.end(), hashed.data());
return hashed;
}
std::string to_string(const vanetza::security::HashedId3& digest)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (uint8_t octet : digest)
{
ss << std::setw(2) << static_cast<unsigned>(octet);
}
return ss.str();
}
std::string to_string(const vanetza::security::HashedId8& digest)
{
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (uint8_t octet : digest)
{
ss << std::setw(2) << static_cast<unsigned>(octet);
}
return ss.str();
}
} // namespace security
} // namespace vanetza
namespace std
{
size_t hash<vanetza::security::HashedId3>::operator()(const vanetza::security::HashedId3& hid3) const
{
size_t seed = 0;
for (uint8_t octet : hid3) {
boost::hash_combine(seed, octet);
}
return seed;
}
size_t hash<vanetza::security::HashedId8>::operator()(const vanetza::security::HashedId8& hid8) const
{
size_t seed = 0;
for (uint8_t octet : hid8) {
boost::hash_combine(seed, octet);
}
return seed;
}
} // namespace std