commit | author | age
|
884add
|
1 |
<?php |
T |
2 |
|
|
3 |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|
4 |
|
|
5 |
/** |
|
6 |
* Various exception handling classes for Crypt_GPG |
|
7 |
* |
|
8 |
* Crypt_GPG provides an object oriented interface to GNU Privacy |
|
9 |
* Guard (GPG). It requires the GPG executable to be on the system. |
|
10 |
* |
|
11 |
* This file contains various exception classes used by the Crypt_GPG package. |
|
12 |
* |
|
13 |
* PHP version 5 |
|
14 |
* |
|
15 |
* LICENSE: |
|
16 |
* |
|
17 |
* This library is free software; you can redistribute it and/or modify |
|
18 |
* it under the terms of the GNU Lesser General Public License as |
|
19 |
* published by the Free Software Foundation; either version 2.1 of the |
|
20 |
* License, or (at your option) any later version. |
|
21 |
* |
|
22 |
* This library is distributed in the hope that it will be useful, |
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
25 |
* Lesser General Public License for more details. |
|
26 |
* |
|
27 |
* You should have received a copy of the GNU Lesser General Public |
|
28 |
* License along with this library; if not, write to the Free Software |
|
29 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
30 |
* |
|
31 |
* @category Encryption |
|
32 |
* @package Crypt_GPG |
|
33 |
* @author Nathan Fredrickson <nathan@silverorange.com> |
|
34 |
* @author Michael Gauthier <mike@silverorange.com> |
|
35 |
* @copyright 2005 silverorange |
|
36 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
37 |
* @version CVS: $Id: Exceptions.php 273745 2009-01-18 05:24:25Z gauthierm $ |
|
38 |
* @link http://pear.php.net/package/Crypt_GPG |
|
39 |
*/ |
|
40 |
|
|
41 |
/** |
|
42 |
* PEAR Exception handler and base class |
|
43 |
*/ |
|
44 |
require_once 'PEAR/Exception.php'; |
|
45 |
|
|
46 |
// {{{ class Crypt_GPG_Exception |
|
47 |
|
|
48 |
/** |
|
49 |
* An exception thrown by the Crypt_GPG package |
|
50 |
* |
|
51 |
* @category Encryption |
|
52 |
* @package Crypt_GPG |
|
53 |
* @author Michael Gauthier <mike@silverorange.com> |
|
54 |
* @copyright 2005 silverorange |
|
55 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
56 |
* @link http://pear.php.net/package/Crypt_GPG |
|
57 |
*/ |
|
58 |
class Crypt_GPG_Exception extends PEAR_Exception |
|
59 |
{ |
|
60 |
} |
|
61 |
|
|
62 |
// }}} |
|
63 |
// {{{ class Crypt_GPG_FileException |
|
64 |
|
|
65 |
/** |
|
66 |
* An exception thrown when a file is used in ways it cannot be used |
|
67 |
* |
|
68 |
* For example, if an output file is specified and the file is not writeable, or |
|
69 |
* if an input file is specified and the file is not readable, this exception |
|
70 |
* is thrown. |
|
71 |
* |
|
72 |
* @category Encryption |
|
73 |
* @package Crypt_GPG |
|
74 |
* @author Michael Gauthier <mike@silverorange.com> |
|
75 |
* @copyright 2007-2008 silverorange |
|
76 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
77 |
* @link http://pear.php.net/package/Crypt_GPG |
|
78 |
*/ |
|
79 |
class Crypt_GPG_FileException extends Crypt_GPG_Exception |
|
80 |
{ |
|
81 |
// {{{ private class properties |
|
82 |
|
|
83 |
/** |
|
84 |
* The name of the file that caused this exception |
|
85 |
* |
|
86 |
* @var string |
|
87 |
*/ |
|
88 |
private $_filename = ''; |
|
89 |
|
|
90 |
// }}} |
|
91 |
// {{{ __construct() |
|
92 |
|
|
93 |
/** |
|
94 |
* Creates a new Crypt_GPG_FileException |
|
95 |
* |
|
96 |
* @param string $message an error message. |
|
97 |
* @param integer $code a user defined error code. |
|
98 |
* @param string $filename the name of the file that caused this exception. |
|
99 |
*/ |
|
100 |
public function __construct($message, $code = 0, $filename = '') |
|
101 |
{ |
|
102 |
$this->_filename = $filename; |
|
103 |
parent::__construct($message, $code); |
|
104 |
} |
|
105 |
|
|
106 |
// }}} |
|
107 |
// {{{ getFilename() |
|
108 |
|
|
109 |
/** |
|
110 |
* Returns the filename of the file that caused this exception |
|
111 |
* |
|
112 |
* @return string the filename of the file that caused this exception. |
|
113 |
* |
|
114 |
* @see Crypt_GPG_FileException::$_filename |
|
115 |
*/ |
|
116 |
public function getFilename() |
|
117 |
{ |
|
118 |
return $this->_filename; |
|
119 |
} |
|
120 |
|
|
121 |
// }}} |
|
122 |
} |
|
123 |
|
|
124 |
// }}} |
|
125 |
// {{{ class Crypt_GPG_OpenSubprocessException |
|
126 |
|
|
127 |
/** |
|
128 |
* An exception thrown when the GPG subprocess cannot be opened |
|
129 |
* |
|
130 |
* This exception is thrown when the {@link Crypt_GPG_Engine} tries to open a |
|
131 |
* new subprocess and fails. |
|
132 |
* |
|
133 |
* @category Encryption |
|
134 |
* @package Crypt_GPG |
|
135 |
* @author Michael Gauthier <mike@silverorange.com> |
|
136 |
* @copyright 2005 silverorange |
|
137 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
138 |
* @link http://pear.php.net/package/Crypt_GPG |
|
139 |
*/ |
|
140 |
class Crypt_GPG_OpenSubprocessException extends Crypt_GPG_Exception |
|
141 |
{ |
|
142 |
// {{{ private class properties |
|
143 |
|
|
144 |
/** |
|
145 |
* The command used to try to open the subprocess |
|
146 |
* |
|
147 |
* @var string |
|
148 |
*/ |
|
149 |
private $_command = ''; |
|
150 |
|
|
151 |
// }}} |
|
152 |
// {{{ __construct() |
|
153 |
|
|
154 |
/** |
|
155 |
* Creates a new Crypt_GPG_OpenSubprocessException |
|
156 |
* |
|
157 |
* @param string $message an error message. |
|
158 |
* @param integer $code a user defined error code. |
|
159 |
* @param string $command the command that was called to open the |
|
160 |
* new subprocess. |
|
161 |
* |
|
162 |
* @see Crypt_GPG::_openSubprocess() |
|
163 |
*/ |
|
164 |
public function __construct($message, $code = 0, $command = '') |
|
165 |
{ |
|
166 |
$this->_command = $command; |
|
167 |
parent::__construct($message, $code); |
|
168 |
} |
|
169 |
|
|
170 |
// }}} |
|
171 |
// {{{ getCommand() |
|
172 |
|
|
173 |
/** |
|
174 |
* Returns the contents of the internal _command property |
|
175 |
* |
|
176 |
* @return string the command used to open the subprocess. |
|
177 |
* |
|
178 |
* @see Crypt_GPG_OpenSubprocessException::$_command |
|
179 |
*/ |
|
180 |
public function getCommand() |
|
181 |
{ |
|
182 |
return $this->_command; |
|
183 |
} |
|
184 |
|
|
185 |
// }}} |
|
186 |
} |
|
187 |
|
|
188 |
// }}} |
|
189 |
// {{{ class Crypt_GPG_InvalidOperationException |
|
190 |
|
|
191 |
/** |
|
192 |
* An exception thrown when an invalid GPG operation is attempted |
|
193 |
* |
|
194 |
* @category Encryption |
|
195 |
* @package Crypt_GPG |
|
196 |
* @author Michael Gauthier <mike@silverorange.com> |
|
197 |
* @copyright 2008 silverorange |
|
198 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
199 |
* @link http://pear.php.net/package/Crypt_GPG |
|
200 |
*/ |
|
201 |
class Crypt_GPG_InvalidOperationException extends Crypt_GPG_Exception |
|
202 |
{ |
|
203 |
// {{{ private class properties |
|
204 |
|
|
205 |
/** |
|
206 |
* The attempted operation |
|
207 |
* |
|
208 |
* @var string |
|
209 |
*/ |
|
210 |
private $_operation = ''; |
|
211 |
|
|
212 |
// }}} |
|
213 |
// {{{ __construct() |
|
214 |
|
|
215 |
/** |
|
216 |
* Creates a new Crypt_GPG_OpenSubprocessException |
|
217 |
* |
|
218 |
* @param string $message an error message. |
|
219 |
* @param integer $code a user defined error code. |
|
220 |
* @param string $operation the operation. |
|
221 |
*/ |
|
222 |
public function __construct($message, $code = 0, $operation = '') |
|
223 |
{ |
|
224 |
$this->_operation = $operation; |
|
225 |
parent::__construct($message, $code); |
|
226 |
} |
|
227 |
|
|
228 |
// }}} |
|
229 |
// {{{ getOperation() |
|
230 |
|
|
231 |
/** |
|
232 |
* Returns the contents of the internal _operation property |
|
233 |
* |
|
234 |
* @return string the attempted operation. |
|
235 |
* |
|
236 |
* @see Crypt_GPG_InvalidOperationException::$_operation |
|
237 |
*/ |
|
238 |
public function getOperation() |
|
239 |
{ |
|
240 |
return $this->_operation; |
|
241 |
} |
|
242 |
|
|
243 |
// }}} |
|
244 |
} |
|
245 |
|
|
246 |
// }}} |
|
247 |
// {{{ class Crypt_GPG_KeyNotFoundException |
|
248 |
|
|
249 |
/** |
|
250 |
* An exception thrown when Crypt_GPG fails to find the key for various |
|
251 |
* operations |
|
252 |
* |
|
253 |
* @category Encryption |
|
254 |
* @package Crypt_GPG |
|
255 |
* @author Michael Gauthier <mike@silverorange.com> |
|
256 |
* @copyright 2005 silverorange |
|
257 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
258 |
* @link http://pear.php.net/package/Crypt_GPG |
|
259 |
*/ |
|
260 |
class Crypt_GPG_KeyNotFoundException extends Crypt_GPG_Exception |
|
261 |
{ |
|
262 |
// {{{ private class properties |
|
263 |
|
|
264 |
/** |
|
265 |
* The key identifier that was searched for |
|
266 |
* |
|
267 |
* @var string |
|
268 |
*/ |
|
269 |
private $_keyId = ''; |
|
270 |
|
|
271 |
// }}} |
|
272 |
// {{{ __construct() |
|
273 |
|
|
274 |
/** |
|
275 |
* Creates a new Crypt_GPG_KeyNotFoundException |
|
276 |
* |
|
277 |
* @param string $message an error message. |
|
278 |
* @param integer $code a user defined error code. |
|
279 |
* @param string $keyId the key identifier of the key. |
|
280 |
*/ |
|
281 |
public function __construct($message, $code = 0, $keyId= '') |
|
282 |
{ |
|
283 |
$this->_keyId = $keyId; |
|
284 |
parent::__construct($message, $code); |
|
285 |
} |
|
286 |
|
|
287 |
// }}} |
|
288 |
// {{{ getKeyId() |
|
289 |
|
|
290 |
/** |
|
291 |
* Gets the key identifier of the key that was not found |
|
292 |
* |
|
293 |
* @return string the key identifier of the key that was not found. |
|
294 |
*/ |
|
295 |
public function getKeyId() |
|
296 |
{ |
|
297 |
return $this->_keyId; |
|
298 |
} |
|
299 |
|
|
300 |
// }}} |
|
301 |
} |
|
302 |
|
|
303 |
// }}} |
|
304 |
// {{{ class Crypt_GPG_NoDataException |
|
305 |
|
|
306 |
/** |
|
307 |
* An exception thrown when Crypt_GPG cannot find valid data for various |
|
308 |
* operations |
|
309 |
* |
|
310 |
* @category Encryption |
|
311 |
* @package Crypt_GPG |
|
312 |
* @author Michael Gauthier <mike@silverorange.com> |
|
313 |
* @copyright 2006 silverorange |
|
314 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
315 |
* @link http://pear.php.net/package/Crypt_GPG |
|
316 |
*/ |
|
317 |
class Crypt_GPG_NoDataException extends Crypt_GPG_Exception |
|
318 |
{ |
|
319 |
} |
|
320 |
|
|
321 |
// }}} |
|
322 |
// {{{ class Crypt_GPG_BadPassphraseException |
|
323 |
|
|
324 |
/** |
|
325 |
* An exception thrown when a required passphrase is incorrect or missing |
|
326 |
* |
|
327 |
* @category Encryption |
|
328 |
* @package Crypt_GPG |
|
329 |
* @author Michael Gauthier <mike@silverorange.com> |
|
330 |
* @copyright 2006-2008 silverorange |
|
331 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
332 |
* @link http://pear.php.net/package/Crypt_GPG |
|
333 |
*/ |
|
334 |
class Crypt_GPG_BadPassphraseException extends Crypt_GPG_Exception |
|
335 |
{ |
|
336 |
// {{{ private class properties |
|
337 |
|
|
338 |
/** |
|
339 |
* Keys for which the passhprase is missing |
|
340 |
* |
|
341 |
* This contains primary user ids indexed by sub-key id. |
|
342 |
* |
|
343 |
* @var array |
|
344 |
*/ |
|
345 |
private $_missingPassphrases = array(); |
|
346 |
|
|
347 |
/** |
|
348 |
* Keys for which the passhprase is incorrect |
|
349 |
* |
|
350 |
* This contains primary user ids indexed by sub-key id. |
|
351 |
* |
|
352 |
* @var array |
|
353 |
*/ |
|
354 |
private $_badPassphrases = array(); |
|
355 |
|
|
356 |
// }}} |
|
357 |
// {{{ __construct() |
|
358 |
|
|
359 |
/** |
|
360 |
* Creates a new Crypt_GPG_BadPassphraseException |
|
361 |
* |
|
362 |
* @param string $message an error message. |
|
363 |
* @param integer $code a user defined error code. |
|
364 |
* @param string $badPassphrases an array containing user ids of keys |
|
365 |
* for which the passphrase is incorrect. |
|
366 |
* @param string $missingPassphrases an array containing user ids of keys |
|
367 |
* for which the passphrase is missing. |
|
368 |
*/ |
|
369 |
public function __construct($message, $code = 0, |
|
370 |
array $badPassphrases = array(), array $missingPassphrases = array() |
|
371 |
) { |
|
372 |
$this->_badPassphrases = $badPassphrases; |
|
373 |
$this->_missingPassphrases = $missingPassphrases; |
|
374 |
|
|
375 |
parent::__construct($message, $code); |
|
376 |
} |
|
377 |
|
|
378 |
// }}} |
|
379 |
// {{{ getBadPassphrases() |
|
380 |
|
|
381 |
/** |
|
382 |
* Gets keys for which the passhprase is incorrect |
|
383 |
* |
|
384 |
* @return array an array of keys for which the passphrase is incorrect. |
|
385 |
* The array contains primary user ids indexed by the sub-key |
|
386 |
* id. |
|
387 |
*/ |
|
388 |
public function getBadPassphrases() |
|
389 |
{ |
|
390 |
return $this->_badPassphrases; |
|
391 |
} |
|
392 |
|
|
393 |
// }}} |
|
394 |
// {{{ getMissingPassphrases() |
|
395 |
|
|
396 |
/** |
|
397 |
* Gets keys for which the passhprase is missing |
|
398 |
* |
|
399 |
* @return array an array of keys for which the passphrase is missing. |
|
400 |
* The array contains primary user ids indexed by the sub-key |
|
401 |
* id. |
|
402 |
*/ |
|
403 |
public function getMissingPassphrases() |
|
404 |
{ |
|
405 |
return $this->_missingPassphrases; |
|
406 |
} |
|
407 |
|
|
408 |
// }}} |
|
409 |
} |
|
410 |
|
|
411 |
// }}} |
|
412 |
// {{{ class Crypt_GPG_DeletePrivateKeyException |
|
413 |
|
|
414 |
/** |
|
415 |
* An exception thrown when an attempt is made to delete public key that has an |
|
416 |
* associated private key on the keyring |
|
417 |
* |
|
418 |
* @category Encryption |
|
419 |
* @package Crypt_GPG |
|
420 |
* @author Michael Gauthier <mike@silverorange.com> |
|
421 |
* @copyright 2008 silverorange |
|
422 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
|
423 |
* @link http://pear.php.net/package/Crypt_GPG |
|
424 |
*/ |
|
425 |
class Crypt_GPG_DeletePrivateKeyException extends Crypt_GPG_Exception |
|
426 |
{ |
|
427 |
// {{{ private class properties |
|
428 |
|
|
429 |
/** |
|
430 |
* The key identifier the deletion attempt was made upon |
|
431 |
* |
|
432 |
* @var string |
|
433 |
*/ |
|
434 |
private $_keyId = ''; |
|
435 |
|
|
436 |
// }}} |
|
437 |
// {{{ __construct() |
|
438 |
|
|
439 |
/** |
|
440 |
* Creates a new Crypt_GPG_DeletePrivateKeyException |
|
441 |
* |
|
442 |
* @param string $message an error message. |
|
443 |
* @param integer $code a user defined error code. |
|
444 |
* @param string $keyId the key identifier of the public key that was |
|
445 |
* attempted to delete. |
|
446 |
* |
|
447 |
* @see Crypt_GPG::deletePublicKey() |
|
448 |
*/ |
|
449 |
public function __construct($message, $code = 0, $keyId = '') |
|
450 |
{ |
|
451 |
$this->_keyId = $keyId; |
|
452 |
parent::__construct($message, $code); |
|
453 |
} |
|
454 |
|
|
455 |
// }}} |
|
456 |
// {{{ getKeyId() |
|
457 |
|
|
458 |
/** |
|
459 |
* Gets the key identifier of the key that was not found |
|
460 |
* |
|
461 |
* @return string the key identifier of the key that was not found. |
|
462 |
*/ |
|
463 |
public function getKeyId() |
|
464 |
{ |
|
465 |
return $this->_keyId; |
|
466 |
} |
|
467 |
|
|
468 |
// }}} |
|
469 |
} |
|
470 |
|
|
471 |
// }}} |
|
472 |
|
|
473 |
?> |