Skip to content

Commit 327d275

Browse files
authored
Merge pull request #6020 from LibreSign/backport/6018/stable32
[stable32] refactor: docmdp enum naming
2 parents 41a0fb7 + 23699b1 commit 327d275

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

lib/Enum/DocMdpLevel.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@
1212
use OCP\IL10N;
1313

1414
enum DocMdpLevel: int {
15-
case NONE = 0;
16-
case NO_CHANGES = 1;
17-
case FORM_FILL = 2;
18-
case FORM_FILL_AND_ANNOTATIONS = 3;
15+
case NOT_CERTIFIED = 0;
16+
case CERTIFIED_NO_CHANGES_ALLOWED = 1;
17+
case CERTIFIED_FORM_FILLING = 2;
18+
case CERTIFIED_FORM_FILLING_AND_ANNOTATIONS = 3;
1919

2020
public function isCertifying(): bool {
21-
return $this !== self::NONE;
21+
return $this !== self::NOT_CERTIFIED;
2222
}
2323

2424
public function getLabel(IL10N $l10n): string {
2525
return match($this) {
26-
self::NONE => $l10n->t('No certification'),
27-
self::NO_CHANGES => $l10n->t('No changes allowed'),
28-
self::FORM_FILL => $l10n->t('Form filling and additional signatures'),
29-
self::FORM_FILL_AND_ANNOTATIONS => $l10n->t('Form filling, annotations and additional signatures'),
26+
self::NOT_CERTIFIED => $l10n->t('No certification'),
27+
self::CERTIFIED_NO_CHANGES_ALLOWED => $l10n->t('No changes allowed'),
28+
self::CERTIFIED_FORM_FILLING => $l10n->t('Form filling and additional signatures'),
29+
self::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS => $l10n->t('Form filling, annotations and additional signatures'),
3030
};
3131
}
3232

3333
public function getDescription(IL10N $l10n): string {
3434
return match($this) {
35-
self::NONE => $l10n->t('Document is not certified. No restrictions on modifications.'),
36-
self::NO_CHANGES => $l10n->t('No changes allowed. Additional approval signatures are prohibited.'),
37-
self::FORM_FILL => $l10n->t('Form filling allowed. Additional approval signatures are allowed.'),
38-
self::FORM_FILL_AND_ANNOTATIONS => $l10n->t('Form filling and annotations allowed. Additional approval signatures are allowed.'),
35+
self::NOT_CERTIFIED => $l10n->t('Document is not certified. No restrictions on modifications.'),
36+
self::CERTIFIED_NO_CHANGES_ALLOWED => $l10n->t('No changes allowed. Additional approval signatures are prohibited.'),
37+
self::CERTIFIED_FORM_FILLING => $l10n->t('Form filling allowed. Additional approval signatures are allowed.'),
38+
self::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS => $l10n->t('Form filling and annotations allowed. Additional approval signatures are allowed.'),
3939
};
4040
}
4141
}

