You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2017/05/30 16:04:52 UTC

svn commit: r1796885 - in /pdfbox/branches/2.0: examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Author: tilman
Date: Tue May 30 16:04:52 2017
New Revision: 1796885

URL: http://svn.apache.org/viewvc?rev=1796885&view=rev
Log:
PDFBOX-3811: improved sonar fix

Modified:
    pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java?rev=1796885&r1=1796884&r2=1796885&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java (original)
+++ pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java Tue May 30 16:04:52 2017
@@ -298,6 +298,7 @@ public class TestCreateSignature
         signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
         signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
         document.addSignature(signature);
+        int[] reserveByteRange = signature.getByteRange();
 
         String digestString = calculateDigestString(document.saveIncrementalForExternalSigning(new ByteArrayOutputStream()).getContent());
         boolean caught = false;
@@ -310,7 +311,7 @@ public class TestCreateSignature
             caught = true;
         }
         Assert.assertTrue("IllegalStateException should have been thrown", caught);
-        document.getLastSignatureDictionary().setByteRange(PDDocument.RESERVE_BYTE_RANGE);
+        document.getLastSignatureDictionary().setByteRange(reserveByteRange);
         Assert.assertEquals(digestString, calculateDigestString(document.saveIncrementalForExternalSigning(new ByteArrayOutputStream()).getContent()));
     }
 }

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1796885&r1=1796884&r2=1796885&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Tue May 30 16:04:52 2017
@@ -79,12 +79,15 @@ import org.apache.pdfbox.pdmodel.interac
 public class PDDocument implements Closeable
 {
     /**
-     * For signing: large reserve byte range used as placeholder in the saved PDF until actual the
-     * length of the PDF is known. You'll need to assign this yourself (with {@link PDSignature#setByteRange(int[])} ) only if you call 
-     * {@link #saveIncrementalForExternalSigning(java.io.OutputStream) saveIncrementalForExternalSigning()} twice.
+     * For signing: large reserve byte range used as placeholder in the saved PDF until the actual
+     * length of the PDF is known. You'll need to fetch (with
+     * {@link PDSignature#getByteRange()} ) and reassign this yourself (with
+     * {@link PDSignature#setByteRange(int[])} ) only if you call
+     * {@link #saveIncrementalForExternalSigning(java.io.OutputStream) saveIncrementalForExternalSigning()}
+     * twice.
      */
-    public static final int[] RESERVE_BYTE_RANGE = new int[] { 0, 1000000000, 1000000000, 1000000000 };
-        
+    private static final int[] RESERVE_BYTE_RANGE = new int[] { 0, 1000000000, 1000000000, 1000000000 };
+
     private static final Log LOG = LogFactory.getLog(PDDocument.class);
 
     /**
@@ -1356,7 +1359,7 @@ public class PDDocument implements Close
         if (!Arrays.equals(byteRange, RESERVE_BYTE_RANGE))
         {
             throw new IllegalStateException("signature reserve byte range has been changed "
-                    + "after addSignature(), please call setByteRange(RESERVE_BYTE_RANGE)");
+                    + "after addSignature(), please set the byte range that existed after addSignature()");
         }
         COSWriter writer = new COSWriter(output, pdfSource);
         writer.write(this);