Package org.conscrypt

Class AddressUtils


  • final class AddressUtils
    extends java.lang.Object
    Utilities to check whether IP addresses meet some criteria.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private AddressUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static boolean asciiEqualsIgnoreCase​(java.lang.String s, java.lang.String expected)
      Compares two ASCII strings case-insensitively.
      private static boolean isDigit​(char c)
      Returns true if the character is a basic ASCII digit (0-9).
      private static boolean isHexDigit​(char c)
      Returns true if the character is a valid hexadecimal digit (0-9, a-f, A-F).
      (package private) static boolean isLiteralIpAddress​(java.lang.String hostname)
      Returns true if the supplied hostname is an literal IP address.
      private static boolean isValidIPv4​(java.lang.String s, int start, int end, boolean allowLeadingZeros)
      Validates IPv4 address.
      private static boolean isValidIPv6​(java.lang.String s)
      Validates IPv6 address.
      (package private) static boolean isValidSniHostname​(java.lang.String sniHostname)
      Returns true when the supplied hostname is valid for SNI purposes.
      private static boolean isValidZoneId​(java.lang.String s, int start)
      Validates the IPv6 Zone ID (Scope ID).
      private static char toLowerCaseAscii​(char c)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AddressUtils

        private AddressUtils()
    • 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 of Character.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 of String.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.