/src/botan/src/fuzzer/ipv4.cpp
Line | Count | Source |
1 | | /* |
2 | | * (C) 2024 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #include "fuzzers.h" |
8 | | |
9 | | #include <botan/internal/loadstor.h> |
10 | | #include <botan/internal/parsing.h> |
11 | | |
12 | 96 | void fuzz(std::span<const uint8_t> in) { |
13 | 96 | std::string_view str(reinterpret_cast<const char*>(in.data()), in.size()); |
14 | 96 | if(auto ipv4 = Botan::string_to_ipv4(str)) { |
15 | 1 | const auto rt = Botan::ipv4_to_string(*ipv4); |
16 | 1 | FUZZER_ASSERT_EQUAL(str, rt); |
17 | 1 | } |
18 | | |
19 | 96 | if(in.size() == 4) { |
20 | 13 | uint32_t ip = Botan::load_be<uint32_t>(in.data(), 0); |
21 | 13 | auto s = Botan::ipv4_to_string(ip); |
22 | 13 | auto rt = Botan::string_to_ipv4(s); |
23 | 13 | FUZZER_ASSERT_TRUE(rt.has_value()); |
24 | 13 | FUZZER_ASSERT_EQUAL(rt.value(), ip); |
25 | 13 | } |
26 | 96 | } |