diff options
| author | Petr Svenda | 2021-01-15 13:33:35 +0100 |
|---|---|---|
| committer | Petr Svenda | 2021-01-15 13:33:35 +0100 |
| commit | fa1a79d5f267e25141200d3dbb9e3e593fa5e7c7 (patch) | |
| tree | b0da1194a9bd9459f98f89a66efb98bc8a7d022f | |
| parent | b03c2a3edb43e164d74c9286fd9e8ce30199a6d2 (diff) | |
| download | sec-certs-fa1a79d5f267e25141200d3dbb9e3e593fa5e7c7.tar.gz sec-certs-fa1a79d5f267e25141200d3dbb9e3e593fa5e7c7.tar.zst sec-certs-fa1a79d5f267e25141200d3dbb9e3e593fa5e7c7.zip | |
fixed recplacement of found strings to respect length and remove longest matches first (was not correctly removing matches before if substring)
| -rw-r--r-- | sec_certs/extract_certificates.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/sec_certs/extract_certificates.py b/sec_certs/extract_certificates.py index 3dd49c1c..2c6424d0 100644 --- a/sec_certs/extract_certificates.py +++ b/sec_certs/extract_certificates.py @@ -217,15 +217,23 @@ def parse_cert_file(file_name, search_rules, limit_max_lines=-1, line_separator= whole_text_with_newlines = whole_text_with_newlines.replace( match, 'x' * len(match)) + + + all_matches = [] # highlight all found strings from the input text and store the rest if not should_censure_right_away: for rule_group in items_found_all.keys(): items_found = items_found_all[rule_group] for rule in items_found.keys(): for match in items_found[rule]: - # warning - if AES string is removed before AES-128, -128 will be left in text (does it matter?) - whole_text_with_newlines = whole_text_with_newlines.replace( - match, 'x' * len(match)) + all_matches.append(match) + + # warning - if AES string is removed before AES-128, -128 would be left in text => sort by length first + # sort before replacement based on the length of match + all_matches.sort(key=len, reverse=True) + for match in all_matches: + whole_text_with_newlines = whole_text_with_newlines.replace( + match, 'x' * len(match)) return items_found_all, (whole_text_with_newlines, was_unicode_decode_error) |
