Skip to content

Commit

Permalink
Remove the internal crypto algorithm enum that has to be maintained
Browse files Browse the repository at this point in the history
The algorithms are already downloaded from Apple, so just use this as the master list instead of keeping another internal lookup key list.
  • Loading branch information
devedup committed Jan 28, 2022
1 parent c0594bd commit 25e0639
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 68 deletions.
29 changes: 0 additions & 29 deletions src/Api/Enum/CryptographicAlgorithmEnum.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Api/Factory/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,5 @@ private function validateAuthKey(array $authKey): void
)
);
}

if (!CryptographicAlgorithmEnum::isSupported($authKey['kid'])) {
throw new UnsupportedCryptographicAlgorithmException(
sprintf(
'Cryptographic algorithm `%s` is not supported. Supported algorithms: `%s`',
$authKey['kid'],
implode(',', CryptographicAlgorithmEnum::supportedAlgorithms())
)
);
}
}
}
12 changes: 6 additions & 6 deletions src/Api/Response/JsonWebKeySetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public function __construct(array $authKeys)

public function getByCryptographicAlgorithm(string $algorithm): ?JsonWebKeySet
{
if (!CryptographicAlgorithmEnum::isSupported($algorithm)) {

$result = $this->authKeys[$algorithm] ?? null;
if(!$result) {
throw new UnsupportedCryptographicAlgorithmException(
sprintf(
'Cryptographic algorithm `%s` is not supported. Supported algorithms: `%s`',
$algorithm,
implode(',', CryptographicAlgorithmEnum::supportedAlgorithms())
'Cryptographic algorithm `%s` is not supported.',
$algorithm
)
);
}

return $this->authKeys[$algorithm] ?? null;
return $result;
}
}
21 changes: 0 additions & 21 deletions tests/Unit/Api/Factory/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,6 @@ public function provideCreateFromArrayThrowsResponseValidationExceptionWhenKeyAr
];
}

public function testIfCreateFromArraySkipsCreatingJsonWebKeySetWhenKidIsNotSupported(): void
{
self::assertEquals(
new JsonWebKeySetCollection([]),
$this->responseFactory->createFromArray(
[
'keys' => [
[
'kty' => 'RSA',
'kid' => 'bar',
'use' => 'sig',
'alg' => 'RS256',
'n' => 'foo',
'e' => 'AQAB',
],
],
]
)
);
}

public function testIfCreateFromArrayReturnsExpectedJsonWebKeySetCollection(): void
{
$responseBody = [
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Auth/Jwt/JwtVerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function testIfVerifyThrowsInvalidCryptographicAlgorithmExceptionWhenAlgo

$this->expectException(Exception\InvalidCryptographicAlgorithmException::class);
$this->expectExceptionMessage(
'Cryptographic algorithm `foo` is not supported. Supported algorithms: `86D88Kf,eXaunmL,YuyXoY,W6WcOKB`'
'Cryptographic algorithm `foo` is not supported.'
);
$this->jwtVerifier->verify($this->jwtTokenMock);
}
Expand All @@ -96,7 +96,7 @@ public function testIfVerifyThrowsInvalidCryptographicAlgorithmExceptionWhenAuth
->andReturn(new JWT\Token\DataSet(['kid' => '86D88Kf'], ''));

$this->expectException(Exception\InvalidCryptographicAlgorithmException::class);
$this->expectExceptionMessage('Unsupported cryptographic algorithm passed `86D88Kf');
$this->expectExceptionMessage('Cryptographic algorithm `86D88Kf` is not supported.');
$this->jwtVerifier->verify($this->jwtTokenMock);
}

Expand Down

0 comments on commit 25e0639

Please sign in to comment.