3 """Assuan errors as defined in `libgpg-error`_.
5 The Assuan_ docs_ suggest these error codes.
7 .. _libgpg-error: http://www.gnupg.org/related_software/libgpg-error/
9 http://www.gnupg.org/documentation/manuals/assuan/Server-responses.html
10 .. _docs: http://www.gnupg.org/documentation/manuals/assuan/Error-codes.html
13 MESSAGE = { # extracted from libgpg-error-1.10/src/err-codes.h and gpg-error.h
17 3: 'Unknown version in packet',
18 4: 'Invalid public key algorithm',
19 5: 'Invalid digest algorithm',
26 12: 'Invalid cipher algorithm',
32 18: 'Wrong secret key used',
33 19: 'Bad session key',
34 20: 'Unknown compression algorithm',
35 21: 'Number is not prime',
36 22: 'Invalid encoding method',
37 23: 'Invalid encryption scheme',
38 24: 'Invalid signature scheme',
39 25: 'Invalid attribute',
42 28: 'Value not found',
45 31: 'Invalid passphrase',
46 32: 'Invalid signature class',
47 33: 'Resources exhausted',
48 34: 'Invalid keyring',
50 36: 'Bad certificate',
51 37: 'Invalid user ID',
52 38: 'Unexpected error',
54 40: 'Keyserver error',
55 41: 'Wrong public key algorithm',
56 42: 'Tribute to D. A.',
57 43: 'Weak encryption key',
58 44: 'Invalid key length',
59 45: 'Invalid argument',
60 46: 'Syntax error in URI',
64 50: 'Selftest failed',
65 51: 'Data not encrypted',
66 52: 'Data not processed',
67 53: 'Unusable public key',
68 54: 'Unusable secret key',
70 56: 'Bad certificate chain',
71 57: 'Missing certificate',
75 61: 'Invalid operation code',
80 66: 'Provided object is too short',
81 67: 'Provided object is too large',
82 68: 'Missing item in object',
83 69: 'Not implemented',
84 70: 'Conflicting use',
85 71: 'Invalid cipher mode',
88 74: 'Result truncated',
89 75: 'Incomplete line',
90 76: 'Invalid response',
91 77: 'No agent running',
94 80: 'Unspecific Assuan server fault',
95 81: 'General Assuan error',
96 82: 'Invalid session key',
97 83: 'Invalid S-expression',
98 84: 'Unsupported algorithm',
100 86: 'pinentry error',
104 90: 'Invalid parameter',
108 94: 'Certificate revoked',
113 99: 'Operation cancelled',
114 100: 'Bad CA certificate',
115 101: 'Certificate expired',
116 102: 'Certificate too young',
117 103: 'Unsupported certificate',
118 104: 'Unknown S-expression',
119 105: 'Unsupported protection',
120 106: 'Corrupted protection',
121 107: 'Ambiguous name',
123 109: 'Card reset required',
126 112: 'Card not present',
127 113: 'No PKCS15 application',
128 114: 'Not confirmed',
129 115: 'Configuration error',
130 116: 'No policy match',
131 117: 'Invalid index',
133 119: 'No SmartCard daemon',
134 120: 'SmartCard daemon error',
135 121: 'Unsupported protocol',
136 122: 'Bad PIN method',
137 123: 'Card not initialized',
138 124: 'Unsupported operation',
139 125: 'Wrong key usage',
140 126: 'Nothing found',
141 127: 'Wrong blob type',
142 128: 'Missing value',
143 129: 'Hardware problem',
145 131: 'Conditions of use not satisfied',
146 132: 'PINs are not synced',
150 136: 'Element not found',
151 137: 'Identifier not found',
153 139: 'Invalid length',
154 140: 'Invalid key info',
155 141: 'Unexpected tag',
156 142: 'Not DER encoded',
157 143: 'No CMS object',
158 144: 'Invalid CMS object',
159 145: 'Unknown CMS object',
160 146: 'Unsupported CMS object',
161 147: 'Unsupported encoding',
162 148: 'Unsupported CMS version',
163 149: 'Unknown algorithm',
164 150: 'Invalid crypto engine',
165 151: 'Public key not trusted',
166 152: 'Decryption failed',
168 154: 'Signature expired',
169 155: 'Encoding problem',
170 156: 'Invalid state',
171 157: 'Duplicated value',
172 158: 'Missing action',
173 159: 'ASN.1 module not found',
174 160: 'Invalid OID string',
176 162: 'Invalid CRL object',
177 163: 'Unsupported CRL version',
178 164: 'Invalid certificate object',
180 166: 'A locale function failed',
182 168: 'Protocol violation',
184 170: 'Invalid request',
185 171: 'Unknown extension',
186 172: 'Unknown critical extension',
188 174: 'Unknown option',
189 175: 'Unknown command',
190 176: 'Not operational',
191 177: 'No passphrase given',
194 180: 'No crypto engine',
196 182: 'Too many objects',
197 183: 'Limit reached',
198 184: 'Not initialized',
199 185: 'Missing issuer certificate',
200 198: 'Operation fully cancelled',
201 199: 'Operation not yet finished',
202 200: 'Buffer too short',
203 201: 'Invalid length specifier in S-expression',
204 202: 'String too long in S-expression',
205 203: 'Unmatched parentheses in S-expression',
206 204: 'S-expression not canonical',
207 205: 'Bad character in S-expression',
208 206: 'Bad quotation in S-expression',
209 207: 'Zero prefix in S-expression',
210 208: 'Nested display hints in S-expression',
211 209: 'Unmatched display hints',
212 210: 'Unexpected reserved punctuation in S-expression',
213 211: 'Bad hexadecimal character in S-expression',
214 212: 'Odd hexadecimal numbers in S-expression',
215 213: 'Bad octal character in S-expression',
216 257: 'General IPC error',
217 258: 'IPC accept call failed',
218 259: 'IPC connect call failed',
219 260: 'Invalid IPC response',
220 261: 'Invalid value passed to IPC',
221 262: 'Incomplete line passed to IPC',
222 263: 'Line passed to IPC too long',
223 264: 'Nested IPC commands',
224 265: 'No data callback in IPC',
225 266: 'No inquire callback in IPC',
226 267: 'Not an IPC server',
227 268: 'Not an IPC client',
228 269: 'Problem starting IPC server',
229 270: 'IPC read error',
230 271: 'IPC write error',
231 273: 'Too much data for IPC layer',
232 274: 'Unexpected IPC command',
233 275: 'Unknown IPC command',
234 276: 'IPC syntax error',
235 277: 'IPC call has been cancelled',
236 278: 'No input source for IPC',
237 279: 'No output source for IPC',
238 280: 'IPC parameter error',
239 281: 'Unknown IPC inquire',
240 1024: 'User defined error code 1',
241 1025: 'User defined error code 2',
242 1026: 'User defined error code 3',
243 1027: 'User defined error code 4',
244 1028: 'User defined error code 5',
245 1029: 'User defined error code 6',
246 1030: 'User defined error code 7',
247 1031: 'User defined error code 8',
248 1032: 'User defined error code 9',
249 1033: 'User defined error code 10',
250 1034: 'User defined error code 11',
251 1035: 'User defined error code 12',
252 1036: 'User defined error code 13',
253 1037: 'User defined error code 14',
254 1038: 'User defined error code 15',
255 1039: 'User defined error code 16',
256 16381: 'System error w/o errno',
257 16382: 'Unknown system error',
258 16383: 'End of file',
260 UNKNOWN = 'Unknown error code'
262 CODE = dict((message,code) for code,message in MESSAGE.items())
264 # TODO: system errors (GPG_ERR_E2BIG = GPG_ERR_SYSTEM_ERROR | 0, etc.)
266 class AssuanError (Exception):
269 >>> e = AssuanError(1)
272 >>> e = AssuanError(1024, 'testing!')
275 >>> e = AssuanError(message='Unknown packet')
279 def __init__(self, code=None, message=None):
280 if code is None and message is None:
281 raise ValueError('missing both `code` and `message`')
283 message = MESSAGE[code]
285 code = CODE.get(message, UNKNOWN)
287 self.message = message
288 super(AssuanError, self).__init__('{} {}'.format(code, message))