001// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org> 002// 003// SPDX-License-Identifier: Apache-2.0 004 005package sop.exception; 006 007public abstract class SOPGPException extends RuntimeException { 008 009 public SOPGPException() { 010 super(); 011 } 012 013 public SOPGPException(String message) { 014 super(message); 015 } 016 017 public SOPGPException(Throwable e) { 018 super(e); 019 } 020 021 public SOPGPException(String message, Throwable cause) { 022 super(message, cause); 023 } 024 025 public abstract int getExitCode(); 026 027 public static class NoSignature extends SOPGPException { 028 029 public static final int EXIT_CODE = 3; 030 031 public NoSignature() { 032 super("No verifiable signature found."); 033 } 034 035 @Override 036 public int getExitCode() { 037 return EXIT_CODE; 038 } 039 } 040 041 public static class UnsupportedAsymmetricAlgo extends SOPGPException { 042 043 public static final int EXIT_CODE = 13; 044 045 public UnsupportedAsymmetricAlgo(String message, Throwable e) { 046 super(message, e); 047 } 048 049 public UnsupportedAsymmetricAlgo(Throwable e) { 050 super(e); 051 } 052 053 @Override 054 public int getExitCode() { 055 return EXIT_CODE; 056 } 057 } 058 059 public static class CertCannotEncrypt extends SOPGPException { 060 public static final int EXIT_CODE = 17; 061 062 public CertCannotEncrypt(String message, Throwable cause) { 063 super(message, cause); 064 } 065 066 @Override 067 public int getExitCode() { 068 return EXIT_CODE; 069 } 070 } 071 072 public static class CertCannotSign extends Exception { 073 074 } 075 076 public static class MissingArg extends SOPGPException { 077 078 public static final int EXIT_CODE = 19; 079 080 public MissingArg(String s) { 081 super(s); 082 } 083 084 @Override 085 public int getExitCode() { 086 return EXIT_CODE; 087 } 088 } 089 090 public static class IncompleteVerification extends SOPGPException { 091 092 public static final int EXIT_CODE = 23; 093 094 public IncompleteVerification(String message) { 095 super(message); 096 } 097 098 @Override 099 public int getExitCode() { 100 return EXIT_CODE; 101 } 102 } 103 104 public static class CannotDecrypt extends SOPGPException { 105 106 public static final int EXIT_CODE = 29; 107 108 @Override 109 public int getExitCode() { 110 return EXIT_CODE; 111 } 112 } 113 114 public static class PasswordNotHumanReadable extends SOPGPException { 115 116 public static final int EXIT_CODE = 31; 117 118 @Override 119 public int getExitCode() { 120 return EXIT_CODE; 121 } 122 } 123 124 public static class UnsupportedOption extends SOPGPException { 125 126 public static final int EXIT_CODE = 37; 127 128 public UnsupportedOption(String message) { 129 super(message); 130 } 131 132 public UnsupportedOption(String message, Throwable cause) { 133 super(message, cause); 134 } 135 136 @Override 137 public int getExitCode() { 138 return EXIT_CODE; 139 } 140 } 141 142 public static class BadData extends SOPGPException { 143 144 public static final int EXIT_CODE = 41; 145 146 public BadData(Throwable e) { 147 super(e); 148 } 149 150 public BadData(String message, BadData badData) { 151 super(message, badData); 152 } 153 154 @Override 155 public int getExitCode() { 156 return EXIT_CODE; 157 } 158 } 159 160 public static class ExpectedText extends SOPGPException { 161 162 public static final int EXIT_CODE = 53; 163 164 @Override 165 public int getExitCode() { 166 return EXIT_CODE; 167 } 168 } 169 170 public static class OutputExists extends SOPGPException { 171 172 public static final int EXIT_CODE = 59; 173 174 public OutputExists(String message) { 175 super(message); 176 } 177 178 @Override 179 public int getExitCode() { 180 return EXIT_CODE; 181 } 182 } 183 184 public static class MissingInput extends SOPGPException { 185 186 public static final int EXIT_CODE = 61; 187 188 public MissingInput(String message, Throwable cause) { 189 super(message, cause); 190 } 191 192 @Override 193 public int getExitCode() { 194 return EXIT_CODE; 195 } 196 } 197 198 public static class KeyIsProtected extends SOPGPException { 199 200 public static final int EXIT_CODE = 67; 201 202 public KeyIsProtected() { 203 super(); 204 } 205 206 public KeyIsProtected(String message, Throwable cause) { 207 super(message, cause); 208 } 209 210 @Override 211 public int getExitCode() { 212 return EXIT_CODE; 213 } 214 } 215 216 public static class UnsupportedSubcommand extends SOPGPException { 217 218 public static final int EXIT_CODE = 69; 219 220 public UnsupportedSubcommand(String message) { 221 super(message); 222 } 223 224 @Override 225 public int getExitCode() { 226 return EXIT_CODE; 227 } 228 } 229 230 public static class UnsupportedSpecialPrefix extends SOPGPException { 231 232 public static final int EXIT_CODE = 71; 233 234 @Override 235 public int getExitCode() { 236 return EXIT_CODE; 237 } 238 } 239 240 241 public static class AmbiguousInput extends SOPGPException { 242 243 public static final int EXIT_CODE = 73; 244 245 public AmbiguousInput(String message) { 246 super(message); 247 } 248 249 @Override 250 public int getExitCode() { 251 return EXIT_CODE; 252 } 253 } 254}