From d6f4b34eae2e977cdd0339fb17302976fdae0574 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Tue, 4 Oct 2022 15:02:43 +0200 Subject: QR code handling --- .../java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'pdf-over-signer/src') 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 80a7e14d..c7be135f 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,8 +11,10 @@ import at.asit.pdfover.signer.ByteArrayDocumentSource; import at.asit.pdfover.signer.SignResult; import at.asit.pdfover.signer.SignatureException; import at.asit.pdfover.signer.SignaturePosition; +import at.asit.pdfover.signer.UserCancelledException; import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.common.exceptions.SLPdfAsException; import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource; import at.gv.egiz.pdfas.lib.api.Configuration; import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; @@ -104,7 +106,7 @@ public class PdfAs4Signer { } } - public static SignResult sign(PdfAs4SigningState state) throws SignatureException { + public static SignResult sign(PdfAs4SigningState state) throws SignatureException, UserCancelledException { try { if (state == null) { throw new SignatureException("Incorrect SigningState!"); @@ -154,6 +156,16 @@ public class PdfAs4Signer { return result; } } catch (PdfAsException | PDFASError e) { + { // TODO hack around pdf-as not handling this error code properly cf. #124 + Throwable rootCause = e; + while (rootCause.getCause() != null) + rootCause = rootCause.getCause(); + try { /* error code 6001 is user cancellation */ + if (((SLPdfAsException)rootCause).getMessage().startsWith("6001 :")) + throw new UserCancelledException(); + } catch (ClassCastException e2) { /* fall through to wrapped throw */} + } + throw new SignatureException(e); } } -- cgit v1.2.3