diff --git a/src/Library/Core/AlgorithmManagerFactory.php b/src/Library/Core/AlgorithmManagerFactory.php index a9c6b515..3854e668 100644 --- a/src/Library/Core/AlgorithmManagerFactory.php +++ b/src/Library/Core/AlgorithmManagerFactory.php @@ -14,6 +14,16 @@ class AlgorithmManagerFactory { private array $algorithms = []; + /** + * @param Algorithm[] $algorithms + */ + public function __construct(array $algorithms = []) + { + foreach ($algorithms as $algorithm) { + $this->add($algorithm->name(), $algorithm); + } + } + /** * Adds an algorithm. * diff --git a/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php b/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php index f4b15346..308e4e62 100644 --- a/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php +++ b/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php @@ -62,11 +62,6 @@ public function getAgreementKey( return ConcatKDF::generate($agreed_key, $algorithm, $encryptionKeyLength, $apu, $apv); } - public function name(): string - { - return 'ECDH-ES'; - } - public function getKeyManagementMode(): string { return self::MODE_AGREEMENT; diff --git a/src/Library/Encryption/Algorithm/KeyEncryption/ECDHES.php b/src/Library/Encryption/Algorithm/KeyEncryption/ECDHES.php index 8cd5ae9e..f83a300c 100644 --- a/src/Library/Encryption/Algorithm/KeyEncryption/ECDHES.php +++ b/src/Library/Encryption/Algorithm/KeyEncryption/ECDHES.php @@ -6,4 +6,8 @@ final class ECDHES extends AbstractECDH { + public function name(): string + { + return 'ECDH-ES'; + } } diff --git a/src/Library/Encryption/Algorithm/KeyEncryption/ECDHSS.php b/src/Library/Encryption/Algorithm/KeyEncryption/ECDHSS.php index 1af2e6d0..50b832a8 100644 --- a/src/Library/Encryption/Algorithm/KeyEncryption/ECDHSS.php +++ b/src/Library/Encryption/Algorithm/KeyEncryption/ECDHSS.php @@ -9,6 +9,11 @@ final class ECDHSS extends AbstractECDH { + public function name(): string + { + return 'ECDH-SS'; + } + /** * @param array $complete_header * @param array $additional_header_values diff --git a/tests/Component/Core/AlgorithmManagerFactoryTest.php b/tests/Component/Core/AlgorithmManagerFactoryTest.php index ab3612b6..298f3eb3 100644 --- a/tests/Component/Core/AlgorithmManagerFactoryTest.php +++ b/tests/Component/Core/AlgorithmManagerFactoryTest.php @@ -50,8 +50,7 @@ public function iCannotGetAnAlgorithmThatDoesNotExist(): void private function getAlgorithmManagerFactory(): AlgorithmManagerFactory { if ($this->algorithmManagerFactory === null) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); - $this->algorithmManagerFactory->add('foo', new FooAlgorithm()); + $this->algorithmManagerFactory = new AlgorithmManagerFactory([new FooAlgorithm()]); } return $this->algorithmManagerFactory; diff --git a/tests/Component/Encryption/EncryptionTestCase.php b/tests/Component/Encryption/EncryptionTestCase.php index ad4740b3..bcc02a57 100644 --- a/tests/Component/Encryption/EncryptionTestCase.php +++ b/tests/Component/Encryption/EncryptionTestCase.php @@ -63,34 +63,35 @@ abstract class EncryptionTestCase extends TestCase protected function getAlgorithmManagerFactory(): AlgorithmManagerFactory { if ($this->algorithmManagerFactory === null) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); - $this->algorithmManagerFactory->add('A128GCM', new A128GCM()); - $this->algorithmManagerFactory->add('A192GCM', new A192GCM()); - $this->algorithmManagerFactory->add('A256GCM', new A256GCM()); - $this->algorithmManagerFactory->add('A128CBC-HS256', new A128CBCHS256()); - $this->algorithmManagerFactory->add('A192CBC-HS384', new A192CBCHS384()); - $this->algorithmManagerFactory->add('A256CBC-HS512', new A256CBCHS512()); - $this->algorithmManagerFactory->add('A128GCMKW', new A128GCMKW()); - $this->algorithmManagerFactory->add('A192GCMKW', new A192GCMKW()); - $this->algorithmManagerFactory->add('A256GCMKW', new A256GCMKW()); - $this->algorithmManagerFactory->add('A128KW', new A128KW()); - $this->algorithmManagerFactory->add('A192KW', new A192KW()); - $this->algorithmManagerFactory->add('A256KW', new A256KW()); - $this->algorithmManagerFactory->add('dir', new Dir()); - $this->algorithmManagerFactory->add('ECDH-ES', new ECDHES()); - $this->algorithmManagerFactory->add('ECDH-ES+A128KW', new ECDHESA128KW()); - $this->algorithmManagerFactory->add('ECDH-ES+A192KW', new ECDHESA192KW()); - $this->algorithmManagerFactory->add('ECDH-ES+A256KW', new ECDHESA256KW()); - $this->algorithmManagerFactory->add('ECDH-SS', new ECDHSS()); - $this->algorithmManagerFactory->add('ECDH-SS+A128KW', new ECDHSSA128KW()); - $this->algorithmManagerFactory->add('ECDH-SS+A192KW', new ECDHSSA192KW()); - $this->algorithmManagerFactory->add('ECDH-SS+A256KW', new ECDHSSA256KW()); - $this->algorithmManagerFactory->add('PBES2-HS256+A128KW', new PBES2HS256A128KW()); - $this->algorithmManagerFactory->add('PBES2-HS384+A192KW', new PBES2HS384A192KW()); - $this->algorithmManagerFactory->add('PBES2-HS512+A256KW', new PBES2HS512A256KW()); - $this->algorithmManagerFactory->add('RSA1_5', new RSA15()); - $this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP()); - $this->algorithmManagerFactory->add('RSA-OAEP-256', new RSAOAEP256()); + $this->algorithmManagerFactory = new AlgorithmManagerFactory([ + new A128GCM(), + new A192GCM(), + new A256GCM(), + new A128CBCHS256(), + new A192CBCHS384(), + new A256CBCHS512(), + new A128GCMKW(), + new A192GCMKW(), + new A256GCMKW(), + new A128KW(), + new A192KW(), + new A256KW(), + new Dir(), + new ECDHES(), + new ECDHESA128KW(), + new ECDHESA192KW(), + new ECDHESA256KW(), + new ECDHSS(), + new ECDHSSA128KW(), + new ECDHSSA192KW(), + new ECDHSSA256KW(), + new PBES2HS256A128KW(), + new PBES2HS384A192KW(), + new PBES2HS512A256KW(), + new RSA15(), + new RSAOAEP(), + new RSAOAEP256(), + ]); } return $this->algorithmManagerFactory; diff --git a/tests/Component/NestedToken/NestedTokenTestCase.php b/tests/Component/NestedToken/NestedTokenTestCase.php index b790ead7..70de496b 100644 --- a/tests/Component/NestedToken/NestedTokenTestCase.php +++ b/tests/Component/NestedToken/NestedTokenTestCase.php @@ -59,30 +59,31 @@ abstract class NestedTokenTestCase extends TestCase protected function getAlgorithmManagerFactory(): AlgorithmManagerFactory { if ($this->algorithmManagerFactory === null) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); - $this->algorithmManagerFactory->add('A128GCM', new A128GCM()); - $this->algorithmManagerFactory->add('A192GCM', new A192GCM()); - $this->algorithmManagerFactory->add('A256GCM', new A256GCM()); - $this->algorithmManagerFactory->add('A128CBC-HS256', new A128CBCHS256()); - $this->algorithmManagerFactory->add('A192CBC-HS384', new A192CBCHS384()); - $this->algorithmManagerFactory->add('A256CBC-HS512', new A256CBCHS512()); - $this->algorithmManagerFactory->add('A128GCMKW', new A128GCMKW()); - $this->algorithmManagerFactory->add('A192GCMKW', new A192GCMKW()); - $this->algorithmManagerFactory->add('A256GCMKW', new A256GCMKW()); - $this->algorithmManagerFactory->add('A128KW', new A128KW()); - $this->algorithmManagerFactory->add('A192KW', new A192KW()); - $this->algorithmManagerFactory->add('A256KW', new A256KW()); - $this->algorithmManagerFactory->add('dir', new Dir()); - $this->algorithmManagerFactory->add('ECDH-ES', new ECDHES()); - $this->algorithmManagerFactory->add('ECDH-ES+A128KW', new ECDHESA128KW()); - $this->algorithmManagerFactory->add('ECDH-ES+A192KW', new ECDHESA192KW()); - $this->algorithmManagerFactory->add('ECDH-ES+A256KW', new ECDHESA256KW()); - $this->algorithmManagerFactory->add('PBES2-HS256+A128KW', new PBES2HS256A128KW()); - $this->algorithmManagerFactory->add('PBES2-HS384+A192KW', new PBES2HS384A192KW()); - $this->algorithmManagerFactory->add('PBES2-HS512+A256KW', new PBES2HS512A256KW()); - $this->algorithmManagerFactory->add('RSA1_5', new RSA15()); - $this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP()); - $this->algorithmManagerFactory->add('RSA-OAEP-256', new RSAOAEP256()); + $this->algorithmManagerFactory = new AlgorithmManagerFactory([ + new A128GCM(), + new A192GCM(), + new A256GCM(), + new A128CBCHS256(), + new A192CBCHS384(), + new A256CBCHS512(), + new A128GCMKW(), + new A192GCMKW(), + new A256GCMKW(), + new A128KW(), + new A192KW(), + new A256KW(), + new Dir(), + new ECDHES(), + new ECDHESA128KW(), + new ECDHESA192KW(), + new ECDHESA256KW(), + new PBES2HS256A128KW(), + new PBES2HS384A192KW(), + new PBES2HS512A256KW(), + new RSA15(), + new RSAOAEP(), + new RSAOAEP256(), + ]); } return $this->algorithmManagerFactory; } diff --git a/tests/Component/NestedToken/NestingTokenBuilderTest.php b/tests/Component/NestedToken/NestingTokenBuilderTest.php index c8856f6a..99661f2b 100644 --- a/tests/Component/NestedToken/NestingTokenBuilderTest.php +++ b/tests/Component/NestedToken/NestingTokenBuilderTest.php @@ -163,10 +163,11 @@ private function getJWSSerializerManagerFactory(): JwsSerializer\JWSSerializerMa private function getAlgorithmManagerFactory(): AlgorithmManagerFactory { if ($this->algorithmManagerFactory === null) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); - $this->algorithmManagerFactory->add('A128GCM', new A128GCM()); - $this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP()); - $this->algorithmManagerFactory->add('PS256', new PS256()); + $this->algorithmManagerFactory = new AlgorithmManagerFactory([ + new A128GCM(), + new RSAOAEP(), + new PS256(), + ]); } return $this->algorithmManagerFactory; diff --git a/tests/Component/NestedToken/NestingTokenUsingNestedTokenLoaderTest.php b/tests/Component/NestedToken/NestingTokenUsingNestedTokenLoaderTest.php index c56242f2..40830cfa 100644 --- a/tests/Component/NestedToken/NestingTokenUsingNestedTokenLoaderTest.php +++ b/tests/Component/NestedToken/NestingTokenUsingNestedTokenLoaderTest.php @@ -203,10 +203,11 @@ private function getJWSVerifierFactory(): JWSVerifierFactory private function getAlgorithmManagerFactory(): AlgorithmManagerFactory { if ($this->algorithmManagerFactory === null) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); - $this->algorithmManagerFactory->add('A128GCM', new A128GCM()); - $this->algorithmManagerFactory->add('RSA-OAEP', new RSAOAEP()); - $this->algorithmManagerFactory->add('PS256', new PS256()); + $this->algorithmManagerFactory = new AlgorithmManagerFactory([ + new A128GCM(), + new RSAOAEP(), + new PS256(), + ]); } return $this->algorithmManagerFactory; diff --git a/tests/Component/Signature/SignatureTestCase.php b/tests/Component/Signature/SignatureTestCase.php index 3b17a059..bc7feb13 100644 --- a/tests/Component/Signature/SignatureTestCase.php +++ b/tests/Component/Signature/SignatureTestCase.php @@ -46,21 +46,22 @@ abstract class SignatureTestCase extends TestCase protected function getAlgorithmManagerFactory(): AlgorithmManagerFactory { if ($this->algorithmManagerFactory === null) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); - $this->algorithmManagerFactory->add('HS256', new HS256()); - $this->algorithmManagerFactory->add('HS384', new HS384()); - $this->algorithmManagerFactory->add('HS512', new HS512()); - $this->algorithmManagerFactory->add('ES256', new ES256()); - $this->algorithmManagerFactory->add('ES384', new ES384()); - $this->algorithmManagerFactory->add('ES512', new ES512()); - $this->algorithmManagerFactory->add('RS256', new RS256()); - $this->algorithmManagerFactory->add('RS384', new RS384()); - $this->algorithmManagerFactory->add('RS512', new RS512()); - $this->algorithmManagerFactory->add('PS256', new PS256()); - $this->algorithmManagerFactory->add('PS384', new PS384()); - $this->algorithmManagerFactory->add('PS512', new PS512()); - $this->algorithmManagerFactory->add('none', new None()); - $this->algorithmManagerFactory->add('EdDSA', new EdDSA()); + $this->algorithmManagerFactory = new AlgorithmManagerFactory([ + new HS256(), + new HS384(), + new HS512(), + new ES256(), + new ES384(), + new ES512(), + new RS256(), + new RS384(), + new RS512(), + new PS256(), + new PS384(), + new PS512(), + new None(), + new EdDSA(), + ]); } return $this->algorithmManagerFactory;