Bob Beck | 8e7025e | 2023-09-05 17:05:26 -0600 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BSSL_PKI_IP_UTIL_H_ |
| 6 | #define BSSL_PKI_IP_UTIL_H_ |
| 7 | |
Bob Beck | 3cd30cc | 2023-11-22 16:59:00 -0700 | [diff] [blame] | 8 | #include <openssl/base.h> |
Bob Beck | 8e7025e | 2023-09-05 17:05:26 -0600 | [diff] [blame] | 9 | |
| 10 | #include "input.h" |
| 11 | |
| 12 | namespace bssl { |
| 13 | |
| 14 | inline constexpr size_t kIPv4AddressSize = 4; |
| 15 | inline constexpr size_t kIPv6AddressSize = 16; |
| 16 | |
Bob Beck | 3aecf1d | 2023-09-08 11:56:02 -0600 | [diff] [blame] | 17 | // Returns whether `mask` is a valid netmask. I.e., whether it is the length of |
| 18 | // an IPv4 or IPv6 address, and is some number of ones, followed by some number |
| 19 | // of zeros. |
Bob Beck | 8e7025e | 2023-09-05 17:05:26 -0600 | [diff] [blame] | 20 | OPENSSL_EXPORT bool IsValidNetmask(der::Input mask); |
| 21 | |
| 22 | // Returns whether `addr1` and `addr2` are equal under the netmask `mask`. |
| 23 | OPENSSL_EXPORT bool IPAddressMatchesWithNetmask(der::Input addr1, |
Bob Beck | 5c7a2a0 | 2023-11-20 17:28:21 -0700 | [diff] [blame] | 24 | der::Input addr2, |
| 25 | der::Input mask); |
Bob Beck | 8e7025e | 2023-09-05 17:05:26 -0600 | [diff] [blame] | 26 | |
Bob Beck | 5c7a2a0 | 2023-11-20 17:28:21 -0700 | [diff] [blame] | 27 | } // namespace bssl |
Bob Beck | 8e7025e | 2023-09-05 17:05:26 -0600 | [diff] [blame] | 28 | |
| 29 | #endif // BSSL_PKI_IP_UTIL_H_ |