From 8184c30617391ce411480b3996542580db7238c7 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 24 May 2022 22:13:11 +0200 Subject: [PATCH] GenerateKeyCmd: Make --with-key-password indirect data type --- .../sop/cli/picocli/commands/GenerateKeyCmd.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sop-java-picocli/src/main/java/sop/cli/picocli/commands/GenerateKeyCmd.java b/sop-java-picocli/src/main/java/sop/cli/picocli/commands/GenerateKeyCmd.java index c1b0c90..56c0f1b 100644 --- a/sop-java-picocli/src/main/java/sop/cli/picocli/commands/GenerateKeyCmd.java +++ b/sop-java-picocli/src/main/java/sop/cli/picocli/commands/GenerateKeyCmd.java @@ -10,6 +10,7 @@ import java.util.List; import picocli.CommandLine; import sop.Ready; +import sop.cli.picocli.FileUtil; import sop.cli.picocli.Print; import sop.cli.picocli.SopCLI; import sop.exception.SOPGPException; @@ -29,7 +30,7 @@ public class GenerateKeyCmd implements Runnable { List userId = new ArrayList<>(); @CommandLine.Option(names = "--with-key-password", - description = "Password to protect the key", + description = "Indirect file type pointing to file containing password to protect the key", paramLabel = "PASSWORD") String withKeyPassword; @@ -48,8 +49,15 @@ public class GenerateKeyCmd implements Runnable { generateKey.noArmor(); } - if (withKeyPassword != null && !withKeyPassword.trim().isEmpty()) { - generateKey.withKeyPassword(withKeyPassword.trim()); + if (withKeyPassword != null) { + try { + String password = FileUtil.stringFromInputStream(FileUtil.getFileInputStream(withKeyPassword)); + generateKey.withKeyPassword(password); + } catch (SOPGPException.UnsupportedOption e) { + throw new SOPGPException.UnsupportedOption("Option '--with-key-password' is not supported."); + } catch (IOException e) { + throw new RuntimeException(e); + } } try {