lib/Handler/DocMdpHandler.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
class DocMdpHandler {
1717
/** @var array<string, string[]> Allowed modification types per DocMDP level */
1818
private const ALLOWED_MODIFICATIONS = [
19-
'NO_CHANGES' => [],
20-
'FORM_FILL' => ['form_field', 'template', 'signature'],
21-
'FORM_FILL_AND_ANNOTATIONS' => ['form_field', 'template', 'annotation', 'signature'],
19+
'CERTIFIED_NO_CHANGES_ALLOWED' => [],
20+
'CERTIFIED_FORM_FILLING' => ['form_field', 'template', 'signature'],
21+
'CERTIFIED_FORM_FILLING_AND_ANNOTATIONS' => ['form_field', 'template', 'annotation', 'signature'],
2222
];
2323

2424
public function __construct(
@@ -70,15 +70,15 @@ private function extractDocMdpLevel($pdfResource): DocMdpLevel {
7070
$content = stream_get_contents($pdfResource);
7171

7272
if (!$this->validateIsoCompliance($content)) {
73-
return DocMdpLevel::NONE;
73+
return DocMdpLevel::NOT_CERTIFIED;
7474
}
7575

7676
$pValue = $this->extractPValue($content);
7777
if ($pValue === null) {
78-
return DocMdpLevel::NONE;
78+
return DocMdpLevel::NOT_CERTIFIED;
7979
}
8080

81-
return DocMdpLevel::tryFrom($pValue) ?? DocMdpLevel::NONE;
81+
return DocMdpLevel::tryFrom($pValue) ?? DocMdpLevel::NOT_CERTIFIED;
8282
}
8383

8484
/**
@@ -249,7 +249,7 @@ private function validateModifications(DocMdpLevel $docmdpLevel, array $modifica
249249
);
250250
}
251251

252-
if ($docmdpLevel === DocMdpLevel::NONE) {
252+
if ($docmdpLevel === DocMdpLevel::NOT_CERTIFIED) {
253253
return $this->buildValidationResult(
254254
true,
255255
File::MODIFICATION_ALLOWED,
@@ -307,9 +307,9 @@ private function buildValidationResult(bool $valid, int $status, string $message
307307
*/
308308
private function getAllowedModificationMessage(DocMdpLevel $level): string {
309309
return match ($level) {
310-
DocMdpLevel::NO_CHANGES => 'Invalid: Document was modified after signing (DocMDP violation - no changes allowed)',
311-
DocMdpLevel::FORM_FILL => 'Document form fields were modified (allowed by DocMDP P=2)',
312-
DocMdpLevel::FORM_FILL_AND_ANNOTATIONS => 'Document form fields or annotations were modified (allowed by DocMDP P=3)',
310+
DocMdpLevel::CERTIFIED_NO_CHANGES_ALLOWED => 'Invalid: Document was modified after signing (DocMDP violation - no changes allowed)',
311+
DocMdpLevel::CERTIFIED_FORM_FILLING => 'Document form fields were modified (allowed by DocMDP P=2)',
312+
DocMdpLevel::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS => 'Document form fields or annotations were modified (allowed by DocMDP P=3)',
313313
default => 'Document was modified after signing',
314314
};
315315
}
@@ -322,9 +322,9 @@ private function getAllowedModificationMessage(DocMdpLevel $level): string {
322322
*/
323323
private function getViolationMessage(DocMdpLevel $level): string {
324324
return match ($level) {
325-
DocMdpLevel::NO_CHANGES => 'Invalid: Document was modified after signing (DocMDP violation - no changes allowed)',
326-
DocMdpLevel::FORM_FILL => 'Invalid: Document was modified after signing (DocMDP P=2 only allows form field changes)',
327-
DocMdpLevel::FORM_FILL_AND_ANNOTATIONS => 'Invalid: Document was modified after signing (DocMDP P=3 only allows form fields and annotations)',
325+
DocMdpLevel::CERTIFIED_NO_CHANGES_ALLOWED => 'Invalid: Document was modified after signing (DocMDP violation - no changes allowed)',
326+
DocMdpLevel::CERTIFIED_FORM_FILLING => 'Invalid: Document was modified after signing (DocMDP P=2 only allows form field changes)',
327+
DocMdpLevel::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS => 'Invalid: Document was modified after signing (DocMDP P=3 only allows form fields and annotations)',
328328
default => 'Invalid: Document was modified after signing (DocMDP violation)',
329329
};
330330
}

tests/php/Unit/Handler/DocMdpHandlerTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testUnsignedPdfIsDetectedAsLevelNone(): void {
3434
$result = $this->handler->extractDocMdpData($resource);
3535
fclose($resource);
3636

37-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level']);
37+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level']);
3838
}
3939

4040
public function testP0AllowsAnyModification(): void {
@@ -154,7 +154,7 @@ public function testExtractsDocMdpFromSignatureReferenceNotPerms(): void {
154154
$result = $this->handler->extractDocMdpData($resource);
155155
fclose($resource);
156156

157-
$this->assertSame(DocMdpLevel::FORM_FILL->value, $result['docmdp']['level'], 'Must extract DocMDP from /Reference per ICP-Brasil recommendation (not /Perms)');
157+
$this->assertSame(DocMdpLevel::CERTIFIED_FORM_FILLING->value, $result['docmdp']['level'], 'Must extract DocMDP from /Reference per ICP-Brasil recommendation (not /Perms)');
158158
}
159159

160160
public function testExtractsDocMdpFromFirstCertifyingSignature(): void {
@@ -164,7 +164,7 @@ public function testExtractsDocMdpFromFirstCertifyingSignature(): void {
164164
$result = $this->handler->extractDocMdpData($resource);
165165
fclose($resource);
166166

167-
$this->assertSame(DocMdpLevel::NO_CHANGES->value, $result['docmdp']['level'], 'Must extract DocMDP from first CERTIFYING signature, not first signature in file');
167+
$this->assertSame(DocMdpLevel::CERTIFIED_NO_CHANGES_ALLOWED->value, $result['docmdp']['level'], 'Must extract DocMDP from first CERTIFYING signature, not first signature in file');
168168
}
169169

170170
public function testP2AllowsPageTemplateInstantiation(): void {
@@ -196,7 +196,7 @@ public function testExtractsDocMdpWithIndirectReferenceItiStyle(): void {
196196
$result = $this->handler->extractDocMdpData($resource);
197197
fclose($resource);
198198

199-
$this->assertSame(DocMdpLevel::FORM_FILL->value, $result['docmdp']['level'], 'Must extract DocMDP from indirect references per ICP-Brasil example');
199+
$this->assertSame(DocMdpLevel::CERTIFIED_FORM_FILLING->value, $result['docmdp']['level'], 'Must extract DocMDP from indirect references per ICP-Brasil example');
200200
}
201201

202202
public function testValidatesTransformParamsVersion(): void {
@@ -206,7 +206,7 @@ public function testValidatesTransformParamsVersion(): void {
206206
$result = $this->handler->extractDocMdpData($resource);
207207
fclose($resource);
208208

209-
$this->assertSame(DocMdpLevel::FORM_FILL->value, $result['docmdp']['level'], 'Must accept /V /1.2 in TransformParams per ICP-Brasil');
209+
$this->assertSame(DocMdpLevel::CERTIFIED_FORM_FILLING->value, $result['docmdp']['level'], 'Must accept /V /1.2 in TransformParams per ICP-Brasil');
210210
}
211211

212212
public function testRejectsDocMdpWithoutVersion(): void {
@@ -216,7 +216,7 @@ public function testRejectsDocMdpWithoutVersion(): void {
216216
$result = $this->handler->extractDocMdpData($resource);
217217
fclose($resource);
218218

219-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'Must reject DocMDP without /V version per ICP-Brasil requirement');
219+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'Must reject DocMDP without /V version per ICP-Brasil requirement');
220220
}
221221

222222
public function testRejectsDocMdpWithInvalidVersion(): void {
@@ -226,7 +226,7 @@ public function testRejectsDocMdpWithInvalidVersion(): void {
226226
$result = $this->handler->extractDocMdpData($resource);
227227
fclose($resource);
228228

229-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'Must reject DocMDP with /V 1.0 (only /V /1.2 allowed per ICP-Brasil)');
229+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'Must reject DocMDP with /V 1.0 (only /V /1.2 allowed per ICP-Brasil)');
230230
}
231231

232232
public function testRejectsDocMdpWithInvalidVersionIndirectRef(): void {
@@ -236,15 +236,15 @@ public function testRejectsDocMdpWithInvalidVersionIndirectRef(): void {
236236
$result = $this->handler->extractDocMdpData($resource);
237237
fclose($resource);
238238

239-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'Must reject indirect DocMDP with /V 1.3 (only /V /1.2 allowed)');
239+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'Must reject indirect DocMDP with /V 1.3 (only /V /1.2 allowed)');
240240
}
241241

242242
public static function docMdpLevelExtractionProvider(): array {
243243
return [
244-
'Level P=0 NONE' => [0, DocMdpLevel::NONE],
245-
'Level P=1 NO_CHANGES' => [1, DocMdpLevel::NO_CHANGES],
246-
'Level P=2 FORM_FILL' => [2, DocMdpLevel::FORM_FILL],
247-
'Level P=3 FORM_FILL_AND_ANNOTATIONS' => [3, DocMdpLevel::FORM_FILL_AND_ANNOTATIONS],
244+
'Level P=0 NOT_CERTIFIED' => [0, DocMdpLevel::NOT_CERTIFIED],
245+
'Level P=1 CERTIFIED_NO_CHANGES_ALLOWED' => [1, DocMdpLevel::CERTIFIED_NO_CHANGES_ALLOWED],
246+
'Level P=2 CERTIFIED_FORM_FILLING' => [2, DocMdpLevel::CERTIFIED_FORM_FILLING],
247+
'Level P=3 CERTIFIED_FORM_FILLING_AND_ANNOTATIONS' => [3, DocMdpLevel::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS],
248248
];
249249
}
250250

@@ -726,7 +726,7 @@ public function testRejectsSignatureDictionaryWithoutTypeWhenPresent(): void {
726726
$result = $this->handler->extractDocMdpData($resource);
727727
fclose($resource);
728728

729-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'ISO 32000-1 Table 252: if /Type present in signature dict, must be /Sig');
729+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'ISO 32000-1 Table 252: if /Type present in signature dict, must be /Sig');
730730
}
731731

732732
public function testRejectsSignatureWithoutFilterEntry(): void {
@@ -744,7 +744,7 @@ public function testRejectsSignatureWithoutFilterEntry(): void {
744744
$result = $this->handler->extractDocMdpData($resource);
745745
fclose($resource);
746746

747-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'ISO 32000-1 Table 252: /Filter is Required in signature dictionary');
747+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'ISO 32000-1 Table 252: /Filter is Required in signature dictionary');
748748
}
749749

750750
public function testRejectsSignatureWithoutByteRange(): void {
@@ -762,7 +762,7 @@ public function testRejectsSignatureWithoutByteRange(): void {
762762
$result = $this->handler->extractDocMdpData($resource);
763763
fclose($resource);
764764

765-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'ISO 32000-1: ByteRange required when DocMDP transform method is used');
765+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'ISO 32000-1: ByteRange required when DocMDP transform method is used');
766766
}
767767

