From faa264c5b8c81df7480dde39950baba5c7ce802b Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Sun, 22 Jan 2023 10:02:07 +0100 Subject: openpgp: Pass OpenPGPSignatureData to OpenPGPVerificationFailure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- gemato/exceptions.py | 6 ++++-- gemato/openpgp.py | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gemato/exceptions.py b/gemato/exceptions.py index cf9208e..8492df9 100644 --- a/gemato/exceptions.py +++ b/gemato/exceptions.py @@ -120,8 +120,6 @@ class OpenPGPRuntimeError(GematoException): Base exception class for OpenPGP runtime errors. """ - __slots__ = ['output'] - def __init__(self, output): super().__init__(output) self.output = output @@ -159,6 +157,10 @@ class OpenPGPVerificationFailure(OpenPGPRuntimeError): An exception raised when OpenPGP verification fails. """ + def __init__(self, output, sig_data=None): + super().__init__(output) + self.sig_data = sig_data + def __str__(self): return f'OpenPGP verification failed:\n{self.output}' diff --git a/gemato/openpgp.py b/gemato/openpgp.py index 50166c4..8c1db59 100644 --- a/gemato/openpgp.py +++ b/gemato/openpgp.py @@ -239,23 +239,23 @@ class SystemGPGEnvironment: OpenPGPSignatureStatus.NO_PUBLIC_KEY, OpenPGPSignatureStatus.ERROR): raise OpenPGPVerificationFailure( - err.decode("utf8", errors="backslashreplace")) + err.decode("utf8", errors="backslashreplace"), sig) elif sig.sig_status == OpenPGPSignatureStatus.EXPIRED_KEY: raise OpenPGPExpiredKeyFailure( - err.decode('utf8', errors='backslashreplace')) + err.decode('utf8', errors='backslashreplace'), sig) elif sig.sig_status == OpenPGPSignatureStatus.REVOKED_KEY: raise OpenPGPRevokedKeyFailure( - err.decode('utf8', errors='backslashreplace')) + err.decode('utf8', errors='backslashreplace'), sig) else: raise OpenPGPUnknownSigFailure( - err.decode('utf8', errors='backslashreplace')) + err.decode('utf8', errors='backslashreplace'), sig) if not sig.valid_sig: raise OpenPGPUnknownSigFailure( - err.decode('utf8', errors='backslashreplace')) + err.decode('utf8', errors='backslashreplace'), sig) if not sig.trusted_sig: raise OpenPGPUntrustedSigFailure( - err.decode('utf8', errors='backslashreplace')) + err.decode('utf8', errors='backslashreplace'), sig) return sig_list -- cgit v1.2.3