From 8a8a7f3b0dd7928802a97e346b307bb06fdb3322 Mon Sep 17 00:00:00 2001 From: Rene Treffer Date: Thu, 3 Apr 2014 10:28:24 +0200 Subject: [PATCH] Add an IDN equals method to check names --- src/de/measite/minidns/util/NameUtil.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/de/measite/minidns/util/NameUtil.java b/src/de/measite/minidns/util/NameUtil.java index c42ac3ebe..a7edc22ad 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);