SignatureUtil { public boolean signatureCoversWholeDocument(String name) { getSignatureNames(); if (!sigNames.containsKey(name)) return false; try { ContentsChecker signatureReader = new ContentsChecker(document.getReader().getSafeFile().createSourceView()); return signatureReader.checkWhetherSignatureCoversWholeDocument(acroForm.getField(name)); } catch (IOException e) { throw new PdfException(e); } } SignatureUtil(PdfDocument document); @Deprecated static long[] asLongArray(PdfArray pdfArray); @Deprecated PdfPKCS7 verifySignature(String name); @Deprecated PdfPKCS7 verifySignature(String name, String provider); PdfPKCS7 readSignatureData(String signatureFieldName); PdfPKCS7 readSignatureData(String signatureFieldName, String securityProvider); PdfSignature getSignature(String name); PdfDictionary getSignatureDictionary(String name); List<String> getSignatureNames(); List<String> getBlankSignatureNames(); int getTotalRevisions(); int getRevision(String field); String getTranslatedFieldName(String name); InputStream extractRevision(String field); boolean signatureCoversWholeDocument(String name); boolean doesSignatureFieldExist(String name);  }
@Test public void firstBytesNotCoveredTest01() throws IOException { String inPdf = sourceFolder + "firstBytesNotCoveredTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertFalse(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void lastBytesNotCoveredTest01() throws IOException { String inPdf = sourceFolder + "lastBytesNotCoveredTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertFalse(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void lastBytesNotCoveredTest02() throws IOException { String inPdf = sourceFolder + "lastBytesNotCoveredTest02.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertFalse(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void bytesAreNotCoveredTest01() throws IOException { String inPdf = sourceFolder + "bytesAreNotCoveredTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertFalse(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void bytesAreCoveredTest01() throws IOException { String inPdf = sourceFolder + "bytesAreCoveredTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertTrue(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void bytesAreCoveredTest02() throws IOException { String inPdf = sourceFolder + "bytesAreCoveredTest02.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertTrue(signatureUtil.signatureCoversWholeDocument("sig")); }
@Test public void twoContentsTest01() throws IOException { String inPdf = sourceFolder + "twoContentsTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertTrue(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void spacesBeforeContentsTest01() throws IOException { String inPdf = sourceFolder + "spacesBeforeContentsTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertFalse(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void spacesBeforeContentsTest02() throws IOException { String inPdf = sourceFolder + "spacesBeforeContentsTest02.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertTrue(signatureUtil.signatureCoversWholeDocument("Signature1")); }
@Test public void notIndirectSigDictionaryTest() throws IOException { String inPdf = sourceFolder + "notIndirectSigDictionaryTest.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf)); SignatureUtil signatureUtil = new SignatureUtil(pdfDocument); Assert.assertTrue(signatureUtil.signatureCoversWholeDocument("Signature1")); }