Package com.lucimber.dbus.util
Class SaslUtils
java.lang.Object
com.lucimber.dbus.util.SaslUtils
Utility class for common methods used for SASL authentication.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
computeHashValue
(byte[] bytes) Computes a hash value via the SHA.static byte[]
fromHexadecimalString
(String hexString) Translates a hexadecimal string to its corresponding binary representation.static String
generateChallengeString
(int challengeLength) Generates an ASCII-safe challenge string.static Path
locateCookieFile
(Path directoryPath, String cookeFileName) Locates the cookie file for the DBUS_COOKIE_SHA1 authentication mechanism.static String
toHexadecimalString
(byte[] bytes) Translates a byte-array to its corresponding hexadecimal representation.
-
Method Details
-
toHexadecimalString
Translates a byte-array to its corresponding hexadecimal representation.- Parameters:
bytes
- The byte-array- Returns:
- The hexadecimal representation as a
String
.
-
fromHexadecimalString
Translates a hexadecimal string to its corresponding binary representation.- Parameters:
hexString
- The hexadecimal string- Returns:
- The binary representation as a byte-array.
-
generateChallengeString
Generates an ASCII-safe challenge string.- Parameters:
challengeLength
- The desired length of the challenge.- Returns:
- The challenge as a
String
.
-
locateCookieFile
public static Path locateCookieFile(Path directoryPath, String cookeFileName) throws FileNotFoundException, AccessDeniedException Locates the cookie file for the DBUS_COOKIE_SHA1 authentication mechanism.- Parameters:
directoryPath
- The path of the directory in which the file resides.cookeFileName
- The name of the cookie file.- Returns:
- The resolved path of the cookie file.
- Throws:
FileNotFoundException
- If the resolved path points to no (regular) file.AccessDeniedException
- If the cookie file cannot be accessed by the VM.
-
computeHashValue
Computes a hash value via the SHA.- Parameters:
bytes
- The bytes that should be hashed.- Returns:
- The hash as a byte-array.
- Throws:
NoSuchAlgorithmException
- If the JVM is not capable of computing the hash via SHA.
-