<?php
 declare(strict_types=1); namespace Jose\Component\Signature; use InvalidArgumentException; use function array_key_exists; use function sprintf; class Signature { private readonly ?string $encodedProtectedHeader; private readonly array $protectedHeader; public function __construct( private readonly string $signature, array $protectedHeader, ?string $encodedProtectedHeader, private readonly array $header ) { $this->protectedHeader = $encodedProtectedHeader === null ? [] : $protectedHeader; $this->encodedProtectedHeader = $encodedProtectedHeader; } public function getProtectedHeader(): array { return $this->protectedHeader; } public function getHeader(): array { return $this->header; } public function getEncodedProtectedHeader(): ?string { return $this->encodedProtectedHeader; } public function getProtectedHeaderParameter(string $key) { if ($this->hasProtectedHeaderParameter($key)) { return $this->getProtectedHeader()[$key]; } throw new InvalidArgumentException(sprintf('The protected header "%s" does not exist', $key)); } public function hasProtectedHeaderParameter(string $key): bool { return array_key_exists($key, $this->getProtectedHeader()); } public function getHeaderParameter(string $key) { if (array_key_exists($key, $this->header)) { return $this->header[$key]; } throw new InvalidArgumentException(sprintf('The header "%s" does not exist', $key)); } public function hasHeaderParameter(string $key): bool { return array_key_exists($key, $this->header); } public function getSignature(): string { return $this->signature; } } 