Class DnsLabel

All Implemented Interfaces:
CharSequence, Comparable<DnsLabel>
Direct Known Subclasses:
LdhLabel, NonLdhLabel

public abstract class DnsLabel extends SafeCharSequence implements Comparable<DnsLabel>
A DNS label is an individual component of a DNS name. Labels are usually shown separated by dots.

This class implements Comparable which compares DNS labels according to the Canonical DNS Name Order as specified in RFC 4034 § 6.1.

Note that as per RFC 2181 § 11 DNS labels may contain any byte.

Author:
Florian Schmaus
See Also:
  • Field Details

    • MAX_LABEL_LENGTH_IN_OCTETS

      public static final int MAX_LABEL_LENGTH_IN_OCTETS
      The maximum length of a DNS label in octets.
      See Also:
    • WILDCARD_LABEL

      public static final DnsLabel WILDCARD_LABEL
    • VALIDATE

      public static final boolean VALIDATE
      Whether or not the DNS label is validated on construction.
      See Also:
    • label

      public final String label
  • Constructor Details

    • DnsLabel

      protected DnsLabel(String label)
  • Method Details

    • getInternationalizedRepresentation

      public final String getInternationalizedRepresentation()
    • getInternationalizedRepresentationInternal

      protected String getInternationalizedRepresentationInternal()
    • getLabelType

      public final String getLabelType()
    • toString

      public final String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • getRawLabel

      public final String getRawLabel()
      Get the raw label. Note that this may return a String containing null bytes. Those Strings are notoriously difficult to handle from a security perspective. Therefore it is recommended to use toString() instead, which will return a sanitized String.
      Returns:
      the raw label.
      Since:
      1.1.0
    • equals

      public final boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • asLowercaseVariant

      public final DnsLabel asLowercaseVariant()
    • writeToBoas

      public final void writeToBoas(ByteArrayOutputStream byteArrayOutputStream)
    • compareTo

      public final int compareTo(DnsLabel other)
      Specified by:
      compareTo in interface Comparable<DnsLabel>
    • from

      public static DnsLabel from(String label)
    • from

      public static DnsLabel[] from(String[] labels)
    • isIdnAcePrefixed

      public static boolean isIdnAcePrefixed(String string)
    • toSafeRepesentation

      public static String toSafeRepesentation(String dnsLabel)
    • consistsOnlyOfLettersDigitsAndHypen

      public static boolean consistsOnlyOfLettersDigitsAndHypen(String string)
    • consistsOnlyOfLettersDigitsHypenAndUnderscore

      public static boolean consistsOnlyOfLettersDigitsHypenAndUnderscore(String string)