pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1849558 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java
Date Sat, 22 Dec 2018 16:18:40 GMT
Author: tilman
Date: Sat Dec 22 16:18:40 2018
New Revision: 1849558

URL: http://svn.apache.org/viewvc?rev=1849558&view=rev
Log:
PDFBOX-4413: add method to get / set DefaultCryptFilter; avoid ClassCastException in getCryptFilterDictionary()

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java?rev=1849558&r1=1849557&r2=1849558&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java
Sat Dec 22 16:18:40 2018
@@ -461,21 +461,32 @@ public class PDEncryption
     }
 
     /**
+     * Returns the default crypt filter (for public-key security handler).
+     * 
+     * @return the default crypt filter if available.
+     */
+    public PDCryptFilterDictionary getDefaultCryptFilterDictionary() 
+    {
+        return getCryptFilterDictionary(COSName.DEFAULT_CRYPT_FILTER);
+    }
+
+    /**
      * Returns the crypt filter with the given name.
      * 
      * @param cryptFilterName the name of the crypt filter
      * 
      * @return the crypt filter with the given name if available
      */
-    public PDCryptFilterDictionary getCryptFilterDictionary(COSName cryptFilterName) 
+    public PDCryptFilterDictionary getCryptFilterDictionary(COSName cryptFilterName)
     {
-        COSDictionary cryptFilterDictionary = (COSDictionary) dictionary.getDictionaryObject(
COSName.CF );
-        if (cryptFilterDictionary != null)
+        // See CF in "Table 20 – Entries common to all encryption dictionaries"
+        COSBase base = dictionary.getDictionaryObject(COSName.CF);
+        if (base instanceof COSDictionary)
         {
-            COSDictionary stdCryptFilterDictionary = (COSDictionary)cryptFilterDictionary.getDictionaryObject(cryptFilterName);
-            if (stdCryptFilterDictionary != null)
+            COSBase base2 = ((COSDictionary) base).getDictionaryObject(cryptFilterName);
+            if (base2 instanceof COSDictionary)
             {
-                return new PDCryptFilterDictionary(stdCryptFilterDictionary);
+                return new PDCryptFilterDictionary((COSDictionary) base2);
             }
         }
         return null;
@@ -508,7 +519,17 @@ public class PDEncryption
     {
         setCryptFilterDictionary(COSName.STD_CF, cryptFilterDictionary);
     }
-    
+
+    /**
+     * Sets the default crypt filter (for public-key security handler).
+     *
+     * @param defaultFilterDictionary the standard crypt filter to set
+     */
+    public void setDefaultCryptFilterDictionary(PDCryptFilterDictionary defaultFilterDictionary)
+    {
+        setCryptFilterDictionary(COSName.DEFAULT_CRYPT_FILTER, defaultFilterDictionary);
+    }
+
     /**
      * Returns the name of the filter which is used for de/encrypting streams.
      * Default value is "Identity".



Mime
View raw message