From 60e53aef1d1e0395f55950d85597cb550150a8d0 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 18 Nov 2024 16:12:35 +0100 Subject: [PATCH] strip new line from end of password file --- src/main/java/org/cryptomator/cli/PasswordSource.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cryptomator/cli/PasswordSource.java b/src/main/java/org/cryptomator/cli/PasswordSource.java index 13eb956..d0a6784 100644 --- a/src/main/java/org/cryptomator/cli/PasswordSource.java +++ b/src/main/java/org/cryptomator/cli/PasswordSource.java @@ -23,7 +23,7 @@ public class PasswordSource { @CommandLine.Option(names = "--password:env", description = "Name of the environment variable containing the passphrase") String passphraseEnvironmentVariable = null; - @CommandLine.Option(names = "--password:file", description = "Path of the file containing the passphrase. The password file must be utf-8 encoded and must not end with a new line") + @CommandLine.Option(names = "--password:file", description = "Path of the file containing the passphrase. The password file must be utf-8 encoded") Path passphraseFile = null; Passphrase readPassphrase() throws IOException { @@ -58,7 +58,12 @@ private Passphrase readPassphraseFromFile() throws ReadingFileFailedException { } fileContent = Files.readAllBytes(passphraseFile); charWrapper = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(fileContent)); - char[] content = new char[charWrapper.limit()]; + //strips newline, since most files on linux end with a new line + var length = charWrapper.limit(); + if(charWrapper.get(length) == '\n') { + length--; + } + char[] content = new char[length]; charWrapper.get(content); return new Passphrase(content); } catch (IOException e) {