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

94 lines
2.1 KiB
C++

#include "hashed_id8.hpp"
#include "hexstring.hpp"
#include <vanetza/asn1/security/HashedId8.h>
#include <boost/algorithm/hex.hpp>
#include <algorithm>
#include <cctype>
#include <cstring>
namespace vanetza
{
namespace pki
{
HashedId8::HashedId8(const Sha256Hash& hash)
{
std::copy(hash.octets.end() - 8, hash.octets.end(), octets.data());
}
HashedId8::HashedId8(const Sha384Hash& hash)
{
std::copy(hash.octets.end() - 8, hash.octets.end(), octets.data());
}
boost::optional<HashedId8> HashedId8::from_hexstring(const std::string& hex)
{
if (hex.size() == 16) {
try {
HashedId8 result;
boost::algorithm::unhex(hex, result.octets.data());
return result;
} catch (boost::algorithm::hex_decode_error&) {
}
}
return boost::none;
}
boost::optional<HashedId8> HashedId8::from_buffer(const OCTET_STRING_t& os)
{
HashedId8 result;
if (os.buf != nullptr && os.size == result.octets.size()) {
std::copy_n(os.buf, result.octets.size(), result.octets.data());
return result;
}
return boost::none;
}
std::string hexstring(const HashedId8& id)
{
return hexstring(id.octets.data(), id.octets.size());
}
bool valid_hashed_id8(const std::string& hex)
{
auto all_hex = [](const std::string& input) {
return std::all_of(input.begin(), input.end(), [](unsigned char c) { return std::isxdigit(c); });
};
return (hex.size() == 16 && all_hex(hex));
}
bool operator==(const HashedId8& a, const HashedId8& b)
{
return a.octets == b.octets;
}
bool operator!=(const HashedId8& a, const HashedId8& b)
{
return a.octets != b.octets;
}
bool operator<(const HashedId8& a, const HashedId8& b)
{
return a.octets < b.octets;
}
bool lexical_cast(const std::string& input, HashedId8& hid8)
{
auto staging = HashedId8::from_hexstring(input);
if (staging) {
hid8 = *staging;
}
return staging.has_value();
}
bool equals(const Vanetza_Security_HashedId8_t& asn, const HashedId8& own)
{
return asn.size == own.octets.size() && std::memcmp(asn.buf, own.octets.data(), own.octets.size()) == 0;
}
} // namespace pki
} // namespace vanetza