Skip to content

Commit 78da15c

Browse files
committed
Merge branch 'temp-45a6dd' into 4.1.x
2 parents b05d01d + 3c2fb82 commit 78da15c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

KeyManagement/Analyzer/UsageAnalyzer.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
use Jose\Component\Core\JWK;
88
use Override;
9+
use function array_diff;
910
use function in_array;
11+
use function is_array;
1012
use function sprintf;
1113

1214
final readonly class UsageAnalyzer implements KeyAnalyzer
@@ -24,18 +26,27 @@ public function analyze(JWK $jwk, MessageBag $bag): void
2426
))
2527
);
2628
}
27-
if ($jwk->has('key_ops') && ! in_array(
28-
$jwk->get('key_ops'),
29-
['sign', 'verify', 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
30-
true
31-
)) {
32-
$bag->add(
33-
Message::high(sprintf(
34-
'The parameter "key_ops" has an unsupported value "%s". Please use one of the following values: %s.',
35-
$jwk->get('key_ops'),
36-
implode(', ', ['verify', 'sign', 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])
37-
))
38-
);
29+
if ($jwk->has('key_ops')) {
30+
$key_ops = $jwk->get('key_ops');
31+
if (! is_array($key_ops)) {
32+
$bag->add(
33+
Message::high(
34+
'The parameter "key_ops" must be an array of key operation values.'
35+
)
36+
);
37+
} else {
38+
$allowedOps = ['sign', 'verify', 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey', 'deriveKey', 'deriveBits'];
39+
$unsupportedOps = array_diff($key_ops, $allowedOps);
40+
if ($unsupportedOps !== []) {
41+
$bag->add(
42+
Message::high(sprintf(
43+
'The parameter "key_ops" contains unsupported values: "%s". Please use only the following values: %s.',
44+
implode('", "', $unsupportedOps),
45+
implode(', ', $allowedOps)
46+
))
47+
);
48+
}
49+
}
3950
}
4051
}
4152
}

0 commit comments

Comments
 (0)