com.mysql.cj.util

## Class SaslPrep

- java.lang.Object
- - com.mysql.cj.util.SaslPrep

    public class SaslPrep
    extends Object

Implementation for SASLprep: Stringprep Profile for User Names and Passwords, as specified in RFC 4013.

See Also:
  RFC 3454

### Nested Class Summary

Nested Classes
`static class` `SaslPrep.StringType` The type of string usage regarding the support for unassigned code points as described in RFC 3454, Section 7.

### Constructor Summary

Constructors
`SaslPrep()`

### Method Summary

All Methods Static Methods Concrete Methods
`private static boolean` `isAsciiControlCharacter(char chr)` Prohibited Output: ASCII control characters [StringPrep, C.2.1].
`private static boolean` `isBidiLCat(int cp)` Bidirectional Characters: LCat characters.
`private static boolean` `isBidiRAndAlCat(int cp)` Bidirectional Characters: RandALCat characters.
`private static boolean` `isChangeDisplayPropertiesOrDeprecatedCharacter(char chr)` Prohibited Output: change display properties or deprecated characters [StringPrep, C.8].
`private static boolean` `isInappropriateForCanonicalRepresentationCharacter(char chr)` Prohibited Output: inappropriate for canonical representation characters [StringPrep, C.7].
`private static boolean` `isInappropriateForPlainTextCharacter(char chr)` Prohibited Output: inappropriate for plain text characters [StringPrep, C.6].
`private static boolean` `isMappeableToNothing(char chr)` Mapping: the "commonly mapped to nothing" characters [StringPrep, B.1] that can be mapped to nothing.
`private static boolean` `isNonAsciiControlCharacter(int cp)` Prohibited Output: non-ASCII control characters [StringPrep, C.2.2].
`private static boolean` `isNonAsciiSpaceChar(char chr)` Mapping: non-ASCII space characters [StringPrep, C.1.2] that can be mapped to SPACE (U+0020).
`private static boolean` `isNonCharacterCodePoint(int cp)` Prohibited Output: non-character code points [StringPrep, C.4].
`private static boolean` `isPrivateUseCharacter(int cp)` Prohibited Output: private use characters [StringPrep, C.3].
`private static boolean` `isProhibited(char chr, int cp)` Checks if the given character is one of the prohibited characters under the "SASLprep Profile" rules.
`private static boolean` `isSurrogateCode(char chr)` Prohibited Output: surrogate code points [StringPrep, C.5].
`private static boolean` `isTaggingCharacter(int cp)` Prohibited Output: tagging characters [StringPrep, C.9].
`private static boolean` `isUnassigned(int cp)` Unassigned Code Points: list of unassigned code points.
`private static String` `normalizeKc(CharSequence str)` Normalization: Unicode normalization form KC.
`static String` `prepare(String str, SaslPrep.StringType sType)` Prepares the given string by applying the "SASLprep" profile of the "stringprep" algorithm.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### SaslPrep

    public SaslPrep()

### Method Detail

#### prepare

    public static String prepare(String str,
                                 SaslPrep.StringType sType)

Prepares the given string by applying the "SASLprep" profile of the "stringprep" algorithm.

Parameters:
  `str` - the string to prepare.
  `sType` - the type of preparation with regard to the support for unassigned code points.
Returns:
  the prepared version of the given string.
See Also:
  RFC 4013, RFC 3454

#### isNonAsciiSpaceChar

    private static boolean isNonAsciiSpaceChar(char chr)

Mapping: non-ASCII space characters [StringPrep, C.1.2] that can be mapped to SPACE (U+0020).

Parameters:
  `chr` - the character to check.
Returns:
  `true` if the character is one of the non-ASCII space characters, `false` otherwise.

#### isMappeableToNothing

    private static boolean isMappeableToNothing(char chr)

Mapping: the "commonly mapped to nothing" characters [StringPrep, B.1] that can be mapped to nothing.

Parameters:
  `chr` - the character to check.
Returns:
  `true` if the character is one of the "commonly mapped to nothing" characters, `false` otherwise.

