Skip to content

Commit 4499852

Browse files
authored
Merge pull request #29 from sevencooks-gmbh-co-kg/v1.1.x
Remove the internal crypto algorithm enum that has to be maintained
2 parents c2fbfb2 + 6cc27e5 commit 4499852

File tree

5 files changed

+7
-70
lines changed

5 files changed

+7
-70
lines changed

src/Api/Enum/CryptographicAlgorithmEnum.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Api/Factory/ResponseFactory.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Azimo\Apple\Api\Factory;
44

5-
use Azimo\Apple\Api\Enum\CryptographicAlgorithmEnum;
65
use Azimo\Apple\Api\Exception\ResponseValidationException;
76
use Azimo\Apple\Api\Exception\UnsupportedCryptographicAlgorithmException;
87
use Azimo\Apple\Api\Response\JsonWebKeySet;
@@ -52,15 +51,5 @@ private function validateAuthKey(array $authKey): void
5251
)
5352
);
5453
}
55-
56-
if (!CryptographicAlgorithmEnum::isSupported($authKey['kid'])) {
57-
throw new UnsupportedCryptographicAlgorithmException(
58-
sprintf(
59-
'Cryptographic algorithm `%s` is not supported. Supported algorithms: `%s`',
60-
$authKey['kid'],
61-
implode(',', CryptographicAlgorithmEnum::supportedAlgorithms())
62-
)
63-
);
64-
}
6554
}
6655
}

src/Api/Response/JsonWebKeySetCollection.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Azimo\Apple\Api\Response;
44

5-
use Azimo\Apple\Api\Enum\CryptographicAlgorithmEnum;
65
use Azimo\Apple\Api\Exception\UnsupportedCryptographicAlgorithmException;
76

87
class JsonWebKeySetCollection
@@ -24,16 +23,16 @@ public function getAuthKeys(): array
2423

2524
public function getByCryptographicAlgorithm(string $algorithm): ?JsonWebKeySet
2625
{
27-
if (!CryptographicAlgorithmEnum::isSupported($algorithm)) {
26+
$result = $this->authKeys[$algorithm] ?? null;
27+
if(!$result) {
2828
throw new UnsupportedCryptographicAlgorithmException(
2929
sprintf(
30-
'Cryptographic algorithm `%s` is not supported. Supported algorithms: `%s`',
31-
$algorithm,
32-
implode(',', CryptographicAlgorithmEnum::supportedAlgorithms())
30+
'Cryptographic algorithm `%s` is not supported.',
31+
$algorithm
3332
)
3433
);
3534
}
3635

37-
return $this->authKeys[$algorithm] ?? null;
36+
return $result;
3837
}
3938
}

tests/Unit/Api/Factory/ResponseFactoryTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,6 @@ public function provideCreateFromArrayThrowsResponseValidationExceptionWhenKeyAr
116116
];
117117
}
118118

119-
public function testIfCreateFromArrayThrowsUnsupportedCryptographicAlgorithmExceptionWhenKidIsNotSupported(): void
120-
{
121-
$this->expectException(UnsupportedCryptographicAlgorithmException::class);
122-
$this->expectExceptionMessage(
123-
'Cryptographic algorithm `bar` is not supported. Supported algorithms: `86D88Kf,eXaunmL`'
124-
);
125-
$this->responseFactory->createFromArray(
126-
[
127-
'keys' => [
128-
[
129-
'kty' => 'RSA',
130-
'kid' => 'bar',
131-
'use' => 'sig',
132-
'alg' => 'RS256',
133-
'n' => 'foo',
134-
'e' => 'AQAB',
135-
],
136-
],
137-
]
138-
);
139-
}
140-
141119
public function testIfCreateFromArrayReturnsExpectedJsonWebKeySetCollection(): void
142120
{
143121
$responseBody = [

tests/Unit/Auth/Jwt/JwtVerifierTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testIfVerifyThrowsInvalidCryptographicAlgorithmExceptionWhenAlgo
9595

9696
$this->expectException(Exception\InvalidCryptographicAlgorithmException::class);
9797
$this->expectExceptionMessage(
98-
'Cryptographic algorithm `foo` is not supported. Supported algorithms: `86D88Kf,eXaunmL,YuyXoY,W6WcOKB`'
98+
'Cryptographic algorithm `foo` is not supported.'
9999
);
100100
$this->jwtVerifier->verify($this->jwtMock);
101101
}
@@ -113,7 +113,7 @@ public function testIfVerifyThrowsInvalidCryptographicAlgorithmExceptionWhenAuth
113113
->andReturn('86D88Kf');
114114

115115
$this->expectException(Exception\InvalidCryptographicAlgorithmException::class);
116-
$this->expectExceptionMessage('Unsupported cryptographic algorithm passed `86D88Kf');
116+
$this->expectExceptionMessage('Cryptographic algorithm `86D88Kf` is not supported.');
117117
$this->jwtVerifier->verify($this->jwtMock);
118118
}
119119

0 commit comments

Comments
 (0)