diff options
author | Rene Treffer <treffer@measite.de> | 2014-04-03 10:28:24 +0200 |
---|---|---|
committer | Rene Treffer <treffer@measite.de> | 2014-04-03 10:28:24 +0200 |
commit | 8a8a7f3b0dd7928802a97e346b307bb06fdb3322 (patch) | |
tree | 38bd5249f14eea9fd9ead6870d69ef4610693752 /src/de/measite | |
parent | 7d086eaf1a6a0b1d45e857eaf65ac53cd7a753e5 (diff) |
Add an IDN equals method to check names
Diffstat (limited to 'src/de/measite')
-rw-r--r-- | src/de/measite/minidns/util/NameUtil.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/de/measite/minidns/util/NameUtil.java b/src/de/measite/minidns/util/NameUtil.java index c42ac3eb..a7edc22a 100644 --- a/src/de/measite/minidns/util/NameUtil.java +++ b/src/de/measite/minidns/util/NameUtil.java @@ -6,6 +6,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.net.IDN; import java.util.HashSet; +import java.util.Arrays; public class NameUtil { @@ -13,6 +14,19 @@ public class NameUtil { return name.length() + 2; } + public static boolean idnEquals(String name1, String name2) { + if (name1 == name2) return true; // catches null, null + if (name1 == null) return false; + if (name2 == null) return false; + if (name1.equals(name2)) return true; + + try { + return Arrays.equals(toByteArray(name1),toByteArray(name2)); + } catch (IOException e) { + return false; // impossible + } + } + public static byte[] toByteArray(String name) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(64); DataOutputStream dos = new DataOutputStream(baos); |