Skip to content

Commit

Permalink
strip new line from end of password file
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Nov 18, 2024
1 parent ded3f90 commit 60e53ae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/cryptomator/cli/PasswordSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 60e53ae

Please sign in to comment.