768768
public function testRejectsMultipleDocMdpSignatures(): void {
@@ -792,7 +792,7 @@ public function testRejectsMultipleDocMdpSignatures(): void {
792792
$result = $this->handler->extractDocMdpData($resource);
793793
fclose($resource);
794794

795-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'ISO 32000-1 12.8.2.2.1: A document can contain only one signature field that contains a DocMDP transform method');
795+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'ISO 32000-1 12.8.2.2.1: A document can contain only one signature field that contains a DocMDP transform method');
796796
}
797797

798798
public function testRejectsDocMdpNotFirstSignature(): void {
@@ -820,7 +820,7 @@ public function testRejectsDocMdpNotFirstSignature(): void {
820820
$result = $this->handler->extractDocMdpData($resource);
821821
fclose($resource);
822822

823-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'ISO 32000-1 12.8.2.2.1: DocMDP signature shall be the first signed field in the document');
823+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'ISO 32000-1 12.8.2.2.1: DocMDP signature shall be the first signed field in the document');
824824
}
825825

826826
public function testRejectsSigRefWithoutTransformMethod(): void {
@@ -839,6 +839,6 @@ public function testRejectsSigRefWithoutTransformMethod(): void {
839839
$result = $this->handler->extractDocMdpData($resource);
840840
fclose($resource);
841841

842-
$this->assertSame(DocMdpLevel::NONE->value, $result['docmdp']['level'], 'ISO 32000-1 Table 253: /TransformMethod is Required in signature reference dictionary');
842+
$this->assertSame(DocMdpLevel::NOT_CERTIFIED->value, $result['docmdp']['level'], 'ISO 32000-1 Table 253: /TransformMethod is Required in signature reference dictionary');
843843
}
844844
}

0 commit comments

Comments
 (0)