Skip to content

Commit d7a5841

Browse files
author
rootware
committed
generates unique shadow files
1 parent 091bc55 commit d7a5841

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ redacted_*
66
ip_test.txt
77
multiredact
88
manhours*
9-
.hashshadow.json
9+
.hashshadow*
1010
*.txt
1111
.vscode
1212
# Ignoring sensitive files and directories.

pyredactkit/redact.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def allowed_file(self, file):
8282
return False
8383
return mimetypes.guess_type(file)[0] in self.get_allowed_files()
8484

85-
def write_hashmap(self, hash_map):
86-
with open(".hashshadow.json", "w", encoding="utf-8") as file:
85+
def write_hashmap(self, hash_map, filename):
86+
with open(f".hashshadow_{os.path.basename(filename)}.json", "w", encoding="utf-8") as file:
8787
json.dump(hash_map, file)
8888

8989
def valid_options(self):
@@ -99,7 +99,7 @@ def valid_options(self):
9999
option_tuple += id['type']
100100
return option_tuple
101101

102-
def redact_specific(self, line=str, option=str):
102+
def redact_specific(self, line=str, option=str, filename=str):
103103
"""Function to redact specific option
104104
Args:
105105
line (str) : line to be supplied to redact
@@ -122,7 +122,7 @@ def redact_specific(self, line=str, option=str):
122122
line = re.sub(
123123
redact_pattern, masked_data, line, flags=re.IGNORECASE)
124124

125-
self.write_hashmap(hash_map)
125+
self.write_hashmap(hash_map, filename)
126126
return line
127127

128128
def redact_name(self, data=str):
@@ -197,7 +197,7 @@ def process_file(self, filename, option=str, savedir="./"):
197197
line = re.sub(redact_pattern, masked_data, line,
198198
flags=re.IGNORECASE)
199199
result.write(line)
200-
self.write_hashmap(hash_map)
200+
self.write_hashmap(hash_map, filename)
201201
# Separate option to redact names
202202
elif option in ("name", "names"):
203203
content = target_file.read()
@@ -216,7 +216,7 @@ def process_file(self, filename, option=str, savedir="./"):
216216
for id in id_object.regexes:
217217
if option in id['type'] and re.search(id['pattern'], line, flags=re.IGNORECASE):
218218
count += 1
219-
line = self.redact_specific(line, option)
219+
line = self.redact_specific(line, option, filename)
220220
result.write(line)
221221

222222
print(f"[ + ] Redacted {count} targets...")

0 commit comments

Comments
 (0)