Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
babenek committed Oct 26, 2022
1 parent e816a68 commit 74fa40e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions credsweeper/app.py
Expand Up @@ -366,11 +366,11 @@ def data_scan(self, data_provider: DataContentProvider, depth: int, recursive_li
candidates.extend(self.struct_scan(struct_data_provider, depth, recursive_limit_size))

elif data_provider.is_xml():
struct_data_provider = StringContentProvider(lines=data_provider.lines,
string_data_provider = StringContentProvider(lines=data_provider.lines,
file_path=data_provider.file_path,
file_type=".xml",
info=f"{data_provider.info}|XML")
candidates.extend(self.file_scan(struct_data_provider))
candidates.extend(self.file_scan(string_data_provider))

else:
# finally try scan the data via byte content provider
Expand Down Expand Up @@ -423,21 +423,21 @@ def struct_scan(self, struct_provider: StructContentProvider, depth: int, recurs
candidates.extend(self.struct_scan(val_struct_provider, depth, recursive_limit_size))

elif isinstance(value, bytes):
val_struct_provider = DataContentProvider(data=value,
file_path=struct_provider.file_path,
file_type=struct_provider.file_type,
info=f"{struct_provider.info}|BYTES:{key}")
bytes_struct_provider = DataContentProvider(data=value,
file_path=struct_provider.file_path,
file_type=struct_provider.file_type,
info=f"{struct_provider.info}|BYTES:{key}")
new_limit = recursive_limit_size - len(value)
new_candidates = self.data_scan(val_struct_provider, depth, new_limit)
new_candidates = self.data_scan(bytes_struct_provider, depth, new_limit)
candidates.extend(new_candidates)

elif isinstance(value, str):
val_struct_provider = DataContentProvider(data=value.encode(encoding=DEFAULT_ENCODING),
str_struct_provider = DataContentProvider(data=value.encode(encoding=DEFAULT_ENCODING),
file_path=struct_provider.file_path,
file_type=struct_provider.file_type,
info=f"{struct_provider.info}|STRING:{key}")
new_limit = recursive_limit_size - len(val_struct_provider.data)
new_candidates = self.data_scan(val_struct_provider, depth, new_limit)
new_limit = recursive_limit_size - len(str_struct_provider.data)
new_candidates = self.data_scan(str_struct_provider, depth, new_limit)
candidates.extend(new_candidates)

# use key = "value" scan for common cases like in Python code
Expand All @@ -448,8 +448,8 @@ def struct_scan(self, struct_provider: StructContentProvider, depth: int, recurs
info=f"{struct_provider.info}|STRING:`{key} = \"{value}\"`")
extra_candidates = self.file_scan(str_provider)
if extra_candidates:
found_values = set(
line_data.value for candidate in candidates for line_data in candidate.line_data_list)
found_values = set(line_data.value for candidate in candidates
for line_data in candidate.line_data_list)
for extra_candidate in extra_candidates:
for line_data in extra_candidate.line_data_list:
if line_data.value not in found_values:
Expand Down
2 changes: 1 addition & 1 deletion credsweeper/utils/util.py
Expand Up @@ -3,7 +3,7 @@
import math
import os
from dataclasses import dataclass
from typing import Dict, List, Tuple, Optional, Any, Set
from typing import Dict, List, Tuple, Optional, Any

import whatthepatch
import yaml
Expand Down

0 comments on commit 74fa40e

Please sign in to comment.