mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-25 04:06:14 +00:00
Add an ipv4 scrubber.
This commit is contained in:
@@ -66,6 +66,17 @@ public final class Scrubber {
|
||||
private static final Pattern UUID_PATTERN = Pattern.compile("(JOB::)?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{10})([0-9a-f]{2})", Pattern.CASE_INSENSITIVE);
|
||||
private static final String UUID_CENSOR = "********-****-****-****-**********";
|
||||
|
||||
/**
|
||||
* The entire string is censored.
|
||||
*/
|
||||
private static final Pattern IPV4_PATTERN = Pattern.compile("\\b" +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" +
|
||||
"\\b");
|
||||
private static final String IPV4_CENSOR = "...ipv4...";
|
||||
|
||||
/**
|
||||
* The domain name except for TLD will be censored.
|
||||
*/
|
||||
@@ -86,6 +97,7 @@ public final class Scrubber {
|
||||
in = scrubGroupsV2(in);
|
||||
in = scrubUuids(in);
|
||||
in = scrubDomains(in);
|
||||
in = scrubIpv4(in);
|
||||
|
||||
return in;
|
||||
}
|
||||
@@ -153,6 +165,13 @@ public final class Scrubber {
|
||||
});
|
||||
}
|
||||
|
||||
private static CharSequence scrubIpv4(@NonNull CharSequence in) {
|
||||
return scrub(in,
|
||||
IPV4_PATTERN,
|
||||
(matcher, output) -> output.append(IPV4_CENSOR));
|
||||
}
|
||||
|
||||
|
||||
private static CharSequence scrub(@NonNull CharSequence in, @NonNull Pattern pattern, @NonNull ProcessMatch processMatch) {
|
||||
final StringBuilder output = new StringBuilder(in.length());
|
||||
final Matcher matcher = pattern.matcher(in);
|
||||
|
||||
Reference in New Issue
Block a user