java.lang.Object
org.minidns.util.SafeCharSequence
org.minidns.dnslabel.DnsLabel
- All Implemented Interfaces:
CharSequence, Comparable<DnsLabel>
- Direct Known Subclasses:
LdhLabel, NonLdhLabel
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.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when a DNS label exceeds the maximum length.Field Summary
Modifier and TypeFieldDescriptionprivate byte[]Cached wire encoding of the label.private StringCached non-ASCII form of the label.final StringThe label string.private DnsLabelCached lower-case form of the label.static final intThe maximum length of a DNS label in octets.private StringCached printable form of the label.private static final booleanWhether or not the DNS label is validated on construction.static final DnsLabelThe wildcard label.Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionfinal DnsLabelGet the lowercase variant of this label.final intOrder labels case-insensitively, ignoring letter case.private static booleanconsistsOnlyOfLdhAndMaybeUnderscore(String string, boolean underscore) Checks whether a whole string is LDH plus allowed underscores.static booleanCheck if a string consists of only letters, digits, and hyphens.static booleanCheck if a string consists of only letters, digits, hyphens, and underscores.final booleanCompare the label text against another label.static DnsLabelCreate a DnsLabel from a string.static DnsLabel[]Create DnsLabel array from string array.final StringGet the internationalized representation of this label.protected StringGets the internal internationalized representation.final StringGet the type of this label.final StringGet the raw label.final inthashCode()Hash the label text.static booleanisIdnAcePrefixed(String string) Check if a string has the IDN ACE prefix.private static booleanisLdhOrMaybeUnderscore(char c, boolean underscore) Checks whether a character is a letter, digit, dash or allowed underscore.private voidFills the byte cache if it is still empty.static StringtoSafeRepesentation(String dnsLabel) Convert a DNS label string to a safe representation.final StringtoString()Render the label with every character outside the LDH set escaped.final voidwriteToBoas(ByteArrayOutputStream byteArrayOutputStream) Write this label to a ByteArrayOutputStream prefixed by its length.Methods inherited from class SafeCharSequence
charAt, length, subSequence, toSafeStringModifier and TypeMethodDescriptionfinal charcharAt(int index) Returns one character of the safe string form.final intlength()Counts the characters of the safe string form.final CharSequencesubSequence(int start, int end) Returns a safe substring of the safe string form.Return a safe string representation.Methods inherited from interface CharSequence
chars, codePoints, getChars, isEmpty
Field Details
MAX_LABEL_LENGTH_IN_OCTETS
public static final int MAX_LABEL_LENGTH_IN_OCTETSThe maximum length of a DNS label in octets.WILDCARD_LABEL
The wildcard label.VALIDATE
private static final boolean VALIDATEWhether or not the DNS label is validated on construction.- See Also:
label
The label string.internationalizedRepresentation
Cached non-ASCII form of the label.safeToStringRepresentation
Cached printable form of the label.lowercasedVariant
Cached lower-case form of the label.byteCache
private transient byte[] byteCacheCached wire encoding of the label.
Constructor Details
DnsLabel
Stores one label, rejecting any longer than 63 octets.- Parameters:
label- presentation-format text of one label, checked against the 63-octet limit
Method Details
getInternationalizedRepresentation
Get the internationalized representation of this label.- Returns:
- the internationalized label
getInternationalizedRepresentationInternal
Gets the internal internationalized representation.- Returns:
- label string
getLabelType
toString
Render the label with every character outside the LDH set escaped.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
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 usetoString()instead, which will return a sanitized String.- Returns:
- the raw label.
equals
hashCode
asLowercaseVariant
Get the lowercase variant of this label.- Returns:
- the lowercase label
setBytesIfRequired
private void setBytesIfRequired()Fills the byte cache if it is still empty.writeToBoas
Write this label to a ByteArrayOutputStream prefixed by its length.- Parameters:
byteArrayOutputStream- the output stream to write to
compareTo
Order labels case-insensitively, ignoring letter case.- Specified by:
compareToin interfaceComparable<DnsLabel>
from
Create a DnsLabel from a string.- Parameters:
label- the label string- Returns:
- a
LdhLabelif the string is a well-formed LDH label, and aNonLdhLabelotherwise
from
isIdnAcePrefixed
Check if a string has the IDN ACE prefix.- Parameters:
string- the string to check- Returns:
- true if the string starts with "xn--"
toSafeRepesentation
isLdhOrMaybeUnderscore
private static boolean isLdhOrMaybeUnderscore(char c, boolean underscore) Checks whether a character is a letter, digit, dash or allowed underscore.- Parameters:
c- the character to checkunderscore- true to allow underscores- Returns:
- true if the character is allowed
consistsOnlyOfLdhAndMaybeUnderscore
Checks whether a whole string is LDH plus allowed underscores.- Parameters:
string- the string to checkunderscore- true to allow underscores- Returns:
- true if every character is allowed
consistsOnlyOfLettersDigitsAndHypen
Check if a string consists of only letters, digits, and hyphens.- Parameters:
string- the string to check- Returns:
- true if it matches LDH rules
consistsOnlyOfLettersDigitsHypenAndUnderscore
Check if a string consists of only letters, digits, hyphens, and underscores.- Parameters:
string- the string to check- Returns:
- true if it matches LDH or underscore rules