xref: /aosp_15_r20/external/cronet/third_party/boringssl/src/pki/ip_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 
8 #include <openssl/base.h>
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 
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.
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,
24                                                 der::Input addr2,
25                                                 der::Input mask);
26 
27 }  // namespace bssl
28 
29 #endif  // BSSL_PKI_IP_UTIL_H_
30