From 2197a8f72dc31cbc8f625c412e205d00e52dccd2 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 14 Mar 2022 15:24:59 +0100 Subject: [PATCH] Refactoring --- .../java/eu/faircode/email/ActivityDmarc.java | 27 +------------------ .../eu/faircode/email/ConnectionHelper.java | 25 +++++++++++++++++ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityDmarc.java b/app/src/main/java/eu/faircode/email/ActivityDmarc.java index d8acef4b59..f6981b5480 100644 --- a/app/src/main/java/eu/faircode/email/ActivityDmarc.java +++ b/app/src/main/java/eu/faircode/email/ActivityDmarc.java @@ -282,7 +282,7 @@ public class ActivityDmarc extends ActivityBase { Integer prefix = Helper.parseInt(net[1]); if (prefix == null) continue; - if (inSubnet(text, net[0], prefix)) { + if (ConnectionHelper.inSubnet(text, net[0], prefix)) { valid = true; break; } @@ -504,31 +504,6 @@ public class ActivityDmarc extends ActivityBase { } return result; } - - private boolean inSubnet(final String ip, final String net, final int prefix) { - try { - byte[] _ip = InetAddress.getByName(ip).getAddress(); - byte[] _net = InetAddress.getByName(net).getAddress(); - - if (_ip.length != _net.length) - return false; - - int i = 0; - int p = prefix; - while (p >= 8) { - if (_ip[i] != _net[i]) - return false; - ++i; - p -= 8; - } - - int m = (0xFF00 >> p) & 0xFF; - return (_ip[i] & m) == (_net[i] & m); - } catch (Throwable ex) { - Log.w(ex); - return false; - } - } }.execute(this, args, "dmarc:decode"); } } diff --git a/app/src/main/java/eu/faircode/email/ConnectionHelper.java b/app/src/main/java/eu/faircode/email/ConnectionHelper.java index 2c15b1a7fb..ad78278e1c 100644 --- a/app/src/main/java/eu/faircode/email/ConnectionHelper.java +++ b/app/src/main/java/eu/faircode/email/ConnectionHelper.java @@ -518,6 +518,31 @@ public class ConnectionHelper { } } + static boolean inSubnet(final String ip, final String net, final int prefix) { + try { + byte[] _ip = InetAddress.getByName(ip).getAddress(); + byte[] _net = InetAddress.getByName(net).getAddress(); + + if (_ip.length != _net.length) + return false; + + int i = 0; + int p = prefix; + while (p >= 8) { + if (_ip[i] != _net[i]) + return false; + ++i; + p -= 8; + } + + int m = (0xFF00 >> p) & 0xFF; + return (_ip[i] & m) == (_net[i] & m); + } catch (Throwable ex) { + Log.w(ex); + return false; + } + } + static List getCommonNames(Context context, String domain, int port, int timeout) throws IOException { List result = new ArrayList<>(); InetSocketAddress address = new InetSocketAddress(domain, port);