PDFSignatureFieldSeedValue.java
14.3 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosNumeric
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.digsig;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosNumeric;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFCertificateSeedValue;
import com.adobe.internal.pdftoolkit.pdf.digsig.PDFTimeStampSeed;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
public class PDFSignatureFieldSeedValue
extends PDFCosDictionary {
public static final int kFilter = 1;
public static final int kSubFilter = 2;
public static final int kV = 4;
public static final int kReasons = 8;
public static final int kLegalAttestation = 16;
public static final int kAddRevInfo = 32;
public static final int kDigestMethod = 64;
public static final int kLockDocument = 128;
public static final int kAppearanceFilter = 256;
public static final String EMPTY_REASON_STRING = ".";
private static final ASName k_MDP = ASName.create((String)"MDP");
private static final ASName k_LegalAttestation = ASName.create((String)"LegalAttestation");
private static final ASName k_Reasons = ASName.create((String)"Reasons");
private static final ASName k_TimeStamp = ASName.create((String)"TimeStamp");
private static final ASName k_P = ASName.create((String)"P");
private static final ASName k_DigestMethod = ASName.create((String)"DigestMethod");
private static final ASName k_AddRevInfo = ASName.create((String)"AddRevInfo");
private static final ASName k_LockDocument = ASName.create((String)"LockDocument");
private static final ASName k_AppearanceFilter = ASName.create((String)"AppearanceFilter");
protected PDFSignatureFieldSeedValue(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFSignatureFieldSeedValue getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFSignatureFieldSeedValue pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFSignatureFieldSeedValue.class);
if (pdfObject == null) {
pdfObject = new PDFSignatureFieldSeedValue(cosObject);
}
return pdfObject;
}
public static PDFSignatureFieldSeedValue newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary cosObject = PDFCosObject.newCosDictionary(pdfDocument);
PDFSignatureFieldSeedValue pdfObject = new PDFSignatureFieldSeedValue((CosObject)cosObject);
pdfObject.setDictionaryNameValue(ASName.k_Type, ASName.k_SV);
return pdfObject;
}
public ASName getType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Type);
}
public ASName getFilter() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Filter);
}
public void setFilter(ASName filter) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_Filter, filter);
}
public ASName[] getSubFilters() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(ASName.k_SubFilter);
if (cosArray == null) {
return null;
}
ASName[] subFilters = new ASName[cosArray.size()];
for (int i = 0; i < subFilters.length; ++i) {
subFilters[i] = cosArray.getName(i);
}
return subFilters;
}
public void setSubFilters(ASName[] subFilters) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (subFilters == null) {
this.removeValue(ASName.k_SubFilter);
} else {
CosArray array = PDFCosObject.newCosArray(this.getPDFDocument());
int addAtIndex = 0;
for (int i = 0; i < subFilters.length; ++i) {
if (subFilters[i] == null) continue;
array.addName(addAtIndex++, subFilters[i]);
}
if (array.size() > 0) {
this.setDictionaryArrayValue(ASName.k_SubFilter, array);
} else {
this.removeValue(ASName.k_SubFilter);
}
}
}
public Double getVersion() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosDictionary().containsKey((Object)ASName.k_V)) {
return this.getDictionaryDoubleValue(ASName.k_V);
}
return null;
}
public void setVersion(Double version) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (version == null) {
this.removeValue(ASName.k_V);
} else {
this.setDictionaryDoubleValue(ASName.k_V, version);
}
}
public PDFCertificateSeedValue getPDFCertificateSeedValue() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFCertificateSeedValue.getInstance(this.getDictionaryCosObjectValue(ASName.k_Cert));
}
public void setPDFCertificateSeedValue(PDFCertificateSeedValue seedValues) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (seedValues == null || seedValues.isEmpty()) {
this.removeValue(ASName.k_Cert);
} else {
this.setDictionaryValue(ASName.k_Cert, seedValues);
}
}
public String[] getReasons() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(k_Reasons);
if (cosArray == null) {
return null;
}
String[] reasons = new String[cosArray.size()];
for (int i = 0; i < reasons.length; ++i) {
reasons[i] = cosArray.getString(i).asString();
}
return reasons;
}
public void setReasons(String[] reasons) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (reasons == null) {
this.removeValue(k_Reasons);
} else {
CosArray cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
for (int i = 0; i < reasons.length; ++i) {
if (reasons[i] == null || reasons[i].length() <= 0) continue;
cosArray.addText(reasons[i]);
}
if (cosArray.size() > 0) {
if (cosArray.size() == 1) {
if (cosArray.getText(0).equals(".")) {
this.removeValue(k_Reasons);
} else {
this.setDictionaryArrayValue(k_Reasons, cosArray);
}
} else {
this.setDictionaryArrayValue(k_Reasons, cosArray);
}
} else {
this.removeValue(k_Reasons);
}
}
}
public Integer getMDP() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary dict = this.getDictionaryDictionaryValue(k_MDP);
if (dict != null) {
CosObject cosObj = dict.get(ASName.k_P);
if (cosObj != null && cosObj instanceof CosNumeric) {
return ((CosNumeric)cosObj).intValue();
}
return null;
}
return null;
}
public void setMDP(Integer value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (value == null) {
this.removeValue(k_MDP);
} else {
CosDictionary dict = this.getDictionaryDictionaryValue(k_MDP);
if (dict == null) {
dict = PDFCosObject.newCosDictionary(this.getPDFDocument());
this.setDictionaryValue(k_MDP, (CosObject)dict);
}
dict.put(k_P, value.intValue());
}
}
public PDFTimeStampSeed getPDFTimeStamp() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFTimeStampSeed.getInstance(this.getDictionaryCosObjectValue(k_TimeStamp));
}
public void setPDFTimeStamp(PDFTimeStampSeed timeStamp) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(k_TimeStamp, timeStamp);
}
public String[] getLegalAttestations() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(k_LegalAttestation);
if (cosArray == null) {
return null;
}
String[] attests = new String[cosArray.size()];
for (int i = 0; i < attests.length; ++i) {
attests[i] = cosArray.getString(i).asString();
}
return attests;
}
public void setLegalAttestations(String[] attestations) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (attestations == null) {
this.removeValue(k_LegalAttestation);
} else {
CosArray cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
for (int i = 0; i < attestations.length; ++i) {
if (attestations[i] == null || attestations[i].length() <= 0) continue;
cosArray.addText(attestations[i]);
}
if (cosArray.size() > 0) {
this.setDictionaryArrayValue(k_LegalAttestation, cosArray);
} else {
this.removeValue(k_LegalAttestation);
}
}
}
public String getAppearanceFilter() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASString filter = this.getDictionaryStringValue(k_AppearanceFilter);
if (filter == null) {
return null;
}
return filter.asString();
}
public void setAppearanceFilter(String filter) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryStringValue(k_AppearanceFilter, filter);
}
public boolean getAddRevInfo() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosDictionary().containsKey((Object)k_AddRevInfo)) {
return this.getDictionaryBooleanValue(k_AddRevInfo);
}
return false;
}
public void setRevInfoFlag(boolean addRevInfo) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!addRevInfo) {
this.removeValue(k_AddRevInfo);
} else {
this.setDictionaryBooleanValue(k_AddRevInfo, addRevInfo);
}
}
public String[] getDigestMethod() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosArray = this.getDictionaryArrayValue(k_DigestMethod);
if (cosArray == null) {
return null;
}
String[] digestMethods = new String[cosArray.size()];
for (int i = 0; i < digestMethods.length; ++i) {
digestMethods[i] = cosArray.getName(i).asString(false);
}
return digestMethods;
}
public void setDigestMethod(String[] digestMethods) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (digestMethods == null) {
this.removeValue(k_DigestMethod);
} else {
CosArray cosArray = PDFCosObject.newCosArray(this.getPDFDocument());
for (int i = 0; i < digestMethods.length; ++i) {
if (digestMethods[i] == null || digestMethods[i].length() <= 0) {
throw new PDFInvalidParameterException("The digest method " + digestMethods[i] + " is not supported");
}
cosArray.addName(ASName.create((String)digestMethods[i]));
}
if (cosArray.size() > 0) {
this.setDictionaryArrayValue(k_DigestMethod, cosArray);
} else {
this.removeValue(k_DigestMethod);
}
}
}
public int getFlags() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosDictionary().containsKey((Object)ASName.k_Ff)) {
return this.getDictionaryIntValue(ASName.k_Ff);
}
return 0;
}
public void setFlags(Integer flags) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (flags == null) {
this.removeValue(ASName.k_Ff);
} else {
this.setDictionaryIntValue(ASName.k_Ff, flags.intValue());
}
}
public void setLockDocument(ASName value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(k_LockDocument, value);
}
public ASName getLockDocument() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.getCosDictionary().containsKey((Object)k_LockDocument)) {
return this.getDictionaryNameValue(k_LockDocument);
}
return null;
}
}