aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/demo/SignatureVerificationDemo.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/demo/SignatureVerificationDemo.java')
-rw-r--r--src/main/java/demo/SignatureVerificationDemo.java32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/main/java/demo/SignatureVerificationDemo.java b/src/main/java/demo/SignatureVerificationDemo.java
index 86d1bb8..950472e 100644
--- a/src/main/java/demo/SignatureVerificationDemo.java
+++ b/src/main/java/demo/SignatureVerificationDemo.java
@@ -12,6 +12,7 @@ import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters;
import at.gv.egiz.pdfas.api.analyze.AnalyzeResult;
import at.gv.egiz.pdfas.api.analyze.NonTextObjectInfo;
import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.api.commons.SignatureInformation;
import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
import at.gv.egiz.pdfas.api.io.DataSource;
import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters;
@@ -71,6 +72,30 @@ public class SignatureVerificationDemo {
AnalyzeResult analyzeResult = pdfasAPI.analyze(analyzeParameters);
System.out.println("Successfully analyzed.");
+ // information on non-textual objects can be used after analysis step and/or after verification
+ List signatures = analyzeResult.getSignatures();
+ if (signatures != null && !signatures.isEmpty()) {
+ int counter = 0;
+ Iterator sigIterator = signatures.iterator();
+ while (sigIterator.hasNext()) {
+ counter++;
+ SignatureInformation sigInfo = (SignatureInformation) sigIterator.next();
+ System.out.println("\n------------------------ SIGNATURE #" + counter + " ------------------------");
+ if (sigInfo.hasNonTextualObjects()) {
+ System.out.println("\nWARNING: " + sigInfo.getNonTextualObjects().size() + " non textual object(s) detected for this signature.");
+ Iterator noit = sigInfo.getNonTextualObjects().iterator();
+ while (noit.hasNext()) {
+ NonTextObjectInfo info = (NonTextObjectInfo) noit.next();
+ System.out.println(" -> " + info.toString());
+ }
+ System.out.println();
+
+ } else {
+ System.out.println("\nNo non-textual objects detected for this signature.");
+ }
+ }
+ }
+
// setup verification
VerifyAfterAnalysisParameters vaap = new VerifyAfterAnalysisParameters();
vaap.setAnalyzeResult(analyzeResult);
@@ -82,13 +107,16 @@ public class SignatureVerificationDemo {
System.out.println("Verifying...");
VerifyResults verifyResults = pdfasAPI.verify(vaap);
List verifyResultList = verifyResults.getResults();
- System.out.println("Verification complete.");
+ System.out.println("Verification complete.\n");
// iterate over results
PrintWriter out = new PrintWriter(System.out);
Iterator it = verifyResultList.iterator();
+ int counter = 0;
while (it.hasNext()) {
+ counter++;
VerifyResult result = (VerifyResult) it.next();
+ out.println("\n------------------------ SIGNATURE #" + counter + " ------------------------\n");
Main.formatVerifyResult(result, out);
// check if there are timestamps
@@ -98,7 +126,7 @@ public class SignatureVerificationDemo {
// check if non textual elements have been detected for this signature
if (result.hasNonTextualObjects()) {
- out.println("\nWARNING: Non textual objects detected for this signature");
+ out.println("\nWARNING: " + result.getNonTextualObjects().size() + " non textual object(s) detected for this signature");
Iterator noit = result.getNonTextualObjects().iterator();
while (noit.hasNext()) {
NonTextObjectInfo info = (NonTextObjectInfo) noit.next();