GenerateKeyCmd: Make --with-key-password indirect data type

This commit is contained in:
Paul Schaub 2022-05-24 22:13:11 +02:00
parent 45ee435a18
commit 8184c30617
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -10,6 +10,7 @@ import java.util.List;
import picocli.CommandLine; import picocli.CommandLine;
import sop.Ready; import sop.Ready;
import sop.cli.picocli.FileUtil;
import sop.cli.picocli.Print; import sop.cli.picocli.Print;
import sop.cli.picocli.SopCLI; import sop.cli.picocli.SopCLI;
import sop.exception.SOPGPException; import sop.exception.SOPGPException;
@ -29,7 +30,7 @@ public class GenerateKeyCmd implements Runnable {
List<String> userId = new ArrayList<>(); List<String> userId = new ArrayList<>();
@CommandLine.Option(names = "--with-key-password", @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") paramLabel = "PASSWORD")
String withKeyPassword; String withKeyPassword;
@ -48,8 +49,15 @@ public class GenerateKeyCmd implements Runnable {
generateKey.noArmor(); generateKey.noArmor();
} }
if (withKeyPassword != null && !withKeyPassword.trim().isEmpty()) { if (withKeyPassword != null) {
generateKey.withKeyPassword(withKeyPassword.trim()); 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 { try {