-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdfSignatureDictionary.cs
More file actions
75 lines (57 loc) · 2.14 KB
/
PdfSignatureDictionary.cs
File metadata and controls
75 lines (57 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using iText.Kernel.Pdf;
using PdfSignabilityCheckerTool.Enums;
namespace PdfSignabilityCheckerTool;
internal class SigFieldPermissions
{
public PdfLockAction Action { get; set; }
public List<string>? Fields { get; set; }
public CertificationPermission? CertificationPermission { get; set; }
public SigFieldPermissions() { }
public SigFieldPermissions(PdfName actionName, PdfArray fieldsArray)
{
if (PdfName.All.Equals(actionName))
Action = PdfLockAction.ALL;
else if (PdfName.Include.Equals(actionName))
Action = PdfLockAction.INCLUDE;
else if (PdfName.Exclude.Equals(actionName))
Action = PdfLockAction.EXCLUDE;
else
throw new NotSupportedException($"Unknown FieldMDP action: {actionName}");
Fields = [];
if (fieldsArray != null)
{
for (int i = 0; i < fieldsArray.Size(); i++)
{
PdfString s = fieldsArray.GetAsString(i);
if (s != null)
Fields.Add(s.ToString());
}
}
}
}
internal class PdfSignatureDictionary(PdfDictionary dict)
{
public PdfDictionary Dictionary { get; } = dict;
public SigFieldPermissions? GetFieldMDP()
{
PdfArray referenceArray = Dictionary.GetAsArray(PdfName.Reference);
if (referenceArray is null)
return null;
for (int i = 0; i < referenceArray.Size(); i++)
{
PdfDictionary refEntry = referenceArray.GetAsDictionary(i);
if (refEntry is null)
continue;
PdfName transformMethod = refEntry.GetAsName(PdfName.TransformMethod);
if (transformMethod != PdfName.FieldMDP)
continue;
PdfDictionary transformParams = refEntry.GetAsDictionary(PdfName.TransformParams);
if (transformParams is null)
continue;
PdfName action = transformParams.GetAsName(PdfName.Action);
PdfArray fields = transformParams.GetAsArray(PdfName.Fields);
return new SigFieldPermissions(action, fields);
}
return null;
}
}