| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Jose\Component\Encryption; |
| 6 |
|
| 7 |
use InvalidArgumentException; |
| 8 |
use function array_key_exists; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
final class Recipient |
| 14 |
{ |
| 15 |
public function __construct( |
| 16 |
private readonly array $header, |
| 17 |
private readonly ?string $encryptedKey |
| 18 |
) { |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public function getHeader(): array |
| 25 |
{ |
| 26 |
return $this->header; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function getHeaderParameter(string $key) |
| 37 |
{ |
| 38 |
if (! $this->hasHeaderParameter($key)) { |
| 39 |
throw new InvalidArgumentException(sprintf('The header "%s" does not exist.', $key)); |
| 40 |
} |
| 41 |
|
| 42 |
return $this->header[$key]; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function hasHeaderParameter(string $key): bool |
| 51 |
{ |
| 52 |
return array_key_exists($key, $this->header); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function getEncryptedKey(): ?string |
| 59 |
{ |
| 60 |
return $this->encryptedKey; |
| 61 |
} |
| 62 |
} |