Commit 171156dfe1d2ebe3f69041777ae6b20ece94dfa8

Authored by Christian Herdtweck
1 parent 805c5a1b

common: diversify crypto-based errors

Showing 1 changed file with 26 additions and 3 deletions
oletools/common/errors.py
... ... @@ -4,10 +4,33 @@ Errors used in several tools to avoid duplication
4 4 .. codeauthor:: Intra2net AG <info@intra2net.com>
5 5 """
6 6  
7   -class FileIsEncryptedError(ValueError):
  7 +class CryptoErrorBase(ValueError):
  8 + """Base class for crypto-based exceptions."""
  9 + pass
  10 +
  11 +class UnsupportedEncryptionError(CryptoErrorBase):
8 12 """Exception thrown if file is encrypted and cannot deal with it."""
9   - # see also: same class in olevba[3] and record_base
10 13 def __init__(self, filename=None):
11   - super(FileIsEncryptedError, self).__init__(
  14 + super(UnsupportedEncryptionError, self).__init__(
12 15 'Office file {}is encrypted, not yet supported'
13 16 .format('' if filename is None else filename + ' '))
  17 +
  18 +
  19 +class WrongEncryptionPassword(CryptoErrorBase):
  20 + """Exception thrown if encryption could be handled but passwords wrong."""
  21 + def __init__(self, filename=None):
  22 + super(WrongEncryptionPassword, self).__init__(
  23 + 'Given passwords could not decrypt office file{}'
  24 + .format('' if filename is None else ' ' + filename))
  25 +
  26 +
  27 +class MaxCryptoNestingReached(CryptoErrorBase):
  28 + """
  29 + Exception thrown if decryption is too deeply layered.
  30 +
  31 + (...or decrypt code creates inf loop)
  32 + """
  33 + def __init__(self, n_layers, filename=None):
  34 + super(MaxCryptoNestingReached, self).__init__(
  35 + 'Encountered more than {} layers of encryption for office file{}'
  36 + .format(n_layers, '' if filename is None else ' ' + filename))
... ...