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))