From 171156dfe1d2ebe3f69041777ae6b20ece94dfa8 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Thu, 28 Feb 2019 15:50:07 +0100 Subject: [PATCH] common: diversify crypto-based errors --- oletools/common/errors.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/oletools/common/errors.py b/oletools/common/errors.py index 4ee4cb1..f492011 100644 --- a/oletools/common/errors.py +++ b/oletools/common/errors.py @@ -4,10 +4,33 @@ Errors used in several tools to avoid duplication .. codeauthor:: Intra2net AG """ -class FileIsEncryptedError(ValueError): +class CryptoErrorBase(ValueError): + """Base class for crypto-based exceptions.""" + pass + +class UnsupportedEncryptionError(CryptoErrorBase): """Exception thrown if file is encrypted and cannot deal with it.""" - # see also: same class in olevba[3] and record_base def __init__(self, filename=None): - super(FileIsEncryptedError, self).__init__( + super(UnsupportedEncryptionError, self).__init__( 'Office file {}is encrypted, not yet supported' .format('' if filename is None else filename + ' ')) + + +class WrongEncryptionPassword(CryptoErrorBase): + """Exception thrown if encryption could be handled but passwords wrong.""" + def __init__(self, filename=None): + super(WrongEncryptionPassword, self).__init__( + 'Given passwords could not decrypt office file{}' + .format('' if filename is None else ' ' + filename)) + + +class MaxCryptoNestingReached(CryptoErrorBase): + """ + Exception thrown if decryption is too deeply layered. + + (...or decrypt code creates inf loop) + """ + def __init__(self, n_layers, filename=None): + super(MaxCryptoNestingReached, self).__init__( + 'Encountered more than {} layers of encryption for office file{}' + .format(n_layers, '' if filename is None else ' ' + filename)) -- libgit2 0.21.4