#### normalizeKc

    private static String normalizeKc(CharSequence str)

Normalization: Unicode normalization form KC.

Parameters:
  `str` - the string to be normalized.
Returns:
  a normalized version of the given string by the rules of the Unicode normalization form KC.

#### isProhibited

    private static boolean isProhibited(char chr,
                                        int cp)

Checks if the given character is one of the prohibited characters under the "SASLprep Profile" rules.

Parameters:
  `chr` - the character to check.
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is prohibited according to the profile rules, `false` otherwise.
See Also:
  RFC 4013, Section 2.3

#### isAsciiControlCharacter

    private static boolean isAsciiControlCharacter(char chr)

Prohibited Output: ASCII control characters [StringPrep, C.2.1].

Parameters:
  `chr` - the character to check.
Returns:
  `true` if the character is one of the ASCII control characters, `false` otherwise.

#### isNonAsciiControlCharacter

    private static boolean isNonAsciiControlCharacter(int cp)

Prohibited Output: non-ASCII control characters [StringPrep, C.2.2].

Parameters:
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is one of the non-ASCII control characters, `false` otherwise.

#### isPrivateUseCharacter

    private static boolean isPrivateUseCharacter(int cp)

Prohibited Output: private use characters [StringPrep, C.3].

Parameters:
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is one of the private use characters, `false` otherwise.

#### isNonCharacterCodePoint

    private static boolean isNonCharacterCodePoint(int cp)

Prohibited Output: non-character code points [StringPrep, C.4].

Parameters:
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is one of the non-character code points, `false` otherwise.

#### isSurrogateCode

    private static boolean isSurrogateCode(char chr)

Prohibited Output: surrogate code points [StringPrep, C.5].

Parameters:
  `chr` - the character to check.
Returns:
  `true` if the character is one of the surrogate code points, `false` otherwise.

#### isInappropriateForPlainTextCharacter

    private static boolean isInappropriateForPlainTextCharacter(char chr)

Prohibited Output: inappropriate for plain text characters [StringPrep, C.6].

Parameters:
  `chr` - the character to check.
Returns:
  `true` if the character is one of the inappropriate for plain text characters, `false` otherwise.

#### isInappropriateForCanonicalRepresentationCharacter

    private static boolean isInappropriateForCanonicalRepresentationCharacter(char chr)

Prohibited Output: inappropriate for canonical representation characters [StringPrep, C.7].

Parameters:
  `chr` - the character to check.
Returns:
  `true` if the character is one of the inappropriate for canonical representation characters, `false` otherwise.

#### isChangeDisplayPropertiesOrDeprecatedCharacter

    private static boolean isChangeDisplayPropertiesOrDeprecatedCharacter(char chr)

Prohibited Output: change display properties or deprecated characters [StringPrep, C.8].

Parameters:
  `chr` - the character to check.
Returns:
  `true` if the character is one of the change display properties or deprecated characters, `false` otherwise.

#### isTaggingCharacter

    private static boolean isTaggingCharacter(int cp)

Prohibited Output: tagging characters [StringPrep, C.9].

Parameters:
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is one of the tagging characters, `false` otherwise.

#### isBidiRAndAlCat

    private static boolean isBidiRAndAlCat(int cp)

Bidirectional Characters: RandALCat characters. See also RFC 3454, Section 6

Parameters:
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is one of the RandALCat characters, `false` otherwise.

#### isBidiLCat

    private static boolean isBidiLCat(int cp)

Bidirectional Characters: LCat characters. See also RFC 3454, Section 6

Parameters:
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is one of the LCat characters, `false` otherwise.

#### isUnassigned

    private static boolean isUnassigned(int cp)

Unassigned Code Points: list of unassigned code points. See also RFC 3454, Section 7.

Note that this implementation does not check exactly the unassigned code points as specified in the RFC since it is based on Java's Unicode support, which is updated regularly while the specification is based on a static list of code points. This should have no major impact, though.

Parameters:
  `cp` - the code point of the character to check.
Returns:
  `true` if the character is unassigned, `false` otherwise.

Copyright © 2016, 2025, Oracle and/or its affiliates.