Skip to content

Phpdoc/incorrect header description #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2045,16 +2045,6 @@ parameters:
count: 1
path: src/Component/NestedToken/NestedTokenBuilder.php

-
message: "#^Parameter \\#2 \\$protectedHeader of method Jose\\\\Component\\\\Signature\\\\JWSBuilder\\:\\:addSignature\\(\\) expects array\\{alg\\?\\: string, string\\?\\: mixed\\}, array\\<string, mixed\\> given\\.$#"
count: 1
path: src/Component/NestedToken/NestedTokenBuilder.php

-
message: "#^Parameter \\#3 \\$header of method Jose\\\\Component\\\\Signature\\\\JWSBuilder\\:\\:addSignature\\(\\) expects array\\{alg\\?\\: string, string\\?\\: mixed\\}, array\\<string, mixed\\> given\\.$#"
count: 1
path: src/Component/NestedToken/NestedTokenBuilder.php

-
message: "#^Result of \\|\\| is always false\\.$#"
count: 2
Expand Down
24 changes: 12 additions & 12 deletions src/Component/Signature/JWSBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use function count;
use function in_array;
use function is_array;
use function is_string;

class JWSBuilder
{
Expand Down Expand Up @@ -79,8 +80,8 @@ public function withPayload(string $payload, bool $isPayloadDetached = false): s
/**
* Adds the information needed to compute the signature. This method will return a new JWSBuilder object.
*
* @param array{alg?: string, string?: mixed} $protectedHeader
* @param array{alg?: string, string?: mixed} $header
* @param array<string, mixed> $protectedHeader
* @param array<string, mixed> $header
*/
public function addSignature(JWK $signatureKey, array $protectedHeader, array $header = []): self
{
Expand Down Expand Up @@ -185,26 +186,25 @@ private function checkB64AndCriticalHeader(array $protectedHeader): void
}

/**
* @param array{alg?: string, string?: mixed} $protectedHeader
* @param array{alg?: string, string?: mixed} $header
* @param array<string, mixed> $protectedHeader
* @param array<string, mixed> $header
* @return MacAlgorithm|SignatureAlgorithm
*/
private function findSignatureAlgorithm(JWK $key, array $protectedHeader, array $header): Algorithm
{
$completeHeader = [...$header, ...$protectedHeader];
if (! array_key_exists('alg', $completeHeader)) {
$alg = $completeHeader['alg'] ?? null;
if (! is_string($alg)) {
throw new InvalidArgumentException('No "alg" parameter set in the header.');
}
if ($key->has('alg') && $key->get('alg') !== $completeHeader['alg']) {
throw new InvalidArgumentException(sprintf(
'The algorithm "%s" is not allowed with this key.',
$completeHeader['alg']
));
$keyAlg = $key->has('alg') ? $key->get('alg') : null;
if (is_string($keyAlg) && $keyAlg !== $alg) {
throw new InvalidArgumentException(sprintf('The algorithm "%s" is not allowed with this key.', $alg));
}

$algorithm = $this->signatureAlgorithmManager->get($completeHeader['alg']);
$algorithm = $this->signatureAlgorithmManager->get($alg);
if (! $algorithm instanceof SignatureAlgorithm && ! $algorithm instanceof MacAlgorithm) {
throw new InvalidArgumentException(sprintf('The algorithm "%s" is not supported.', $completeHeader['alg']));
throw new InvalidArgumentException(sprintf('The algorithm "%s" is not supported.', $alg));
}

return $algorithm;
Expand Down