+ public static String readPassphrase(String filePath) {
+ return readPassphrase(Paths.get(filePath));
+ }
+
+ /** @return the first line of the file. */
+ public static String readPassphrase(Path path) {
+ if (!isPathAvailable(path))
+ return null;
+ List<String> lines;
+ try {
+ lines = Files.readAllLines(path);
+ } catch (IOException e) {
+ throw new IllegalStateException("Cannot read " + path, e);
+ }
+ if (lines.size() == 0)
+ return null;
+ String passphrase = lines.get(0);
+ return passphrase;
+ }
+
+ public static boolean isDefaultAuthdPassphraseFileAvailable() {
+ return isPathAvailable(Paths.get(AUTHD_PASSPHRASE_PATH));
+ }
+
+ public static boolean isPathAvailable(Path path) {
+ if (!Files.exists(path))
+ return false;
+ if (!Files.isReadable(path))
+ return false;
+ return true;
+ }
+