From adca24608339f0b7166b2aa301a76526a4716a40 Mon Sep 17 00:00:00 2001 From: Miljan Ilic Date: Sun, 10 Mar 2024 11:10:17 +0100 Subject: [PATCH 1/3] Fix Cipher Exceptions Namespace --- src/Cipher/AdvancedEncryptionStandardCipher.php | 8 ++++---- src/Cipher/AsymmetricEncryptionCipher.php | 4 ++-- src/Cipher/Cipher.php | 2 +- src/Cipher/Exception/CipherException.php | 2 +- .../FailedCalculatingInitializationVectorLength.php | 2 +- src/Cipher/Exception/FailedDecryptingValue.php | 2 +- src/Cipher/Exception/FailedEncryptingValue.php | 2 +- .../Exception/FailedGeneratingInitializationVector.php | 2 +- src/ObjectEncryptionService.php | 2 +- src/StringEncryptionService.php | 5 +++-- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Cipher/AdvancedEncryptionStandardCipher.php b/src/Cipher/AdvancedEncryptionStandardCipher.php index f748ab1..cb6dad6 100644 --- a/src/Cipher/AdvancedEncryptionStandardCipher.php +++ b/src/Cipher/AdvancedEncryptionStandardCipher.php @@ -2,10 +2,10 @@ namespace IlicMiljan\SecureProps\Cipher; -use IlicMiljan\SecureProps\Reader\Exception\FailedCalculatingInitializationVectorLength; -use IlicMiljan\SecureProps\Reader\Exception\FailedDecryptingValue; -use IlicMiljan\SecureProps\Reader\Exception\FailedEncryptingValue; -use IlicMiljan\SecureProps\Reader\Exception\FailedGeneratingInitializationVector; +use IlicMiljan\SecureProps\Cipher\Exception\FailedCalculatingInitializationVectorLength; +use IlicMiljan\SecureProps\Cipher\Exception\FailedDecryptingValue; +use IlicMiljan\SecureProps\Cipher\Exception\FailedEncryptingValue; +use IlicMiljan\SecureProps\Cipher\Exception\FailedGeneratingInitializationVector; use InvalidArgumentException; use SensitiveParameter; diff --git a/src/Cipher/AsymmetricEncryptionCipher.php b/src/Cipher/AsymmetricEncryptionCipher.php index bc93c7a..e2525c7 100644 --- a/src/Cipher/AsymmetricEncryptionCipher.php +++ b/src/Cipher/AsymmetricEncryptionCipher.php @@ -2,8 +2,8 @@ namespace IlicMiljan\SecureProps\Cipher; -use IlicMiljan\SecureProps\Reader\Exception\FailedDecryptingValue; -use IlicMiljan\SecureProps\Reader\Exception\FailedEncryptingValue; +use IlicMiljan\SecureProps\Cipher\Exception\FailedDecryptingValue; +use IlicMiljan\SecureProps\Cipher\Exception\FailedEncryptingValue; use SensitiveParameter; class AsymmetricEncryptionCipher implements Cipher diff --git a/src/Cipher/Cipher.php b/src/Cipher/Cipher.php index d5d86de..8ffe05a 100644 --- a/src/Cipher/Cipher.php +++ b/src/Cipher/Cipher.php @@ -2,7 +2,7 @@ namespace IlicMiljan\SecureProps\Cipher; -use IlicMiljan\SecureProps\Reader\Exception\CipherException; +use IlicMiljan\SecureProps\Cipher\Exception\CipherException; use SensitiveParameter; interface Cipher diff --git a/src/Cipher/Exception/CipherException.php b/src/Cipher/Exception/CipherException.php index 7ac90b1..ee0a9c9 100644 --- a/src/Cipher/Exception/CipherException.php +++ b/src/Cipher/Exception/CipherException.php @@ -1,6 +1,6 @@ Date: Sun, 10 Mar 2024 11:10:40 +0100 Subject: [PATCH 2/3] Fix Cipher Tests Exceptions Namespace --- tests/ObjectEncryptionServiceTest.php | 2 +- tests/StringEncryptionServiceTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ObjectEncryptionServiceTest.php b/tests/ObjectEncryptionServiceTest.php index 9450864..740fc39 100644 --- a/tests/ObjectEncryptionServiceTest.php +++ b/tests/ObjectEncryptionServiceTest.php @@ -3,8 +3,8 @@ namespace IlicMiljan\SecureProps\Tests; use IlicMiljan\SecureProps\Cipher\Cipher; +use IlicMiljan\SecureProps\Cipher\Exception\CipherException; use IlicMiljan\SecureProps\ObjectEncryptionService; -use IlicMiljan\SecureProps\Reader\Exception\CipherException; use IlicMiljan\SecureProps\Reader\Exception\ReaderException; use IlicMiljan\SecureProps\Reader\ObjectPropertiesReader; use IlicMiljan\SecureProps\Attribute\Encrypted; diff --git a/tests/StringEncryptionServiceTest.php b/tests/StringEncryptionServiceTest.php index 2d0cc47..1ad6574 100644 --- a/tests/StringEncryptionServiceTest.php +++ b/tests/StringEncryptionServiceTest.php @@ -2,11 +2,10 @@ namespace IlicMiljan\SecureProps\Tests; -use IlicMiljan\SecureProps\Reader\Exception\CipherException; +use IlicMiljan\SecureProps\Cipher\Exception\CipherException; use IlicMiljan\SecureProps\StringEncryptionService; use IlicMiljan\SecureProps\Cipher\Cipher; use InvalidArgumentException; -use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; From 2c37a58654d8704d6fc6ad18e4374d7bd0947613 Mon Sep 17 00:00:00 2001 From: Miljan Ilic Date: Sun, 10 Mar 2024 11:18:10 +0100 Subject: [PATCH 3/3] Add Cipher Exceptions Tests --- ...culatingInitializationVectorLengthTest.php | 47 +++++++++++++++++++ .../Exception/FailedDecryptingValueTest.php | 33 +++++++++++++ .../Exception/FailedEncryptingValueTest.php | 33 +++++++++++++ ...iledGeneratingInitializationVectorTest.php | 47 +++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 tests/Cipher/Exception/FailedCalculatingInitializationVectorLengthTest.php create mode 100644 tests/Cipher/Exception/FailedDecryptingValueTest.php create mode 100644 tests/Cipher/Exception/FailedEncryptingValueTest.php create mode 100644 tests/Cipher/Exception/FailedGeneratingInitializationVectorTest.php diff --git a/tests/Cipher/Exception/FailedCalculatingInitializationVectorLengthTest.php b/tests/Cipher/Exception/FailedCalculatingInitializationVectorLengthTest.php new file mode 100644 index 0000000..b32c0c8 --- /dev/null +++ b/tests/Cipher/Exception/FailedCalculatingInitializationVectorLengthTest.php @@ -0,0 +1,47 @@ +cipher = 'AES-256-GCM'; + } + + public function testCanBeCreated(): void + { + $exception = new FailedCalculatingInitializationVectorLength($this->cipher); + + $this->assertInstanceOf(FailedCalculatingInitializationVectorLength::class, $exception); + } + + public function testReturnsCipher(): void + { + $exception = new FailedCalculatingInitializationVectorLength($this->cipher); + + $this->assertEquals($this->cipher, $exception->getCipher()); + } + + public function testPreviousExceptionIsStored(): void + { + $previous = new LogicException('Previous exception'); + $exception = new FailedCalculatingInitializationVectorLength($this->cipher, $previous); + + $this->assertSame($previous, $exception->getPrevious()); + } + + public function testImplementsCipherExceptionInterface(): void + { + $exception = new FailedCalculatingInitializationVectorLength($this->cipher); + + $this->assertInstanceOf(CipherException::class, $exception); + } +} diff --git a/tests/Cipher/Exception/FailedDecryptingValueTest.php b/tests/Cipher/Exception/FailedDecryptingValueTest.php new file mode 100644 index 0000000..204928e --- /dev/null +++ b/tests/Cipher/Exception/FailedDecryptingValueTest.php @@ -0,0 +1,33 @@ +assertInstanceOf(FailedDecryptingValue::class, $exception); + } + + public function testPreviousExceptionIsStored(): void + { + $previous = new LogicException('Previous exception'); + $exception = new FailedDecryptingValue($previous); + + $this->assertSame($previous, $exception->getPrevious()); + } + + public function testImplementsCipherExceptionInterface(): void + { + $exception = new FailedDecryptingValue(); + + $this->assertInstanceOf(CipherException::class, $exception); + } +} diff --git a/tests/Cipher/Exception/FailedEncryptingValueTest.php b/tests/Cipher/Exception/FailedEncryptingValueTest.php new file mode 100644 index 0000000..e42d1f3 --- /dev/null +++ b/tests/Cipher/Exception/FailedEncryptingValueTest.php @@ -0,0 +1,33 @@ +assertInstanceOf(FailedEncryptingValue::class, $exception); + } + + public function testPreviousExceptionIsStored(): void + { + $previous = new LogicException('Previous exception'); + $exception = new FailedEncryptingValue($previous); + + $this->assertSame($previous, $exception->getPrevious()); + } + + public function testImplementsCipherExceptionInterface(): void + { + $exception = new FailedEncryptingValue(); + + $this->assertInstanceOf(CipherException::class, $exception); + } +} diff --git a/tests/Cipher/Exception/FailedGeneratingInitializationVectorTest.php b/tests/Cipher/Exception/FailedGeneratingInitializationVectorTest.php new file mode 100644 index 0000000..86db83e --- /dev/null +++ b/tests/Cipher/Exception/FailedGeneratingInitializationVectorTest.php @@ -0,0 +1,47 @@ +length = 16; + } + + public function testCanBeCreated(): void + { + $exception = new FailedGeneratingInitializationVector($this->length); + + $this->assertInstanceOf(FailedGeneratingInitializationVector::class, $exception); + } + + public function testReturnsLength(): void + { + $exception = new FailedGeneratingInitializationVector($this->length); + + $this->assertEquals($this->length, $exception->getLength()); + } + + public function testPreviousExceptionIsStored(): void + { + $previous = new LogicException('Previous exception'); + $exception = new FailedGeneratingInitializationVector($this->length, $previous); + + $this->assertSame($previous, $exception->getPrevious()); + } + + public function testImplementsCipherExceptionInterface(): void + { + $exception = new FailedGeneratingInitializationVector($this->length); + + $this->assertInstanceOf(CipherException::class, $exception); + } +}