Skip to content

Commit 9ef48e7

Browse files
author
rootware
committed
fixed redact count
1 parent 8a402b9 commit 9ef48e7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyredactkit"
7-
version = "0.3.1"
7+
version = "0.3.2"
88
description = "Python cli tool to redact sensitive data"
99
authors = ["brootware <[email protected]>"]
1010
license = "GPL-3.0-or-later"

pyredactkit/redact.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def process_custom_file(self, filename, customfile=str, savedir="./"):
219219
Returns:
220220
Creates redacted file.
221221
"""
222-
count = 0
223-
hash_map = {}
222+
redact_count = 0
223+
secret_map = {}
224224
try:
225225
# Open a file read pointer as target_file
226226
with open(filename, encoding="utf-8") as target_file:
@@ -250,23 +250,23 @@ def process_custom_file(self, filename, customfile=str, savedir="./"):
250250
) as result:
251251
# The supplied custom regex pattern file will be used to redact the file
252252
print(f"[+] {customfile} file supplied, will be redacting all supplied custom regex patterns")
253-
hash_map = {}
254-
253+
secret_map = {}
254+
custom_pattern = self.read_custom_patterns(customfile)
255255
for line in target_file:
256-
# count elements to be redacted
257-
for id in id_object.regexes:
258-
if re.search(id['pattern'], line):
259-
count += 1
256+
# redact_count elements to be redacted
257+
for id in range(len(custom_pattern)):
258+
if re.search(custom_pattern[id]['pattern'], line):
259+
redact_count += 1
260260
# redact all and write hashshadow
261261
data = self.redact_custom(line, customfile)
262262
redacted_line = data[0]
263263
kv_pairs = data[1]
264-
hash_map.update(kv_pairs)
264+
secret_map.update(kv_pairs)
265265
result.write(redacted_line)
266-
self.write_hashmap(hash_map, filename, savedir)
266+
self.write_hashmap(secret_map, filename, savedir)
267267
print(
268268
f"[+] .hashshadow_{os.path.basename(filename)}.json file generated. Keep this safe if you need to undo the redaction.")
269-
print(f"[+] Redacted {count} targets...")
269+
print(f"[+] Redacted {redact_count} targets...")
270270
print(
271271
f"[+] Redacted results saved to {savedir}redacted_{os.path.basename(filename)}")
272272

0 commit comments

Comments
 (0)