Skip to content

Commit

Permalink
Fix EdDSA algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Feb 12, 2024
1 parent 034d891 commit c5cf734
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Component/KeyManagement/KeyConverter/KeyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ private static function tryToLoadOtherKeyTypes(string $input): array
private static function populatePoints(PrivateKey $key, array $values): array
{
$x = self::getPublicKey($key, $values['crv']);
$values['x'] = Base64UrlSafe::encodeUnpadded($x);
if ($x !== null) {
$values['x'] = Base64UrlSafe::encodeUnpadded($x);
}

return $values;
}

private static function getPublicKey(PrivateKey $key, string $crv): string
private static function getPublicKey(PrivateKey $key, string $crv): ?string
{
switch ($crv) {
case 'Ed25519':
Expand All @@ -268,7 +270,7 @@ private static function getPublicKey(PrivateKey $key, string $crv): string
}
// no break
default:
throw new InvalidArgumentException('Unsupported key type');
return null;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/SignatureAlgorithm/EdDSA/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"require": {
"php": ">=8.1",
"ext-sodium": "*",
"paragonie/sodium_compat": "^1.20",
"web-token/jwt-signature": "^3.2"
}
}
2 changes: 1 addition & 1 deletion tests/Component/KeyManagement/JWKFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static function dataKeys(): iterable
'kty' => 'OKP',
'crv' => 'Ed25519',
'd' => 'Pr9AxZivB-zSq95wLrZfYa7DQ3TUPqZTkP_0w33r3rc',
'x' => 'uRhai1TsvrSB43HD-36TQ2hMQfV8ruJz7F8o0wIe1VI',
'x' => 'wrI33AEj15KHHYplueUE5cnJKtbM8oVHFf6wGnw2oOE',
],
];
yield [
Expand Down

0 comments on commit c5cf734

Please sign in to comment.