mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-22 15:12:06 +01:00
Kotlin conversion: DearmorCmd
This commit is contained in:
parent
49120c5da8
commit
688b8043a2
2 changed files with 37 additions and 47 deletions
|
@ -1,47 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 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.Dearmor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@CommandLine.Command(name = "dearmor",
|
||||
resourceBundle = "msg_dearmor",
|
||||
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||
public class DearmorCmd extends AbstractSopCmd {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Dearmor dearmor = throwIfUnsupportedSubcommand(
|
||||
SopCLI.getSop().dearmor(), "dearmor");
|
||||
|
||||
try {
|
||||
dearmor.data(System.in)
|
||||
.writeTo(System.out);
|
||||
} catch (SOPGPException.BadData e) {
|
||||
String errorMsg = getMsg("sop.error.input.stdin_not_openpgp_data");
|
||||
throw new SOPGPException.BadData(errorMsg, e);
|
||||
} catch (IOException e) {
|
||||
String msg = e.getMessage();
|
||||
if (msg == null) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
String errorMsg = getMsg("sop.error.input.stdin_not_openpgp_data");
|
||||
if (msg.equals("invalid armor") ||
|
||||
msg.equals("invalid armor header") ||
|
||||
msg.equals("inconsistent line endings in headers") ||
|
||||
msg.startsWith("unable to decode base64 data")) {
|
||||
throw new SOPGPException.BadData(errorMsg, e);
|
||||
}
|
||||
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package sop.cli.picocli.commands
|
||||
|
||||
import java.io.IOException
|
||||
import picocli.CommandLine.Command
|
||||
import sop.cli.picocli.SopCLI
|
||||
import sop.exception.SOPGPException
|
||||
import sop.exception.SOPGPException.BadData
|
||||
|
||||
@Command(
|
||||
name = "dearmor",
|
||||
resourceBundle = "msg_dearmor",
|
||||
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||
class DearmorCmd : AbstractSopCmd() {
|
||||
|
||||
override fun run() {
|
||||
val dearmor = throwIfUnsupportedSubcommand(SopCLI.getSop().dearmor(), "dearmor")
|
||||
|
||||
try {
|
||||
dearmor.data(System.`in`).writeTo(System.out)
|
||||
} catch (badData: BadData) {
|
||||
val errorMsg = getMsg("sop.error.input.stdin_not_openpgp_data")
|
||||
throw BadData(errorMsg, badData)
|
||||
} catch (e: IOException) {
|
||||
e.message?.let {
|
||||
val errorMsg = getMsg("sop.error.input.stdin_not_openpgp_data")
|
||||
if (it == "invalid armor" ||
|
||||
it == "invalid armor header" ||
|
||||
it == "inconsistent line endings in headers" ||
|
||||
it.startsWith("unable to decode base64 data")) {
|
||||
throw BadData(errorMsg, e)
|
||||
}
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
?: throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue