Package com.ongres.scram.common
Enum StringPreparation
- java.lang.Object
-
- java.lang.Enum<StringPreparation>
-
- com.ongres.scram.common.StringPreparation
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<StringPreparation>
public enum StringPreparation extends java.lang.Enum<StringPreparation>
StringPreparations enumerations to use in SCRAM.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description NO_PREPARATION
Implementation of StringPreparation that performs no preparation.POSTGRESQL_PREPARATION
Implementation of StringPreparation that performsSASLprep
preparation for PostgreSQL.SASL_PREPARATION
Implementation of StringPreparation that performsSASLprep
preparation.
-
Constructor Summary
Constructors Modifier Constructor Description private
StringPreparation()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract char[]
doNormalize(char[] value)
char[]
normalize(char[] value)
Normalize acording the selected preparation.static StringPreparation
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static StringPreparation[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
NO_PREPARATION
public static final StringPreparation NO_PREPARATION
Implementation of StringPreparation that performs no preparation. Non US-ASCII characters will produce an exception.Even though the [RFC5802] is not very clear about it, this implementation will normalize non-printable US-ASCII characters similarly to what SASLprep does (i.e., removing them).
-
SASL_PREPARATION
public static final StringPreparation SASL_PREPARATION
Implementation of StringPreparation that performsSASLprep
preparation. UTF-8 byte sequences that are prohibited by the SASLprep algorithm will produce an exception.
-
POSTGRESQL_PREPARATION
public static final StringPreparation POSTGRESQL_PREPARATION
Implementation of StringPreparation that performsSASLprep
preparation for PostgreSQL.The SCRAM specification dictates that the password is also in UTF-8, and is processed with the
SASLprep
algorithm. PostgreSQL, however, does not require UTF-8 to be used for the password. When a user's password is set, it is processed with SASLprep as if it was in UTF-8, regardless of the actual encoding used. However, if it is not a legal UTF-8 byte sequence, or it contains UTF-8 byte sequences that are prohibited by the SASLprep algorithm, the raw password will be used without SASLprep processing, instead of throwing an error. This allows the password to be normalized when it is in UTF-8, but still allows a non-UTF-8 password to be used, and doesn't require the system to know which encoding the password is in.- See Also:
- PostgreSQL SCRAM-SHA-256 Authentication
-
-
Method Detail
-
values
public static StringPreparation[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (StringPreparation c : StringPreparation.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static StringPreparation valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
doNormalize
abstract char[] doNormalize(char[] value)
-
normalize
public char[] normalize(char[] value)
Normalize acording the selected preparation.- Parameters:
value
- array of chars to normalize- Returns:
- the normalized array of chars
- Throws:
java.lang.IllegalArgumentException
- if the string is null or empty
-
-