mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-22 15:12:06 +01:00
Kotlin conversion: ChangeKeyPasswordCmd
This commit is contained in:
parent
377a7287b3
commit
49120c5da8
2 changed files with 46 additions and 56 deletions
|
@ -1,56 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package sop.cli.picocli.commands;
|
|
||||||
|
|
||||||
import picocli.CommandLine;
|
|
||||||
import sop.cli.picocli.SopCLI;
|
|
||||||
import sop.exception.SOPGPException;
|
|
||||||
import sop.operation.ChangeKeyPassword;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandLine.Command(name = "change-key-password",
|
|
||||||
resourceBundle = "msg_change-key-password",
|
|
||||||
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
|
||||||
public class ChangeKeyPasswordCmd extends AbstractSopCmd {
|
|
||||||
|
|
||||||
@CommandLine.Option(names = "--no-armor",
|
|
||||||
negatable = true)
|
|
||||||
boolean armor = true;
|
|
||||||
|
|
||||||
@CommandLine.Option(names = {"--old-key-password"},
|
|
||||||
paramLabel = "PASSWORD")
|
|
||||||
List<String> oldKeyPasswords = new ArrayList<>();
|
|
||||||
|
|
||||||
@CommandLine.Option(names = {"--new-key-password"}, arity = "0..1",
|
|
||||||
paramLabel = "PASSWORD")
|
|
||||||
String newKeyPassword = null;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ChangeKeyPassword changeKeyPassword = throwIfUnsupportedSubcommand(
|
|
||||||
SopCLI.getSop().changeKeyPassword(), "change-key-password");
|
|
||||||
|
|
||||||
if (!armor) {
|
|
||||||
changeKeyPassword.noArmor();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String oldKeyPassword : oldKeyPasswords) {
|
|
||||||
changeKeyPassword.oldKeyPassphrase(oldKeyPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newKeyPassword != null) {
|
|
||||||
changeKeyPassword.newKeyPassphrase(newKeyPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
changeKeyPassword.keys(System.in).writeTo(System.out);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.cli.picocli.commands
|
||||||
|
|
||||||
|
import java.io.IOException
|
||||||
|
import java.lang.RuntimeException
|
||||||
|
import picocli.CommandLine.Command
|
||||||
|
import picocli.CommandLine.Option
|
||||||
|
import sop.cli.picocli.SopCLI
|
||||||
|
import sop.exception.SOPGPException
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
name = "change-key-password",
|
||||||
|
resourceBundle = "msg_change-key-password",
|
||||||
|
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
|
class ChangeKeyPasswordCmd : AbstractSopCmd() {
|
||||||
|
|
||||||
|
@Option(names = ["--no-armor"], negatable = true) var armor: Boolean = true
|
||||||
|
|
||||||
|
@Option(names = ["--old-key-password"], paramLabel = "PASSWORD")
|
||||||
|
var oldKeyPasswords: List<String> = listOf()
|
||||||
|
|
||||||
|
@Option(names = ["--new-key-password"], arity = "0..1", paramLabel = "PASSWORD")
|
||||||
|
var newKeyPassword: String? = null
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val changeKeyPassword =
|
||||||
|
throwIfUnsupportedSubcommand(SopCLI.getSop().changeKeyPassword(), "change-key-password")
|
||||||
|
|
||||||
|
if (!armor) {
|
||||||
|
changeKeyPassword.noArmor()
|
||||||
|
}
|
||||||
|
|
||||||
|
oldKeyPasswords.forEach { changeKeyPassword.oldKeyPassphrase(it) }
|
||||||
|
|
||||||
|
newKeyPassword?.let { changeKeyPassword.newKeyPassphrase(it) }
|
||||||
|
|
||||||
|
try {
|
||||||
|
changeKeyPassword.keys(System.`in`).writeTo(System.out)
|
||||||
|
} catch (e: IOException) {
|
||||||
|
throw RuntimeException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue