15std::vector<std::byte>
BitsToBytes(std::span<const uint8_t> bits)
noexcept
17 std::vector<std::byte>
ret;
19 int next_byte_bits{0};
20 for (uint8_t val : bits) {
21 next_byte |= (val & 1) << (next_byte_bits++);
22 if (next_byte_bits == 8) {
23 ret.push_back(std::byte(next_byte));
28 if (next_byte_bits)
ret.push_back(std::byte(next_byte));
36 std::optional<size_t> sep_pos_opt;
37 for (
size_t pos = 0; pos < buffer.size(); ++pos) {
38 uint8_t x = buffer[pos];
39 if ((x & 0xFE) == 0)
continue;
41 if (sep_pos_opt)
return;
47 if (!sep_pos_opt)
return;
48 const size_t sep_pos{sep_pos_opt.value()};
49 const size_t ip_len{buffer.size() - sep_pos - 1};
50 if (ip_len > 128)
return;
56 for (
size_t prefix_len = sep_pos - 1; prefix_len > 0; --prefix_len) {
61 if (
prefix.size() == asmap.size())
continue;
66 auto addr =
BitsToBytes(buffer.subspan(sep_pos + 1));
std::vector< std::byte > BitsToBytes(std::span< const uint8_t > bits) noexcept
FUZZ_TARGET(asmap_direct)
bool SanityCheckAsmap(const std::span< const std::byte > asmap, int bits)
Validates ASMap structure by simulating all possible execution paths.
uint32_t Interpret(const std::span< const std::byte > asmap, const std::span< const std::byte > ip)
Execute the ASMap bytecode to find the ASN for an IP.