diff options
| -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) |
