From 9144df55ff7eac00f7633da6b8e4b58bab923d1f Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Tue, 2 Aug 2022 14:36:45 +0200 Subject: YAGNI: SigningState interface --- .../at/asit/pdfover/signer/pdfas/PdfAs4Signer.java | 27 ++++++++-------------- .../pdfover/signer/pdfas/PdfAs4SigningState.java | 9 +------- 2 files changed, 11 insertions(+), 25 deletions(-) (limited to 'pdf-over-signer/src/main/java') diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java index 9959dcdf..9adf99aa 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java @@ -11,7 +11,6 @@ import at.asit.pdfover.signator.SignResult; import at.asit.pdfover.signator.SignResultImpl; import at.asit.pdfover.signator.SignatureException; import at.asit.pdfover.signator.SignaturePosition; -import at.asit.pdfover.signator.SigningState; import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource; @@ -41,7 +40,7 @@ public class PdfAs4Signer { protected static final String LOC_REF = "" + URL_TEMPLATE + ""; - public static SigningState prepare(PdfAs4SignatureParameter parameter) throws SignatureException { + public static PdfAs4SigningState prepare(PdfAs4SignatureParameter parameter) throws SignatureException { if (parameter == null) { throw new SignatureException("Incorrect SignatureParameter!"); @@ -85,35 +84,29 @@ public class PdfAs4Signer { return state; } - public static SignResult sign(SigningState state) throws SignatureException { + public static SignResult sign(PdfAs4SigningState state) throws SignatureException { try { - PdfAs4SigningState sstate = null; - - if (PdfAs4SigningState.class.isInstance(state)) { - sstate = PdfAs4SigningState.class.cast(state); - } - - if (sstate == null) { + if (state == null) { throw new SignatureException("Incorrect SigningState!"); } // Retrieve objects PdfAs pdfas = PdfAs4Helper.getPdfAs(); - SignParameter param = sstate.getSignParameter(); + SignParameter param = state.getSignParameter(); Configuration config = param.getConfiguration(); config.setValue(IConfigurationConstants.SL_REQUEST_TYPE, - sstate.getUseBase64Request() ? + state.getUseBase64Request() ? IConfigurationConstants.SL_REQUEST_TYPE_BASE64 : IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD); IPlainSigner signer; - if (sstate.hasBKUConnector()) { - ISLConnector connector = new PdfAs4BKUSLConnector(sstate.getBKUConnector()); + if (state.hasBKUConnector()) { + ISLConnector connector = new PdfAs4BKUSLConnector(state.getBKUConnector()); signer = new PAdESSigner(connector); - } else if (sstate.hasKSSigner()) { - signer = sstate.getKSSigner(); + } else if (state.hasKSSigner()) { + signer = state.getKSSigner(); } else { throw new SignatureException("SigningState doesn't have a signer"); } @@ -137,7 +130,7 @@ public class PdfAs4Signer { result.setSignaturePosition(sp); } - result.setSignedDocument(new ByteArrayDocumentSource(sstate.getOutput().toByteArray())); + result.setSignedDocument(new ByteArrayDocumentSource(state.getOutput().toByteArray())); return result; } catch (PdfAsException | PDFASError e) { throw new SignatureException(e); diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java index f0aff1c8..0fe32b25 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java @@ -22,7 +22,6 @@ import at.asit.pdfover.signator.BkuSlConnector; import at.asit.pdfover.signator.SLRequest; import at.asit.pdfover.signator.SLResponse; import at.asit.pdfover.signator.SignatureException; -import at.asit.pdfover.signator.SigningState; import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; import at.gv.egiz.pdfas.lib.api.sign.SignParameter; @@ -31,7 +30,7 @@ import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore; /** * Signing State for PDFAS Wrapper */ -public class PdfAs4SigningState implements SigningState { +public class PdfAs4SigningState { /** * The Signature Layer request @@ -59,7 +58,6 @@ public class PdfAs4SigningState implements SigningState { /* (non-Javadoc) * @see at.asit.pdfover.signator.SigningState#getSignatureRequest() */ - @Override public SLRequest getSignatureRequest() { return this.slrequest; } @@ -75,7 +73,6 @@ public class PdfAs4SigningState implements SigningState { /* (non-Javadoc) * @see at.asit.pdfover.signator.SigningState#setUseBase64Request(boolean) */ - @Override public void setUseBase64Request(boolean useBase64Request) { this.useBase64Request = useBase64Request; } @@ -99,7 +96,6 @@ public class PdfAs4SigningState implements SigningState { /* (non-Javadoc) * @see at.asit.pdfover.signator.SigningState#setSignatureResponse(at.asit.pdfover.signator.SLResponse) */ - @Override public void setSignatureResponse(SLResponse response) { this.slresponse = response; } @@ -107,7 +103,6 @@ public class PdfAs4SigningState implements SigningState { /* (non-Javadoc) * @see at.asit.pdfover.signator.SigningState#hasSignatureResponse() */ - @Override public boolean hasSignatureResponse() { return this.slresponse != null; } @@ -143,7 +138,6 @@ public class PdfAs4SigningState implements SigningState { /* (non-Javadoc) * @see at.asit.pdfover.signator.SigningState#setBKUConnector(at.asit.pdfover.signator.BkuSlConnector) */ - @Override public void setBKUConnector(BkuSlConnector connector) { this.bkuconnector = connector; } @@ -151,7 +145,6 @@ public class PdfAs4SigningState implements SigningState { /* (non-Javadoc) * @see at.asit.pdfover.signator.SigningState#setKSSigner(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ - @Override public void setKSSigner(String file, String alias, String kspassword, String keypassword, String type) throws SignatureException { try { -- cgit v1.2.3