Return-Path: X-Original-To: apmail-pdfbox-commits-archive@www.apache.org Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 54B1A1032C for ; Mon, 1 Dec 2014 21:06:58 +0000 (UTC) Received: (qmail 60749 invoked by uid 500); 1 Dec 2014 21:06:58 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 60728 invoked by uid 500); 1 Dec 2014 21:06:58 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 60712 invoked by uid 99); 1 Dec 2014 21:06:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2014 21:06:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2014 21:06:56 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BF0BD238939D; Mon, 1 Dec 2014 21:06:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1642756 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Date: Mon, 01 Dec 2014 21:06:36 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141201210636.BF0BD238939D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tilman Date: Mon Dec 1 21:06:36 2014 New Revision: 1642756 URL: http://svn.apache.org/r1642756 Log: PDFBOX-2533: add decryptDictionary method that supports recursion; renamed decrypt to decryptString Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1642756&r1=1642755&r2=1642756&view=diff ============================================================================== --- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java (original) +++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Mon Dec 1 21:06:36 2014 @@ -1462,35 +1462,11 @@ public class NonSequentialPDFParser exte // decrypt if (pb instanceof COSString) { - decrypt((COSString) pb, objNr, objGenNr); + decryptString((COSString) pb, objNr, objGenNr); } else if (pb instanceof COSDictionary) { - COSDictionary dict = (COSDictionary) pb; - // skip dictionary containing the signature - if (!COSName.SIG.equals(dict.getItem(COSName.TYPE))) - { - for (Entry entry : dict.entrySet()) - { - if (entry.getValue() instanceof COSString) - { - decrypt((COSString) entry.getValue(), objNr, objGenNr); - } - else if (entry.getValue() instanceof COSArray) - { - try - { - securityHandler.decryptArray((COSArray) entry.getValue(), objNr, objGenNr); - } - catch (CryptographyException ce) - { - throw new IOException("Error decrypting stream object " + objNr + ": " - + ce.getMessage() - /* , ce // TODO: remove remark with Java 1.6 */); - } - } - } - } + decryptDictionary((COSDictionary) pb, objNr, objGenNr); } else if (pb instanceof COSArray) { @@ -1499,7 +1475,7 @@ public class NonSequentialPDFParser exte { if (array.get(aIdx) instanceof COSString) { - decrypt((COSString) array.get(aIdx), objNr, objGenNr); + decryptString((COSString) array.get(aIdx), objNr, objGenNr); } } } @@ -1562,6 +1538,46 @@ public class NonSequentialPDFParser exte // ------------------------------------------------------------------------ /** + * + * @param dict the dictionary to be decrypted + * @param the object number + * @param objGenNr the object generation number + * @throws IOException ff something went wrong + */ + protected final void decryptDictionary(COSDictionary dict, long objNr, long objGenNr) throws IOException + { + // skip dictionary containing the signature + if (!COSName.SIG.equals(dict.getItem(COSName.TYPE))) + { + for (Entry entry : dict.entrySet()) + { + if (entry.getValue() instanceof COSString) + { + decryptString((COSString) entry.getValue(), objNr, objGenNr); + } + else if (entry.getValue() instanceof COSArray) + { + try + { + securityHandler.decryptArray((COSArray) entry.getValue(), objNr, objGenNr); + } + catch (CryptographyException ce) + { + throw new IOException("Error decrypting stream object " + objNr + ": " + + ce.getMessage() + /* , ce // TODO: remove remark with Java 1.6 */); + } + } + else if (entry.getValue() instanceof COSDictionary) + { + decryptDictionary((COSDictionary) entry.getValue(), objNr, objGenNr); + } + } + } + } + + + /** * Decrypts given COSString. * * @param str the string to be decrypted @@ -1569,7 +1585,7 @@ public class NonSequentialPDFParser exte * @param objGenNr the object generation number * @throws IOException ff something went wrong */ - protected final void decrypt(COSString str, long objNr, long objGenNr) throws IOException + protected final void decryptString(COSString str, long objNr, long objGenNr) throws IOException { try {