@@ -420,26 +420,13 @@ public PdfPadesSigner setTrustedCertificates(List<Certificate> certificateList)
420420 return this ;
421421 }
422422
423- private void performTimestamping (PdfDocument document , OutputStream outputStream , ITSAClient tsaClient )
423+ void performTimestamping (PdfDocument document , OutputStream outputStream , ITSAClient tsaClient )
424424 throws IOException , GeneralSecurityException {
425425 PdfSigner timestampSigner = new PdfSigner (document , outputStream , tempOutputStream , tempFile );
426426 timestampSigner .timestamp (tsaClient , timestampSignatureName );
427427 }
428428
429- private void performSignDetached (SignerProperties signerProperties , boolean isFinal ,
430- IExternalSignature externalSignature , Certificate [] chain , ITSAClient tsaClient )
431- throws GeneralSecurityException , IOException {
432- Certificate [] fullChain = issuingCertificateRetriever .retrieveMissingCertificates (chain );
433- PdfSigner signer = createPdfSigner (signerProperties , isFinal );
434- try {
435- signer .signDetached (externalDigest , externalSignature , fullChain , null , null , tsaClient ,
436- estimatedSize , CryptoStandard .CADES );
437- } finally {
438- signer .originalOS .close ();
439- }
440- }
441-
442- private PdfSigner createPdfSigner (SignerProperties signerProperties , boolean isFinal ) throws IOException {
429+ PdfSigner createPdfSigner (SignerProperties signerProperties , boolean isFinal ) throws IOException {
443430 String tempFilePath = null ;
444431 if (temporaryDirectoryPath != null ) {
445432 tempFilePath = getNextTempFile ().getAbsolutePath ();
@@ -464,7 +451,7 @@ private PdfSigner createPdfSigner(SignerProperties signerProperties, boolean isF
464451 return signer ;
465452 }
466453
467- private void performLtvVerification (PdfDocument pdfDocument , List <String > signatureNames ,
454+ void performLtvVerification (PdfDocument pdfDocument , List <String > signatureNames ,
468455 LtvVerification .RevocationDataNecessity revocationDataNecessity )
469456 throws IOException , GeneralSecurityException {
470457 LtvVerification ltvVerification = new LtvVerification (pdfDocument )
@@ -478,43 +465,28 @@ private void performLtvVerification(PdfDocument pdfDocument, List<String> signat
478465 ltvVerification .merge ();
479466 }
480467
481- private void deleteTempFiles () {
468+ void deleteTempFiles () {
482469 for (File tempFile : tempFiles ) {
483470 tempFile .delete ();
484471 }
485472 }
486473
487- private OutputStream createOutputStream () throws FileNotFoundException {
474+ OutputStream createOutputStream () throws FileNotFoundException {
488475 if (temporaryDirectoryPath != null ) {
489476 return FileUtil .getFileOutputStream (getNextTempFile ());
490477 }
491478 tempOutputStream = new ByteArrayOutputStream ();
492479 return tempOutputStream ;
493480 }
494481
495- private InputStream createInputStream () throws IOException {
482+ InputStream createInputStream () throws IOException {
496483 if (temporaryDirectoryPath != null ) {
497484 return FileUtil .getInputStreamForFile (tempFile );
498485 }
499486 return new ByteArrayInputStream (tempOutputStream .toByteArray ());
500487 }
501488
502- private File getNextTempFile () {
503- if (!FileUtil .directoryExists (temporaryDirectoryPath )) {
504- throw new PdfException (MessageFormatUtil .format (SignExceptionMessageConstant .PATH_IS_NOT_DIRECTORY ,
505- temporaryDirectoryPath ));
506- }
507- synchronized (LOCK_OBJECT ) {
508- do {
509- increment ++;
510- tempFile = new File (temporaryDirectoryPath + "/" + TEMP_FILE_NAME + increment + ".pdf" );
511- } while (tempFile .exists ());
512- tempFiles .add (tempFile );
513- }
514- return tempFile ;
515- }
516-
517- private void createRevocationClients (Certificate signingCert , boolean clientsRequired ) {
489+ void createRevocationClients (Certificate signingCert , boolean clientsRequired ) {
518490 if (crlClient == null && ocspClient == null && clientsRequired ) {
519491 X509Certificate signingCertificate = (X509Certificate ) signingCert ;
520492 if (CertificateUtil .getOCSPURL (signingCertificate ) == null &&
@@ -530,6 +502,34 @@ private void createRevocationClients(Certificate signingCert, boolean clientsReq
530502 }
531503 }
532504
505+ private void performSignDetached (SignerProperties signerProperties , boolean isFinal ,
506+ IExternalSignature externalSignature , Certificate [] chain , ITSAClient tsaClient )
507+ throws GeneralSecurityException , IOException {
508+ Certificate [] fullChain = issuingCertificateRetriever .retrieveMissingCertificates (chain );
509+ PdfSigner signer = createPdfSigner (signerProperties , isFinal );
510+ try {
511+ signer .signDetached (externalDigest , externalSignature , fullChain , null , null , tsaClient ,
512+ estimatedSize , CryptoStandard .CADES );
513+ } finally {
514+ signer .originalOS .close ();
515+ }
516+ }
517+
518+ private File getNextTempFile () {
519+ if (!FileUtil .directoryExists (temporaryDirectoryPath )) {
520+ throw new PdfException (MessageFormatUtil .format (SignExceptionMessageConstant .PATH_IS_NOT_DIRECTORY ,
521+ temporaryDirectoryPath ));
522+ }
523+ synchronized (LOCK_OBJECT ) {
524+ do {
525+ increment ++;
526+ tempFile = new File (temporaryDirectoryPath + "/" + TEMP_FILE_NAME + increment + ".pdf" );
527+ } while (tempFile .exists ());
528+ tempFiles .add (tempFile );
529+ }
530+ return tempFile ;
531+ }
532+
533533 private String getDigestAlgorithm (PrivateKey privateKey ) {
534534 String signatureAlgorithm = SignUtils .getPrivateKeyAlgorithm (privateKey );
535535 switch (signatureAlgorithm ) {
0 commit comments