Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PublicKeyRecipient | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
4.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
3.03 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Security; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfNumber; |
| 11 | use Phpdftk\Pdf\Core\PdfString; |
| 12 | use Phpdftk\Pdf\Core\PdfVersion; |
| 13 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 14 | use Phpdftk\Pdf\Core\Serializable; |
| 15 | |
| 16 | /** |
| 17 | * Public-key recipient dictionary — ISO 32000-2 §7.6.5.3, Table 27. |
| 18 | * |
| 19 | * A single entry in the /Recipients array of a public-key crypt filter. |
| 20 | * Carries the PKCS#7 envelope that encrypts the file encryption key for |
| 21 | * one recipient plus that recipient's access permissions. |
| 22 | */ |
| 23 | #[RequiresPdfVersion(PdfVersion::V1_5)] |
| 24 | class PublicKeyRecipient implements Serializable |
| 25 | { |
| 26 | public PdfString $pkcs7; // the envelope (byte string) |
| 27 | public ?int $p = null; // /P permissions |
| 28 | public ?PdfArray $recipient = null; // optional /Recipient identity |
| 29 | |
| 30 | public function __construct(PdfString $pkcs7) |
| 31 | { |
| 32 | $this->pkcs7 = $pkcs7; |
| 33 | } |
| 34 | |
| 35 | public function toPdf(): string |
| 36 | { |
| 37 | $dict = new PdfDictionary(); |
| 38 | $dict->set('PKCS7', $this->pkcs7); |
| 39 | if ($this->p !== null) { |
| 40 | $dict->set('P', new PdfNumber($this->p)); |
| 41 | } |
| 42 | if ($this->recipient !== null) { |
| 43 | $dict->set('Recipient', $this->recipient); |
| 44 | } |
| 45 | return $dict->toPdf(); |
| 46 | } |
| 47 | } |