Author: tilman Date: Tue Mar 6 21:21:15 2018 New Revision: 1826050 URL: http://svn.apache.org/viewvc?rev=1826050&view=rev Log: PDFBOX-4020: simplify code, by Alexis Suter
Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java?rev=1826050&r1=1826049&r2=1826050&view=diff ============================================================================== --- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java (original) +++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java Tue Mar 6 21:21:15 2018 @@ -97,9 +97,9 @@ public class CreateEmbeddedTimeStamp } /** - * Processes the timestamping of the Signature. - * - * @param output Where the new file will be written to + * Processes the time-stamping of the Signature. + * + * @param outFile Where the new file will be written to * @param fileName of the existing file containing the pdf * @throws IOException */ @@ -139,23 +139,18 @@ public class CreateEmbeddedTimeStamp { throw new IOException(e); } - catch (TSPException e) - { - throw new IOException(e); - } } /** * Create changed Signature with embedded TimeStamp from TSA * - * @param documentInput Stream of the input file + * @param documentBytes byte[] of the input file * @throws IOException * @throws CMSException * @throws NoSuchAlgorithmException - * @throws TSPException */ private void processRelevantSignatures(byte[] documentBytes) - throws IOException, CMSException, NoSuchAlgorithmException, TSPException + throws IOException, CMSException, NoSuchAlgorithmException { getRelevantSignature(document); if (signature != null) @@ -190,12 +185,11 @@ public class CreateEmbeddedTimeStamp } /** - * Extracts last Document-Signature from the document - * + * Extracts last Document-Signature from the document. The signature will be set on the + * signature-field. + * * @param document to get the Signature from - * - * @return the Signature, where a TimeStamp will be added. <code>null</code> when no - * Document-Signature is available. + * @throws IOException */ private void getRelevantSignature(PDDocument document) throws IOException { @@ -238,7 +232,7 @@ public class CreateEmbeddedTimeStamp output.write(docBytes, byteRange[2] - 1, byteRange[3] + 1); } - public static void main(String[] args) throws IOException, GeneralSecurityException + public static void main(String[] args) throws IOException { if (args.length != 3) { Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java?rev=1826050&r1=1826049&r2=1826050&view=diff ============================================================================== --- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java (original) +++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java Tue Mar 6 21:21:15 2018 @@ -107,11 +107,6 @@ public abstract class CreateSignatureBas this.certificateChain = certificateChain; } - public String getTsaUrl() - { - return tsaUrl; - } - public void setTsaUrl(String tsaUrl) { this.tsaUrl = tsaUrl; Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java?rev=1826050&r1=1826049&r2=1826050&view=diff ============================================================================== --- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java (original) +++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java Tue Mar 6 21:21:15 2018 @@ -82,12 +82,11 @@ public final class ShowSignature * @throws CertificateException * @throws java.security.NoSuchAlgorithmException * @throws java.security.NoSuchProviderException - * @throws java.security.SignatureException * @throws org.bouncycastle.tsp.TSPException */ public static void main(String[] args) throws IOException, CertificateException, - NoSuchAlgorithmException, - NoSuchProviderException, SignatureException, + NoSuchAlgorithmException, + NoSuchProviderException, TSPException { ShowSignature show = new ShowSignature(); @@ -96,7 +95,7 @@ public final class ShowSignature private void showSignature(String[] args) throws IOException, CertificateException, NoSuchAlgorithmException, - NoSuchProviderException, SignatureException, + NoSuchProviderException, TSPException { if( args.length != 2 ) @@ -267,7 +266,7 @@ public final class ShowSignature // http://stackoverflow.com/a/9261365/535646 CMSProcessable signedContent = new CMSProcessableByteArray(byteArray); CMSSignedData signedData = new CMSSignedData(signedContent, contents.getBytes()); - Store certificatesStore = signedData.getCertificates(); + Store<X509CertificateHolder> certificatesStore = signedData.getCertificates(); Collection<SignerInformation> signers = signedData.getSignerInfos().getSigners(); SignerInformation signerInformation = signers.iterator().next(); Collection<X509CertificateHolder> matches = certificatesStore.getMatches(signerInformation.getSID()); @@ -297,10 +296,10 @@ public final class ShowSignature } /** - * Analyzes the DSS-Dictionary (Document security Store) of the document. Which is used for + * Analyzes the DSS-Dictionary (Document Security Store) of the document. Which is used for * signature validation. The DSS is defined in PAdES Part 4 - Long Term Validation. * - * @param document + * @param document PDDocument, to get the DSS from */ private void analyseDSS(PDDocument document) throws IOException { @@ -326,7 +325,7 @@ public final class ShowSignature { printStreamsFromArray((COSArray) crlElement, "CRL"); } - // TODO: go through VRIs (wich indirectly point to the DSS-Data) + // TODO: go through VRIs (which indirectly point to the DSS-Data) } }