Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DocTimeStamp | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
5.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
4.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Interactive\Signature; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfNumber; |
| 10 | use Phpdftk\Pdf\Core\PdfString; |
| 11 | use Phpdftk\Pdf\Core\PdfVersion; |
| 12 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 13 | |
| 14 | /** |
| 15 | * Document-level timestamp signature (/Type /DocTimeStamp) — |
| 16 | * ISO 32000-2 §12.8.5 / PAdES Part 4. |
| 17 | * |
| 18 | * Wraps an RFC 3161 timestamp token (produced by a Time-Stamping |
| 19 | * Authority) in the same byte-range + /Contents placeholder structure as |
| 20 | * a regular signature. /SubFilter defaults to ETSI.RFC3161 and /Type is |
| 21 | * /DocTimeStamp rather than /Sig. |
| 22 | * |
| 23 | * Structurally identical to {@see SignatureValue}, so all byte-range and |
| 24 | * /Contents placeholder handling in `PdfWriter` works unchanged. |
| 25 | */ |
| 26 | #[RequiresPdfVersion(PdfVersion::V1_6)] |
| 27 | class DocTimeStamp extends SignatureValue |
| 28 | { |
| 29 | public const PDF_TYPE = 'DocTimeStamp'; |
| 30 | |
| 31 | public function __construct( |
| 32 | string $filter = 'Adobe.PPKLite', |
| 33 | ?string $subFilter = 'ETSI.RFC3161', |
| 34 | ?PdfString $contents = null, |
| 35 | ) { |
| 36 | parent::__construct($filter, $subFilter, $contents); |
| 37 | } |
| 38 | |
| 39 | public function toPdf(): string |
| 40 | { |
| 41 | $dict = new PdfDictionary(); |
| 42 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 43 | $dict->set('Filter', $this->filter); |
| 44 | if ($this->subFilter !== null) { |
| 45 | $dict->set('SubFilter', $this->subFilter); |
| 46 | } |
| 47 | $dict->set('Contents', $this->contents); |
| 48 | if ($this->byteRange !== null) { |
| 49 | $dict->set('ByteRange', $this->byteRange); |
| 50 | } |
| 51 | if ($this->v !== null) { |
| 52 | $dict->set('V', new PdfNumber($this->v)); |
| 53 | } |
| 54 | return $dict->toPdf(); |
| 55 | } |
| 56 | } |