Package org.conscrypt
Class AddressUtils
- java.lang.Object
-
- org.conscrypt.AddressUtils
-
final class AddressUtils extends java.lang.ObjectUtilities to check whether IP addresses meet some criteria.
-
-
Field Summary
Fields Modifier and Type Field Description private static intASCII_CASE_DIFFprivate static intIPV4_OCTET_COUNTprivate static intIPV6_GROUPS_PER_IPV4private static intIPV6_TOTAL_GROUPSprivate static intMAX_HEX_DIGITS_PER_GROUPprivate static intMAX_IPV4_ADDRESS_LENGTHprivate static intMAX_IPV4_DOTSprivate static intMAX_IPV4_OCTET_DIGITSprivate static intMAX_IPV4_OCTET_VALUEprivate static intMIN_IPV4_ADDRESS_LENGTH
-
Constructor Summary
Constructors Modifier Constructor Description privateAddressUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static booleanasciiEqualsIgnoreCase(java.lang.String s, java.lang.String expected)Compares two ASCII strings case-insensitively.private static booleanisDigit(char c)Returns true if the character is a basic ASCII digit (0-9).private static booleanisHexDigit(char c)Returns true if the character is a valid hexadecimal digit (0-9, a-f, A-F).(package private) static booleanisLiteralIpAddress(java.lang.String hostname)Returns true if the supplied hostname is an literal IP address.private static booleanisValidIPv4(java.lang.String s, int start, int end, boolean allowLeadingZeros)Validates IPv4 address.private static booleanisValidIPv6(java.lang.String s)Validates IPv6 address.(package private) static booleanisValidSniHostname(java.lang.String sniHostname)Returns true when the supplied hostname is valid for SNI purposes.private static booleanisValidZoneId(java.lang.String s, int start)Validates the IPv6 Zone ID (Scope ID).private static chartoLowerCaseAscii(char c)
-
-
-
Field Detail
-
IPV4_OCTET_COUNT
private static final int IPV4_OCTET_COUNT
- See Also:
- Constant Field Values
-
MAX_IPV4_OCTET_VALUE
private static final int MAX_IPV4_OCTET_VALUE
- See Also:
- Constant Field Values
-
MAX_IPV4_OCTET_DIGITS
private static final int MAX_IPV4_OCTET_DIGITS
- See Also:
- Constant Field Values
-
MAX_IPV4_DOTS
private static final int MAX_IPV4_DOTS
- See Also:
- Constant Field Values
-
MIN_IPV4_ADDRESS_LENGTH
private static final int MIN_IPV4_ADDRESS_LENGTH
- See Also:
- Constant Field Values
-
MAX_IPV4_ADDRESS_LENGTH
private static final int MAX_IPV4_ADDRESS_LENGTH
- See Also:
- Constant Field Values
-
IPV6_TOTAL_GROUPS
private static final int IPV6_TOTAL_GROUPS
- See Also:
- Constant Field Values
-
IPV6_GROUPS_PER_IPV4
private static final int IPV6_GROUPS_PER_IPV4
- See Also:
- Constant Field Values
-
MAX_HEX_DIGITS_PER_GROUP
private static final int MAX_HEX_DIGITS_PER_GROUP
- See Also:
- Constant Field Values
-
ASCII_CASE_DIFF
private static final int ASCII_CASE_DIFF
- See Also:
- Constant Field Values
-
-
Method Detail
-
isValidSniHostname
static boolean isValidSniHostname(java.lang.String sniHostname)
Returns true when the supplied hostname is valid for SNI purposes.
-
isLiteralIpAddress
static boolean isLiteralIpAddress(java.lang.String hostname)
Returns true if the supplied hostname is an literal IP address.
-
isValidIPv4
private static boolean isValidIPv4(java.lang.String s, int start, int end, boolean allowLeadingZeros)Validates IPv4 address. Expects exactly 4 octets separated by dots, each octet being 0-255. Allows leading zeros (up to 3 digits per octet). Parses the substring [start, end) without allocation.
-
isValidIPv6
private static boolean isValidIPv6(java.lang.String s)
Validates IPv6 address. Supports full, compressed (::), and embedded IPv4 formats. Also supports optional Zone ID (%zone) at the end. Scans the string in a single pass without allocations.
-
isValidZoneId
private static boolean isValidZoneId(java.lang.String s, int start)Validates the IPv6 Zone ID (Scope ID). A valid Zone ID must not be empty and must not contain any line terminators, matching the behavior of the '.' character in the original regular expression.
-
isDigit
private static boolean isDigit(char c)
Returns true if the character is a basic ASCII digit (0-9). We use this custom implementation instead ofCharacter.isDigit(char)to avoid checking for other Unicode digit characters, keeping it strictly to ASCII and avoiding any locale or Unicode overhead.
-
isHexDigit
private static boolean isHexDigit(char c)
Returns true if the character is a valid hexadecimal digit (0-9, a-f, A-F). This is a simple range check that avoids any character class or regex compilation.
-
toLowerCaseAscii
private static char toLowerCaseAscii(char c)
-
asciiEqualsIgnoreCase
private static boolean asciiEqualsIgnoreCase(java.lang.String s, java.lang.String expected)Compares two ASCII strings case-insensitively. We use this custom implementation instead ofString.equalsIgnoreCase(String)to: 1. Avoid dependency on Guava's Ascii class. 2. Avoid locale-dependent behavior of String.equalsIgnoreCase (e.g. Turkish 'I' mapping), ensuring strictly ASCII comparison. 3. Avoid any object allocations.
-
-