Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SignatureReference | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
5.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
4.02 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Interactive\Signature; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfObject; |
| 11 | use Phpdftk\Pdf\Core\PdfReference; |
| 12 | use Phpdftk\Pdf\Core\PdfString; |
| 13 | use Phpdftk\Pdf\Core\PdfVersion; |
| 14 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 15 | |
| 16 | /** |
| 17 | * Signature reference dictionary (/Type /SigRef) — ISO 32000-2 §12.8.1, |
| 18 | * Table 253. Referenced by /Reference on a SignatureValue; each entry |
| 19 | * names a transform method plus its params. |
| 20 | */ |
| 21 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 22 | class SignatureReference extends PdfObject |
| 23 | { |
| 24 | public const PDF_TYPE = 'SigRef'; |
| 25 | |
| 26 | public PdfName $transformMethod; // /TransformMethod |
| 27 | public TransformParams|PdfReference|PdfDictionary|null $transformParams = null; // /TransformParams |
| 28 | public ?PdfReference $data = null; // /Data |
| 29 | public ?PdfName $digestMethod = null; // /DigestMethod MD5|SHA1|SHA256|SHA384|SHA512|RIPEMD160 |
| 30 | |
| 31 | public function __construct(string $transformMethod) |
| 32 | { |
| 33 | $this->transformMethod = new PdfName($transformMethod); |
| 34 | } |
| 35 | |
| 36 | public function toPdf(): string |
| 37 | { |
| 38 | $dict = new PdfDictionary(); |
| 39 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 40 | $dict->set('TransformMethod', $this->transformMethod); |
| 41 | if ($this->transformParams !== null) { |
| 42 | $dict->set('TransformParams', $this->transformParams); |
| 43 | } |
| 44 | if ($this->data !== null) { |
| 45 | $dict->set('Data', $this->data); |
| 46 | } |
| 47 | if ($this->digestMethod !== null) { |
| 48 | $dict->set('DigestMethod', $this->digestMethod); |
| 49 | } |
| 50 | return $dict->toPdf(); |
| 51 | } |
| 52 | } |