Package org.conscrypt
Class AddressUtils
java.lang.Object
org.conscrypt.AddressUtils
Utilities to check whether IP addresses meet some criteria.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanasciiEqualsIgnoreCase(String s, 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(String hostname) Returns true if the supplied hostname is an literal IP address.private static booleanisValidIPv4(String s, int start, int end, boolean allowLeadingZeros) Validates IPv4 address.private static booleanValidates IPv6 address.(package private) static booleanisValidSniHostname(String sniHostname) Returns true when the supplied hostname is valid for SNI purposes.private static booleanisValidZoneId(String s, int start) Validates the IPv6 Zone ID (Scope ID).private static chartoLowerCaseAscii(char c)
-
Field Details
-
IPV4_OCTET_COUNT
private static final int IPV4_OCTET_COUNT- See Also:
-
MAX_IPV4_OCTET_VALUE
private static final int MAX_IPV4_OCTET_VALUE- See Also:
-
MAX_IPV4_OCTET_DIGITS
private static final int MAX_IPV4_OCTET_DIGITS- See Also:
-
MAX_IPV4_DOTS
private static final int MAX_IPV4_DOTS- See Also:
-
MIN_IPV4_ADDRESS_LENGTH
private static final int MIN_IPV4_ADDRESS_LENGTH- See Also:
-
MAX_IPV4_ADDRESS_LENGTH
private static final int MAX_IPV4_ADDRESS_LENGTH- See Also:
-
IPV6_TOTAL_GROUPS
private static final int IPV6_TOTAL_GROUPS- See Also:
-
IPV6_GROUPS_PER_IPV4
private static final int IPV6_GROUPS_PER_IPV4- See Also:
-
MAX_HEX_DIGITS_PER_GROUP
private static final int MAX_HEX_DIGITS_PER_GROUP- See Also:
-
ASCII_CASE_DIFF
private static final int ASCII_CASE_DIFF- See Also:
-
-
Constructor Details
-
AddressUtils
private AddressUtils()
-
-
Method Details
-
isValidSniHostname
Returns true when the supplied hostname is valid for SNI purposes. -
isLiteralIpAddress
Returns true if the supplied hostname is an literal IP address. -
isValidIPv4
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
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
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
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.
-