mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-14 12:49:44 +02:00
Initial implementation of 'revoke-key' command
This commit is contained in:
parent
ab2e4aa8e7
commit
e6393b44b9
8 changed files with 151 additions and 0 deletions
|
@ -17,6 +17,7 @@ import sop.cli.picocli.commands.GenerateKeyCmd;
|
|||
import sop.cli.picocli.commands.InlineSignCmd;
|
||||
import sop.cli.picocli.commands.InlineVerifyCmd;
|
||||
import sop.cli.picocli.commands.ListProfilesCmd;
|
||||
import sop.cli.picocli.commands.RevokeKeyCmd;
|
||||
import sop.cli.picocli.commands.SignCmd;
|
||||
import sop.cli.picocli.commands.VerifyCmd;
|
||||
import sop.cli.picocli.commands.VersionCmd;
|
||||
|
@ -43,6 +44,7 @@ import java.util.ResourceBundle;
|
|||
InlineSignCmd.class,
|
||||
InlineVerifyCmd.class,
|
||||
ListProfilesCmd.class,
|
||||
RevokeKeyCmd.class,
|
||||
VersionCmd.class,
|
||||
AutoComplete.GenerateCompletion.class
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.cli.picocli.commands;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import sop.Ready;
|
||||
import sop.cli.picocli.SopCLI;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.operation.RevokeKey;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@CommandLine.Command(name = "revoke-key",
|
||||
resourceBundle = "msg_revoke-key",
|
||||
exitCodeOnInvalidInput = 37)
|
||||
public class RevokeKeyCmd extends AbstractSopCmd {
|
||||
|
||||
@CommandLine.Option(names = "--no-armor",
|
||||
negatable = true)
|
||||
boolean armor = true;
|
||||
|
||||
@CommandLine.Option(names = "--with-key-password",
|
||||
paramLabel = "PASSWORD")
|
||||
String withKeyPassword;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
RevokeKey revokeKey = throwIfUnsupportedSubcommand(
|
||||
SopCLI.getSop().revokeKey(), "revoke-key");
|
||||
|
||||
if (!armor) {
|
||||
revokeKey.noArmor();
|
||||
}
|
||||
|
||||
if (withKeyPassword != null) {
|
||||
try {
|
||||
String password = stringFromInputStream(getInput(withKeyPassword));
|
||||
revokeKey.withKeyPassword(password);
|
||||
} catch (SOPGPException.UnsupportedOption e) {
|
||||
String errorMsg = getMsg("sop.error.feature_support.option_not_supported", "--with-key-password");
|
||||
throw new SOPGPException.UnsupportedOption(errorMsg, e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Ready ready;
|
||||
try {
|
||||
ready = revokeKey.keys(System.in);
|
||||
} catch (SOPGPException.KeyIsProtected e) {
|
||||
String errorMsg = getMsg("sop.error.runtime.cannot_unlock_key", "STANDARD_IN");
|
||||
throw new SOPGPException.KeyIsProtected(errorMsg, e);
|
||||
}
|
||||
try {
|
||||
ready.writeTo(System.out);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue