2021-10-07 15:48:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
package sop.exception;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public abstract class SOPGPException extends RuntimeException {
|
2021-07-15 16:55:13 +02:00
|
|
|
|
|
|
|
public SOPGPException() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public SOPGPException(String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SOPGPException(Throwable e) {
|
|
|
|
super(e);
|
|
|
|
}
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public SOPGPException(String message, Throwable cause) {
|
|
|
|
super(message, cause);
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract int getExitCode();
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* No acceptable signatures found (sop verify).
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class NoSignature extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 3;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public NoSignature() {
|
|
|
|
super("No verifiable signature found.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Asymmetric algorithm unsupported (sop encrypt).
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class UnsupportedAsymmetricAlgo extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 13;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public UnsupportedAsymmetricAlgo(String message, Throwable e) {
|
|
|
|
super(message, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Certificate not encryption capable (e,g, expired, revoked, unacceptable usage).
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class CertCannotEncrypt extends SOPGPException {
|
|
|
|
public static final int EXIT_CODE = 17;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public CertCannotEncrypt(String message, Throwable cause) {
|
|
|
|
super(message, cause);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Missing required argument.
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class MissingArg extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 19;
|
|
|
|
|
|
|
|
public MissingArg(String s) {
|
|
|
|
super(s);
|
|
|
|
}
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Incomplete verification instructions (sop decrypt).
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class IncompleteVerification extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 23;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public IncompleteVerification(String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Unable to decrypt (sop decrypt).
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class CannotDecrypt extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 29;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Non-UTF-8 or otherwise unreliable password (sop encrypt).
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class PasswordNotHumanReadable extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 31;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Unsupported option.
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class UnsupportedOption extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 37;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public UnsupportedOption(String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public UnsupportedOption(String message, Throwable cause) {
|
|
|
|
super(message, cause);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Invalid data type (no secret key where KEYS expected, etc.).
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class BadData extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 41;
|
|
|
|
|
|
|
|
public BadData(Throwable e) {
|
|
|
|
super(e);
|
|
|
|
}
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public BadData(String message, BadData badData) {
|
|
|
|
super(message, badData);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Non-Text input where text expected.
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class ExpectedText extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 53;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Output file already exists.
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public static class OutputExists extends SOPGPException {
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public static final int EXIT_CODE = 59;
|
|
|
|
|
|
|
|
public OutputExists(String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
2021-07-15 16:55:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Input file does not exist.
|
|
|
|
*/
|
2021-07-19 18:20:52 +02:00
|
|
|
public static class MissingInput extends SOPGPException {
|
2021-07-15 16:55:13 +02:00
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public static final int EXIT_CODE = 61;
|
|
|
|
|
|
|
|
public MissingInput(String message, Throwable cause) {
|
|
|
|
super(message, cause);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
2021-07-15 16:55:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* A KEYS input is protected (locked) with a password, and sop cannot unlock it.
|
|
|
|
*/
|
2021-07-19 18:20:52 +02:00
|
|
|
public static class KeyIsProtected extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 67;
|
|
|
|
|
|
|
|
public KeyIsProtected() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public KeyIsProtected(String message, Throwable cause) {
|
|
|
|
super(message, cause);
|
|
|
|
}
|
2021-07-15 16:55:13 +02:00
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
@Override
|
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
2021-07-15 16:55:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* Unsupported subcommand.
|
|
|
|
*/
|
2021-07-19 18:20:52 +02:00
|
|
|
public static class UnsupportedSubcommand extends SOPGPException {
|
2021-07-15 16:55:13 +02:00
|
|
|
|
|
|
|
public static final int EXIT_CODE = 69;
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
public UnsupportedSubcommand(String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* An indirect parameter is a special designator (it starts with @), but sop does not know how to handle the prefix.
|
|
|
|
*/
|
2021-07-19 18:20:52 +02:00
|
|
|
public static class UnsupportedSpecialPrefix extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 71;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 14:28:36 +01:00
|
|
|
/**
|
|
|
|
* A indirect input parameter is a special designator (it starts with @),
|
|
|
|
* and a filename matching the designator is actually present.
|
|
|
|
*/
|
2021-07-19 18:20:52 +02:00
|
|
|
public static class AmbiguousInput extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 73;
|
|
|
|
|
2021-08-19 16:44:29 +02:00
|
|
|
public AmbiguousInput(String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
|
2021-07-19 18:20:52 +02:00
|
|
|
@Override
|
2021-07-15 16:55:13 +02:00
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
2022-01-07 14:28:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Key not signature-capable (e.g. expired, revoked, unacceptable usage flags)
|
|
|
|
* (sop sign and sop encrypt with --sign-with).
|
|
|
|
*/
|
|
|
|
public static class KeyCannotSign extends SOPGPException {
|
|
|
|
|
|
|
|
public static final int EXIT_CODE = 79;
|
|
|
|
|
|
|
|
public KeyCannotSign() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public KeyCannotSign(String s, KeyCannotSign keyCannotSign) {
|
|
|
|
super(s, keyCannotSign);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getExitCode() {
|
|
|
|
return EXIT_CODE;
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 16:55:13 +02:00
|
|
|
}
|