Skip to content

Commit

Permalink
rm unused error names from handler and fix unintended default values …
Browse files Browse the repository at this point in the history
…in parameters
  • Loading branch information
celuchmarek committed Apr 18, 2024
1 parent d9bc029 commit 1a2ecc3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
7 changes: 0 additions & 7 deletions src/main/java/digital/slovensko/avm/core/SigningJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@
import digital.slovensko.avm.core.errors.AutogramException;
import digital.slovensko.avm.core.errors.DataToSignMismatchException;
import digital.slovensko.avm.util.DSSUtils;
import eu.europa.esig.dss.AbstractSignatureParameters;
import eu.europa.esig.dss.asic.cades.ASiCWithCAdESSignatureParameters;
import eu.europa.esig.dss.asic.cades.signature.ASiCWithCAdESService;
import eu.europa.esig.dss.asic.xades.ASiCWithXAdESSignatureParameters;
import eu.europa.esig.dss.asic.xades.signature.ASiCWithXAdESService;
import eu.europa.esig.dss.cades.CAdESSignatureParameters;
import eu.europa.esig.dss.cades.signature.CAdESService;
import eu.europa.esig.dss.enumerations.ASiCContainerType;
import eu.europa.esig.dss.enumerations.SignatureForm;
import eu.europa.esig.dss.jades.JAdESSignatureParameters;
import eu.europa.esig.dss.jades.signature.JAdESService;
import eu.europa.esig.dss.model.*;
import eu.europa.esig.dss.pades.PAdESSignatureParameters;
import eu.europa.esig.dss.pades.signature.PAdESService;
import eu.europa.esig.dss.signature.AbstractSignatureService;
import eu.europa.esig.dss.validation.CertificateVerifier;
import eu.europa.esig.dss.validation.CommonCertificateVerifier;
import eu.europa.esig.dss.xades.XAdESSignatureParameters;
import eu.europa.esig.dss.xades.signature.XAdESService;

import static digital.slovensko.avm.core.AutogramMimeType.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public ErrorResponseBody getBody() {
public static ErrorResponse buildFromException(Exception e) {
// TODO maybe replace with pattern matching someday
return switch (e.getClass().getSimpleName()) {
case "SigningCanceledByUserException" -> new ErrorResponse(204, "USER_CANCELLED", (AutogramException) e);
case "UnrecognizedException" -> new ErrorResponse(502, "UNRECOGNIZED_DSS_ERROR", (AutogramException) e);
case "UnsupportedSignatureLevelException" -> new ErrorResponse(422, "UNSUPPORTED_SIGNATURE_LEVEL", (AutogramException) e);
case "RequestValidationException",
Expand All @@ -43,11 +42,6 @@ public static ErrorResponse buildFromException(Exception e) {
case "MalformedBodyException" -> new ErrorResponse(400, "MALFORMED_INPUT", (AutogramException) e);
case "AutogramException" -> new ErrorResponse(502, "SIGNING_FAILED", (AutogramException) e);
case "EmptyBodyException" -> new ErrorResponse(400, "EMPTY_BODY", (AutogramException) e);
case "BatchEndedException" -> new ErrorResponse(400, "BATCH_ENDED", (AutogramException) e);
case "BatchExpiredException" -> new ErrorResponse(400, "BATCH_EXPIRED", (AutogramException) e);
case "BatchNotStartedException" -> new ErrorResponse(400, "BATCH_NOT_STARTED", (AutogramException) e);
case "BatchInvalidIdException" -> new ErrorResponse(404, "BATCH_NOT_FOUND", (AutogramException) e);
case "BatchConflictException" -> new ErrorResponse(400, "BATCH_CONFLICT", (AutogramException) e);
case "DataToSignMismatchException" -> new ErrorResponse(400, "DATATOSIGN_MISMATCH", (AutogramException) e);
default -> new ErrorResponse(500, "INTERNAL_ERROR", "Unexpected exception signing document", e.getMessage());
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void validateSigningParameters() throws RequestValidationException, Malfo
if (documentSignatureLevel == null)
throw new RequestValidationException("Parameters are required for yet to be signed document", "");

parameters = new ServerSigningParameters();
parameters = ServerSigningParameters.buildEmpty();
}

parameters.validate(getDocument().getMimeType(), documentSignatureLevel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,29 @@ public ServerSigningParameters(SignatureLevel level, ASiCContainerType container
this.transformationTargetEnvironment = transformationTargetEnvironment;
}

public ServerSigningParameters() {
this.level = null;
this.container = null;
this.containerXmlns = null;
this.packaging = null;
this.digestAlgorithm = null;
this.en319132 = null;
this.infoCanonicalization = null;
this.propertiesCanonicalization = null;
this.keyInfoCanonicalization = null;
this.schema = null;
this.transformation = null;
this.identifier = null;
this.checkPDFACompliance = false;
this.autoLoadEform = true;
this.embedUsedSchemas = false;
this.schemaIdentifier = null;
this.transformationIdentifier = null;
this.transformationLanguage = null;
this.transformationMediaDestinationTypeDescription = null;
this.transformationTargetEnvironment = null;

public static ServerSigningParameters buildEmpty() {
return new ServerSigningParameters(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
false,
true,
false,
null,
null,
null,
null,
null);
};

public SigningParameters getSigningParameters(boolean isBase64, DSSDocument document, TSPSource tspSource, boolean plainXmlEnabled) {
Expand Down

0 comments on commit 1a2ecc3

Please sign in to comment.