Enum ScramMechanisms

  • All Implemented Interfaces:
    ScramMechanism, Serializable, Comparable<ScramMechanisms>

    public enum ScramMechanisms
    extends Enum<ScramMechanisms>
    implements ScramMechanism
    SCRAM Mechanisms supported by this library. At least, SCRAM-SHA-1 and SCRAM-SHA-256 are provided, since both the hash and the HMAC implementations are provided by the Java JDK version 6 or greater. MessageDigest: "Every implementation of the Java platform is required to support the following standard MessageDigest algorithms: MD5, SHA-1, SHA-256". Mac: "Every implementation of the Java platform is required to support the following standard Mac algorithms: HmacMD5, HmacSHA1, HmacSHA256".
    See Also:
    SASL SCRAM Family Mechanisms
    • Method Detail

      • values

        public static ScramMechanisms[] 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 (ScramMechanisms c : ScramMechanisms.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static ScramMechanisms valueOf​(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:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • getHashAlgorithmName

        protected String getHashAlgorithmName()
        Method that returns the name of the hash algorithm. It is protected since should be of no interest for direct users. The instance is supposed to provide abstractions over the algorithm names, and are not meant to be directly exposed.
        Returns:
        The name of the hash algorithm
      • getHmacAlgorithmName

        protected String getHmacAlgorithmName()
        Method that returns the name of the HMAC algorithm. It is protected since should be of no interest for direct users. The instance is supposed to provide abstractions over the algorithm names, and are not meant to be directly exposed.
        Returns:
        The name of the HMAC algorithm
      • supportsChannelBinding

        public boolean supportsChannelBinding()
        Description copied from interface: ScramMechanism
        Whether this mechanism supports channel binding
        Specified by:
        supportsChannelBinding in interface ScramMechanism
        Returns:
        True if it supports channel binding, false otherwise
      • getMacInstance

        public Mac getMacInstance()
        Description copied from interface: ScramMechanism
        Gets a constructed Mac instance, according to the algorithm of the SCRAM mechanism.
        Specified by:
        getMacInstance in interface ScramMechanism
        Returns:
        The Mac instance
      • secretKeySpec

        public SecretKeySpec secretKeySpec​(byte[] key)
        Description copied from interface: ScramMechanism
        Generates a key of the algorith used, based on the key given.
        Specified by:
        secretKeySpec in interface ScramMechanism
        Parameters:
        key - The bytes of the key to use
        Returns:
        The instance of SecretKeySpec
      • algorithmKeyLength

        public int algorithmKeyLength()
        Description copied from interface: ScramMechanism
        Returns the length of the key length of the algorithm.
        Specified by:
        algorithmKeyLength in interface ScramMechanism
        Returns:
        The length (in bits)
      • byName

        public static Optional<ScramMechanisms> byName​(String name)
        Gets a SCRAM mechanism, given its standard IANA name.
        Parameters:
        name - The standard IANA full name of the mechanism.
        Returns:
        An Optional instance that contains the ScramMechanism if it was found, or empty otherwise.
      • selectMatchingMechanism

        public static Optional<ScramMechanism> selectMatchingMechanism​(boolean channelBinding,
                                                                       String... peerMechanisms)
        This class classifies SCRAM mechanisms by two properties: whether they support channel binding; and a priority, which is higher for safer algorithms (like SHA-256 vs SHA-1). Given a list of SCRAM mechanisms supported by the peer, pick one that matches the channel binding requirements and has the highest priority.
        Parameters:
        channelBinding - The type of matching mechanism searched for
        peerMechanisms - The mechanisms supported by the other peer
        Returns:
        The selected mechanism, or null if no mechanism matched