From e03c6d0dfa0a95ac705028e45f0db3a7a7b9cd05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Mon, 18 Nov 2024 14:36:26 +0100 Subject: [PATCH] fix body of deprectaed sign response (#12) --- .../dto/DeprecatedSignedDocumentResponse.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/service/src/main/java/digital/slovensko/autogram/service/dto/DeprecatedSignedDocumentResponse.java b/service/src/main/java/digital/slovensko/autogram/service/dto/DeprecatedSignedDocumentResponse.java index 26a16bd..bfa77c4 100644 --- a/service/src/main/java/digital/slovensko/autogram/service/dto/DeprecatedSignedDocumentResponse.java +++ b/service/src/main/java/digital/slovensko/autogram/service/dto/DeprecatedSignedDocumentResponse.java @@ -1,25 +1,14 @@ package digital.slovensko.autogram.service.dto; -import digital.slovensko.autogram.core.errors.UnrecognizedException; import digital.slovensko.autogram.core.server.dto.Document; import eu.europa.esig.dss.model.DSSDocument; -import java.io.IOException; -import java.util.Base64; - public record DeprecatedSignedDocumentResponse(Document documentResponse, Signer signer) { - public static DeprecatedSignedDocumentResponse buildFormDSS(DSSDocument document, String signedBy, String issuedBy) { - try (var stream = document.openStream()) { - return new DeprecatedSignedDocumentResponse( - new Document( - Base64.getEncoder().encodeToString(stream.readAllBytes()), - document.getMimeType().getMimeTypeString() + ";base64", - document.getName()), - new Signer(signedBy, issuedBy) - ); - } catch (IOException e) { - throw new UnrecognizedException(e); - } + public static DeprecatedSignedDocumentResponse buildFormDSS(DSSDocument document, String signedBy, String issuedBy) { + return new DeprecatedSignedDocumentResponse( + (Document) Document.buildFromDSS(document), + new Signer(signedBy, issuedBy) + ); } }