Skip to content

Commit

Permalink
Switch mime types to set for good
Browse files Browse the repository at this point in the history
The set of mime types is an actual set of unique elements. No need to
convert back and forth from list.
  • Loading branch information
michaelweiser committed Aug 31, 2018
1 parent 834c520 commit 7963921
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions peekaboo/ruleset/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def file_type_on_whitelist(config, s):

whitelist = config['file_type_on_whitelist']['whitelist']

if set(s.mimetypes).issubset(set(whitelist)):
if s.mimetypes.issubset(set(whitelist)):
return RuleResult(position,
result=Result.ignored,
reason="Dateityp ist auf Whitelist",
Expand All @@ -99,7 +99,7 @@ def file_type_on_greylist(config, s):

greylist = config['file_type_on_greylist']['greylist']

if set(s.mimetypes).issubset(set(greylist)):
if s.mimetypes.issubset(set(greylist)):
return RuleResult(position,
result=Result.unknown,
reason="Dateityp ist auf der Liste der zu analysiserenden Typen",
Expand Down
14 changes: 7 additions & 7 deletions peekaboo/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def mimetypes(self):
determine mime on original p[0-9]* file
later result will be "inode/symlink"
"""
mime_types = []
mime_types = set()

smime = {
'p7s': [
Expand All @@ -306,7 +306,7 @@ def mimetypes(self):
declared_mt = self.get_attr('meta_info_type_declared')
if declared_mt is not None:
logger.debug('Sample declared as "%s"' % declared_mt)
mime_types.append(declared_mt)
mime_types.add(declared_mt)
except Exception as e:
logger.exception(e)
declared_mt = None
Expand All @@ -318,19 +318,19 @@ def mimetypes(self):
declared_filename = self.__filename

content_based_mime_type = guess_mime_type_from_file_contents(self.__path)
if content_based_mime_type is not None and content_based_mime_type not in mime_types:
mime_types.append(content_based_mime_type)
if content_based_mime_type is not None:
mime_types.add(content_based_mime_type)

name_based_mime_type = guess_mime_type_from_filename(declared_filename)
if name_based_mime_type is not None and name_based_mime_type not in mime_types:
mime_types.append(name_based_mime_type)
if name_based_mime_type is not None:
mime_types.add(name_based_mime_type)

logger.debug('Determined MIME Types: %s' % mime_types)
# check if the sample is an S/MIME signature (smime.p7s)
# If so, don't overwrite the MIME type since we do not want to analyse S/MIME signatures.
if declared_filename == 'smime.p7s' and declared_mt in smime['p7s']:
logger.info('S/MIME signature detected. Using declared MIME type over detected ones.')
mime_types = [declared_mt]
mime_types = set([declared_mt])

if not self.has_attr('mimetypes'):
self.set_attr('mimetypes', mime_types)
Expand Down

0 comments on commit 7963921

Please sign in to comment.