Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| EncryptionException | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| forEncryptionFailure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forDecryptionFailure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Security\Encryption; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use RuntimeException; |
| 12 | |
| 13 | /** |
| 14 | * Enterprise Encryption and Decryption Failure Exception. |
| 15 | * |
| 16 | * Thrown when symmetric encryption, payload unpacking, or authenticated decryption fails. |
| 17 | * |
| 18 | * @package App\Core\Security\Encryption |
| 19 | */ |
| 20 | final class EncryptionException extends RuntimeException |
| 21 | { |
| 22 | /** |
| 23 | * Creates an exception for encryption failure. |
| 24 | * |
| 25 | * @param string $reason Failure explanation. |
| 26 | * @return self New exception instance. |
| 27 | */ |
| 28 | public static function forEncryptionFailure(string $reason = 'Encryption operation failed.'): self |
| 29 | { |
| 30 | return new self($reason); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Creates an exception for decryption authentication mismatch or corruption. |
| 35 | * |
| 36 | * @param string $reason Failure explanation. |
| 37 | * @return self New exception instance. |
| 38 | */ |
| 39 | public static function forDecryptionFailure( |
| 40 | string $reason = 'Decryption failed: integrity authentication tag mismatch or corrupted key.' |
| 41 | ): self { |
| 42 | return new self($reason); |
| 43 | } |
| 44 | } |