| 181 | SubNetTest(AuthAllowedSubnet const& subnet) : subnet(subnet) {} |
| 182 | template <bool V4> |
| 183 | static SubNetTest randomSubNetImpl() { |
| 184 | constexpr int width = V4 ? 4 : 16; |
| 185 | std::array<unsigned char, width> binAddr; |
| 186 | unsigned char rnd[4]; |
| 187 | for (int i = 0; i < binAddr.size(); ++i) { |
| 188 | if (i % 4 == 0) { |
| 189 | auto tmp = deterministicRandom()->randomUInt32(); |
| 190 | ::memcpy(rnd, &tmp, 4); |
| 191 | } |
| 192 | binAddr[i] = rnd[i % 4]; |
| 193 | } |
| 194 | auto netmaskWeight = deterministicRandom()->randomInt(1, width); |
| 195 | std::string address; |
| 196 | if constexpr (V4) { |
| 197 | address_v4 a(binAddr); |
| 198 | address = a.to_string(); |
| 199 | } else { |
| 200 | address_v6 a(binAddr); |
| 201 | address = a.to_string(); |
| 202 | } |
| 203 | return SubNetTest(AuthAllowedSubnet::fromString(fmt::format("{}/{}", address, netmaskWeight))); |
| 204 | } |
| 205 | static SubNetTest randomSubNet() { |
| 206 | if (deterministicRandom()->coinflip()) { |
| 207 | return randomSubNetImpl<true>(); |
nothing calls this directly
no test coverage detected