Skip to content

Commit 43c3860

Browse files
committed
rephrase OKP subtypes concepts
1 parent 8fbeba2 commit 43c3860

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/JWK.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ class JWK
3131
// 'P-521' => '1.3.132.0.35', // Len: 132 (not supported)
3232
];
3333

34-
// 'crv' identifier => JWT 'alg'
35-
private const OKP_CURVES = [
36-
'Ed25519' => 'EdDSA',
34+
// For keys with "kty" equal to "OKP" (Octet Key Pair), the "crv" parameter must contain the key subtype.
35+
// This library supports the following subtypes:
36+
private const OKP_SUBTYPES = [
37+
'Ed25519' => true, // RFC 8037
3738
];
3839

3940
/**
@@ -160,17 +161,17 @@ public static function parseKey(array $jwk, string $defaultAlg = null): ?Key
160161
throw new UnexpectedValueException('crv not set');
161162
}
162163

163-
if (!isset(self::OKP_CURVES[$jwk['crv']])) {
164-
throw new DomainException('Unrecognised or unsupported OKP curve');
164+
if (empty(self::OKP_SUBTYPES[$jwk['crv']])) {
165+
throw new DomainException('Unrecognised or unsupported OKP key subtype');
165166
}
166167

167168
if (empty($jwk['x'])) {
168169
throw new UnexpectedValueException('x not set');
169170
}
170171

172+
// This library works internally with EdDSA keys (Ed25519) encoded in standard base64.
171173
$publicKey = JWT::convertBase64urlToBase64($jwk['x']);
172-
$alg = self::OKP_CURVES[$jwk['crv']];
173-
return new Key($publicKey, $alg);
174+
return new Key($publicKey, $jwk['alg']);
174175
default:
175176
break;
176177
}

0 commit comments

Comments
 (0)