Commit 5988d7951b85f2e447f748546ea37e2cb13b2664

Authored by Christian Herdtweck
1 parent 4e1f626d

crypto: Do not throw from is_encrypted

Showing 1 changed file with 12 additions and 6 deletions
oletools/crypto.py
... ... @@ -229,12 +229,18 @@ def is_encrypted(some_file):
229 229 log.warning('Ignoring error during clean up: {}'.format(exc))
230 230  
231 231 # if that failed, try ourselves with older and less accurate code
232   - if isinstance(some_file, OleFileIO):
233   - return _is_encrypted_ole(some_file)
234   - if zipfile.is_zipfile(some_file):
235   - return _is_encrypted_zip(some_file)
236   - # otherwise assume it is the name of an ole file
237   - return _is_encrypted_ole(OleFileIO(some_file))
  232 + try:
  233 + if isinstance(some_file, OleFileIO):
  234 + return _is_encrypted_ole(some_file)
  235 + if zipfile.is_zipfile(some_file):
  236 + return _is_encrypted_zip(some_file)
  237 + # otherwise assume it is the name of an ole file
  238 + return _is_encrypted_ole(OleFileIO(some_file))
  239 + except Exception as exc:
  240 + log.warning('Failed to check {} for encryption ({}); assume it is not '
  241 + 'encrypted.'.format(some_file, exc))
  242 +
  243 + return False
238 244  
239 245  
240 246 def _is_encrypted_zip(filename):
... ...