directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [1/2] directory-kerberos git commit: Consolidating common utils
Date Tue, 13 Jan 2015 00:01:44 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/master 85b27a188 -> b7d418229


Consolidating common utils


Project: http://git-wip-us.apache.org/repos/asf/directory-kerberos/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerberos/commit/c58ed0ea
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerberos/tree/c58ed0ea
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerberos/diff/c58ed0ea

Branch: refs/heads/master
Commit: c58ed0ea117575c28cba8544f1112214ce125c2d
Parents: 85b27a1
Author: Drankye <drankye@gmail.com>
Authored: Tue Jan 13 08:00:32 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Tue Jan 13 08:00:32 2015 +0800

----------------------------------------------------------------------
 .../org/apache/haox/transport/BytesUtil.java    | 144 -------------------
 contrib/pom.xml                                 |   1 +
 haox-kerb/kerb-crypto/pom.xml                   |   2 +-
 .../apache/kerberos/kerb/crypto/BytesUtil.java  |  20 +++
 .../apache/kerberos/kerb/crypto/Camellia.java   |   6 +-
 .../org/apache/kerberos/kerb/crypto/Cmac.java   |   8 +-
 .../org/apache/kerberos/kerb/crypto/Util.java   |  24 ----
 .../kerberos/kerb/crypto/key/DesKeyMaker.java   |   3 +-
 .../kerberos/kerb/crypto/CamelliaEncTest.java   |   3 +-
 .../kerberos/kerb/crypto/CheckSumTest.java      |   3 +-
 .../kerberos/kerb/crypto/CheckSumsTest.java     |   5 +-
 .../apache/kerberos/kerb/crypto/CmacTest.java   |  13 +-
 .../apache/kerberos/kerb/crypto/Crc32Test.java  |   3 +-
 .../kerberos/kerb/crypto/DecryptionTest.java    |   5 +-
 .../kerberos/kerb/crypto/KeyDeriveTest.java     |   9 +-
 .../kerberos/kerb/crypto/String2keyTest.java    |   7 +-
 .../apache/kerberos/kerb/crypto/TestUtil.java   |  39 -----
 17 files changed, 58 insertions(+), 237 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/contrib/haox-event/src/main/java/org/apache/haox/transport/BytesUtil.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/BytesUtil.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/BytesUtil.java
deleted file mode 100644
index c3a3e99..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/transport/BytesUtil.java
+++ /dev/null
@@ -1,144 +0,0 @@
-package org.apache.haox.transport;
-
-public class BytesUtil {
-
-    public static short bytes2short(byte[] bytes, int offset, boolean bigEndian) {
-        short val = 0;
-
-        if (bigEndian) {
-            val += (bytes[offset + 0] & 0xff) << 8;
-            val += (bytes[offset + 1] & 0xff);
-        } else {
-            val += (bytes[offset + 1] & 0xff) << 8;
-            val += (bytes[offset + 0] & 0xff);
-        }
-
-        return val;
-    }
-
-    public static short bytes2short(byte[] bytes, boolean bigEndian) {
-        return bytes2short(bytes, 0, bigEndian);
-    }
-
-    public static byte[] short2bytes(int val, boolean bigEndian) {
-        byte[] bytes = new byte[2];
-
-        short2bytes(val, bytes, 0, bigEndian);
-
-        return bytes;
-    }
-
-    public static void short2bytes(int val, byte[] bytes, int offset, boolean bigEndian)
{
-        if (bigEndian) {
-            bytes[offset + 0] = (byte) ((val >> 8) & 0xff);
-            bytes[offset + 1] = (byte) ((val) & 0xff);
-        } else {
-            bytes[offset + 1] = (byte) ((val >>  8) & 0xff);
-            bytes[offset + 0] = (byte) ((val      ) & 0xff);
-        }
-    }
-
-    public static int bytes2int(byte[] bytes, boolean bigEndian) {
-        return bytes2int(bytes, 0, bigEndian);
-    }
-
-    public static int bytes2int(byte[] bytes, int offset, boolean bigEndian) {
-        int val = 0;
-
-        if (bigEndian) {
-            val += (bytes[offset + 0] & 0xff) << 24;
-            val += (bytes[offset + 1] & 0xff) << 16;
-            val += (bytes[offset + 2] & 0xff) << 8;
-            val += (bytes[offset + 3] & 0xff);
-        } else {
-            val += (bytes[offset + 3] & 0xff) << 24;
-            val += (bytes[offset + 2] & 0xff) << 16;
-            val += (bytes[offset + 1] & 0xff) << 8;
-            val += (bytes[offset + 0] & 0xff);
-        }
-
-        return val;
-    }
-
-    public static byte[] int2bytes(int val, boolean bigEndian) {
-        byte[] bytes = new byte[4];
-
-        int2bytes(val, bytes, 0, bigEndian);
-
-        return bytes;
-    }
-
-    public static void int2bytes(int val, byte[] bytes, int offset, boolean bigEndian) {
-        if (bigEndian) {
-            bytes[offset + 0] = (byte) ((val >> 24) & 0xff);
-            bytes[offset + 1] = (byte) ((val >> 16) & 0xff);
-            bytes[offset + 2] = (byte) ((val >> 8) & 0xff);
-            bytes[offset + 3] = (byte) ((val) & 0xff);
-        } else {
-            bytes[offset + 3] = (byte) ((val >> 24) & 0xff);
-            bytes[offset + 2] = (byte) ((val >> 16) & 0xff);
-            bytes[offset + 1] = (byte) ((val >> 8) & 0xff);
-            bytes[offset + 0] = (byte) ((val) & 0xff);
-        }
-    }
-
-    public static byte[] long2bytes(long val, boolean bigEndian) {
-        byte[] bytes = new byte[8];
-        long2bytes(val, bytes, 0, bigEndian);
-        return bytes;
-    }
-
-    public static void long2bytes(long val, byte[] bytes, int offset, boolean bigEndian)
{
-        if (bigEndian) {
-            for (int i = 0; i < 8; i++) {
-                bytes[i + offset] = (byte) ((val >> ((7 - i) * 8)) & 0xffL);
-            }
-        } else {
-            for (int i = 0; i < 8; i++) {
-                bytes[i + offset] = (byte) ((val >> (i * 8)) & 0xffL);
-            }
-        }
-    }
-
-    public static long bytes2long(byte[] bytes, boolean bigEndian) {
-        return bytes2long(bytes, 0, bigEndian);
-    }
-
-    public static long bytes2long(byte[] bytes, int offset, boolean bigEndian) {
-        long val = 0;
-
-        if (bigEndian) {
-            for (int i = 0; i < 8; i++) {
-                val |= (((long) bytes[i + offset]) & 0xffL) << ((7 - i) * 8);
-            }
-        } else {
-            for (int i = 0; i < 8; i++) {
-                val |= (((long) bytes[i + offset]) & 0xffL) << (i * 8);
-            }
-        }
-
-        return val;
-    }
-
-    public static byte[] padding(byte[] data, int block) {
-        int len = data.length;
-        int paddingLen = len % block != 0 ? 8 - len % block : 0;
-        if (paddingLen == 0) {
-            return data;
-        }
-
-        byte[] result = new byte[len + + paddingLen];
-        System.arraycopy(data, 0, result, 0, len);
-        return result;
-    }
-
-    public static byte[] duplicate(byte[] bytes) {
-        return duplicate(bytes, 0, bytes.length);
-    }
-
-    public static byte[] duplicate(byte[] bytes, int offset, int len) {
-        byte[] dup = new byte[len];
-        System.arraycopy(bytes, offset, dup, 0, len);
-        return dup;
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/contrib/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/pom.xml b/contrib/pom.xml
index 7fbc4a8..d1c413c 100644
--- a/contrib/pom.xml
+++ b/contrib/pom.xml
@@ -19,6 +19,7 @@
     <module>haox-asn1</module>
     <module>haox-pkix</module>
     <module>haox-token</module>
+    <module>haox-util</module>
   </modules>
 
   <dependencies>

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/pom.xml
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/pom.xml b/haox-kerb/kerb-crypto/pom.xml
index 589fc23..99419ea 100644
--- a/haox-kerb/kerb-crypto/pom.xml
+++ b/haox-kerb/kerb-crypto/pom.xml
@@ -16,7 +16,7 @@
   <dependencies>
     <dependency>
       <groupId>org.haox</groupId>
-      <artifactId>haox-config</artifactId>
+      <artifactId>haox-util</artifactId>
       <version>${project.version}</version>
     </dependency>
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/BytesUtil.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/BytesUtil.java
b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/BytesUtil.java
index 7282107..ee6c14b 100644
--- a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/BytesUtil.java
+++ b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/BytesUtil.java
@@ -141,4 +141,24 @@ public class BytesUtil {
         System.arraycopy(bytes, offset, dup, 0, len);
         return dup;
     }
+
+    public static void xor(byte[] input, int offset, byte[] output) {
+        int a, b;
+        for (int i = 0; i < output.length / 4; ++i) {
+            a = BytesUtil.bytes2int(input, offset + i * 4, true);
+            b = BytesUtil.bytes2int(output, i * 4, true);
+            b = a ^ b;
+            BytesUtil.int2bytes(b, output, i * 4, true);
+        }
+    }
+
+    public static void xor(byte[] a, byte[] b, byte[] output) {
+        int av, bv, v;
+        for (int i = 0; i < a.length / 4; ++i) {
+            av = BytesUtil.bytes2int(a, i * 4, true);
+            bv = BytesUtil.bytes2int(b, i * 4, true);
+            v = av ^ bv;
+            BytesUtil.int2bytes(v, output, i * 4, true);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Camellia.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Camellia.java
b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Camellia.java
index 89db740..9dbab8d 100644
--- a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Camellia.java
+++ b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Camellia.java
@@ -199,7 +199,7 @@ public class Camellia {
         byte[] cipher = new byte[BLOCK_SIZE];
         for (int i = 0; i < blocksNum; ++i) {
             System.arraycopy(data, offset + i * BLOCK_SIZE, cipher, 0, BLOCK_SIZE);
-            Util.xor(cipherState, 0, cipher);
+            BytesUtil.xor(cipherState, 0, cipher);
             processBlock(cipher, 0);
             System.arraycopy(cipher, 0, data, offset + i * BLOCK_SIZE, BLOCK_SIZE);
             System.arraycopy(cipher, 0, cipherState, 0, BLOCK_SIZE);
@@ -219,9 +219,9 @@ public class Camellia {
             processBlock(cipher, 0);
 
             if (i == 1) {
-                Util.xor(cipherState, 0, cipher);
+                BytesUtil.xor(cipherState, 0, cipher);
             } else {
-                Util.xor(data, offset + (i - 2) * BLOCK_SIZE, cipher);
+                BytesUtil.xor(data, offset + (i - 2) * BLOCK_SIZE, cipher);
             }
 
             System.arraycopy(cipher, 0, data, offset + (i - 1) * BLOCK_SIZE, BLOCK_SIZE);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
index 7f7d333..68391a8 100644
--- a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
+++ b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
@@ -81,10 +81,10 @@ public class Cmac {
         byte[] lastBlock = new byte[lastLen];
         System.arraycopy(data, lastPos, lastBlock, 0, lastLen);
         if (lastIsComplete) {
-            Util.xor(lastBlock, K1, mLast);
+            BytesUtil.xor(lastBlock, K1, mLast);
         } else {
             padding(lastBlock, padded);
-            Util.xor(padded, K2, mLast);
+            BytesUtil.xor(padded, K2, mLast);
         }
 
         // Step 6 (last block)
@@ -108,7 +108,7 @@ public class Cmac {
         } else {
             byte[] tmp = new byte[K1.length];
             leftShiftByOne(L, tmp);
-            Util.xor(tmp, constRb, K1);
+            BytesUtil.xor(tmp, constRb, K1);
         }
 
         // K2 := (MSB(K1) == 0) ? K1 << 1 : (K1 << 1) XOR const_Rb
@@ -117,7 +117,7 @@ public class Cmac {
         } else {
             byte[] tmp = new byte[K1.length];
             leftShiftByOne(K1, tmp);
-            Util.xor(tmp, constRb, K2);
+            BytesUtil.xor(tmp, constRb, K2);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Util.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Util.java
b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Util.java
deleted file mode 100644
index 58117b9..0000000
--- a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Util.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.apache.kerberos.kerb.crypto;
-
-public class Util {
-
-    public static void xor(byte[] input, int offset, byte[] output) {
-        int a, b;
-        for (int i = 0; i < output.length / 4; ++i) {
-            a = BytesUtil.bytes2int(input, offset + i * 4, true);
-            b = BytesUtil.bytes2int(output, i * 4, true);
-            b = a ^ b;
-            BytesUtil.int2bytes(b, output, i * 4, true);
-        }
-    }
-
-    public static void xor(byte[] a, byte[] b, byte[] output) {
-        int av, bv, v;
-        for (int i = 0; i < a.length / 4; ++i) {
-            av = BytesUtil.bytes2int(a, i * 4, true);
-            bv = BytesUtil.bytes2int(b, i * 4, true);
-            v = av ^ bv;
-            BytesUtil.int2bytes(v, output, i * 4, true);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/key/DesKeyMaker.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/key/DesKeyMaker.java
b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/key/DesKeyMaker.java
index 4a8dc56..b0e9fb8 100644
--- a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/key/DesKeyMaker.java
+++ b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/key/DesKeyMaker.java
@@ -3,7 +3,6 @@ package org.apache.kerberos.kerb.crypto.key;
 import org.apache.kerberos.kerb.KrbException;
 import org.apache.kerberos.kerb.crypto.BytesUtil;
 import org.apache.kerberos.kerb.crypto.Des;
-import org.apache.kerberos.kerb.crypto.Util;
 import org.apache.kerberos.kerb.crypto.enc.EncryptProvider;
 
 public class DesKeyMaker extends AbstractKeyMaker {
@@ -75,7 +74,7 @@ public class DesKeyMaker extends AbstractKeyMaker {
                 reverse(bits56);
             }
             odd = ! odd;
-            Util.xor(bits56, 0, tempString);
+            BytesUtil.xor(bits56, 0, tempString);
         }
 
         byte[] keyBytes = addParityBits(tempString);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CamelliaEncTest.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CamelliaEncTest.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CamelliaEncTest.java
index 41bab8f..1dfbc88 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CamelliaEncTest.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CamelliaEncTest.java
@@ -4,6 +4,7 @@ import org.apache.kerberos.kerb.KrbException;
 import org.apache.kerberos.kerb.crypto.enc.EncryptProvider;
 import org.apache.kerberos.kerb.crypto.enc.provider.Camellia128Provider;
 import org.apache.kerberos.kerb.crypto.enc.provider.Camellia256Provider;
+import org.haox.util.HexUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -75,7 +76,7 @@ public class CamelliaEncTest {
     }
 
     private void hexDump(String label, byte[] bytes) {
-        String line = label + "=" + TestUtil.bytesToHex(bytes);
+        String line = label + "=" + HexUtil.bytesToHex(bytes);
         outputs.add(line);
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumTest.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumTest.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumTest.java
index caa501d..9f9c46b 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumTest.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumTest.java
@@ -1,6 +1,7 @@
 package org.apache.kerberos.kerb.crypto;
 
 import org.apache.kerberos.kerb.spec.common.*;
+import org.haox.util.HexUtil;
 import org.junit.Test;
 
 /**
@@ -49,7 +50,7 @@ public class CheckSumTest {
     }
 
     private void testWith(CksumTest testCase) throws Exception {
-        byte[] knownChecksum = TestUtil.hex2bytes(testCase.knownChecksum);
+        byte[] knownChecksum = HexUtil.hex2bytes(testCase.knownChecksum);
         byte[] plainData = testCase.plainText.getBytes();
         CheckSum newCksum;
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumsTest.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumsTest.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumsTest.java
index 5941b29..1394994 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumsTest.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CheckSumsTest.java
@@ -4,6 +4,7 @@ import org.apache.kerberos.kerb.spec.common.CheckSum;
 import org.apache.kerberos.kerb.spec.common.CheckSumType;
 import org.apache.kerberos.kerb.spec.common.EncryptionType;
 import org.apache.kerberos.kerb.spec.common.KeyUsage;
+import org.haox.util.HexUtil;
 import org.junit.Test;
 
 /**
@@ -121,7 +122,7 @@ public class CheckSumsTest {
     }
 
     private void testWith(CksumTest testCase) throws Exception {
-        byte[] answer = TestUtil.hex2bytes(testCase.answer);
+        byte[] answer = HexUtil.hex2bytes(testCase.answer);
         byte[] plainData = testCase.plainText.getBytes();
         CheckSum newCksum;
 
@@ -137,7 +138,7 @@ public class CheckSumsTest {
                 return;
             }
 
-            byte[] key = TestUtil.hex2bytes(testCase.key);
+            byte[] key = HexUtil.hex2bytes(testCase.key);
             KeyUsage keyUsage = KeyUsage.fromValue(testCase.keyUsage);
             newCksum = CheckSumHandler.checksumWithKey(testCase.cksumType, plainData, key,
keyUsage);
             if (CheckSumHandler.verifyWithKey(newCksum, plainData, key, keyUsage)) {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CmacTest.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CmacTest.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CmacTest.java
index 99a26af..2e7bd7e 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CmacTest.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/CmacTest.java
@@ -3,6 +3,7 @@ package org.apache.kerberos.kerb.crypto;
 import org.apache.kerberos.kerb.KrbException;
 import org.apache.kerberos.kerb.crypto.enc.EncryptProvider;
 import org.apache.kerberos.kerb.crypto.enc.provider.Camellia128Provider;
+import org.haox.util.HexUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -41,25 +42,25 @@ public class CmacTest {
 
     @Test
     public void testCmac() throws KrbException, KrbException {
-        byte[] key = TestUtil.hex2bytes(keyBytes);
-        byte[] input = TestUtil.hex2bytes(inputBytes);
+        byte[] key = HexUtil.hex2bytes(keyBytes);
+        byte[] input = HexUtil.hex2bytes(inputBytes);
         EncryptProvider encProvider = new Camellia128Provider();
         byte[] result;
 
         // test 1
         result = Cmac.cmac(encProvider, key, input, 0, 0);
-        Assert.assertArrayEquals("Test 1", TestUtil.hex2bytes(cmac1), result);
+        Assert.assertArrayEquals("Test 1", HexUtil.hex2bytes(cmac1), result);
 
         // test 2
         result = Cmac.cmac(encProvider, key, input, 0, 16);
-        Assert.assertArrayEquals("Test 2", TestUtil.hex2bytes(cmac2), result);
+        Assert.assertArrayEquals("Test 2", HexUtil.hex2bytes(cmac2), result);
 
         // test 3
         result = Cmac.cmac(encProvider, key, input, 0, 40);
-        Assert.assertArrayEquals("Test 3", TestUtil.hex2bytes(cmac3), result);
+        Assert.assertArrayEquals("Test 3", HexUtil.hex2bytes(cmac3), result);
 
         // test 4
         result = Cmac.cmac(encProvider, key, input, 0, 64);
-        Assert.assertArrayEquals("Test 4", TestUtil.hex2bytes(cmac4), result);
+        Assert.assertArrayEquals("Test 4", HexUtil.hex2bytes(cmac4), result);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/Crc32Test.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/Crc32Test.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/Crc32Test.java
index f9b6b5d..d728278 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/Crc32Test.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/Crc32Test.java
@@ -1,5 +1,6 @@
 package org.apache.kerberos.kerb.crypto;
 
+import org.haox.util.HexUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -92,7 +93,7 @@ public class Crc32Test {
     }
 
     private boolean testWith(TestCase testCase) {
-        byte[] data = TestUtil.hex2bytes(testCase.data);
+        byte[] data = HexUtil.hex2bytes(testCase.data);
         long value = Crc32.crc(0, data, 0, data.length);
         return value == testCase.answer;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/DecryptionTest.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/DecryptionTest.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/DecryptionTest.java
index 389fab9..d942b23 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/DecryptionTest.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/DecryptionTest.java
@@ -22,6 +22,7 @@ package org.apache.kerberos.kerb.crypto;
 import org.apache.kerberos.kerb.spec.common.EncryptionKey;
 import org.apache.kerberos.kerb.spec.common.EncryptionType;
 import org.apache.kerberos.kerb.spec.common.KeyUsage;
+import org.haox.util.HexUtil;
 import org.junit.Test;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -58,8 +59,8 @@ public class DecryptionTest {
     private boolean testDecrypt(TestCase testCase) throws Exception {
         KeyUsage ku = KeyUsage.fromValue(testCase.keyUsage);
 
-        byte[] cipherBytes = TestUtil.hex2bytes(testCase.cipher);
-        byte[] keyBytes = TestUtil.hex2bytes(testCase.key);
+        byte[] cipherBytes = HexUtil.hex2bytes(testCase.cipher);
+        byte[] keyBytes = HexUtil.hex2bytes(testCase.key);
 
         EncryptionKey encKey = new EncryptionKey(testCase.encType, keyBytes);
         byte[] decrypted = EncryptionHandler.decrypt(cipherBytes, encKey, ku);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/KeyDeriveTest.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/KeyDeriveTest.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/KeyDeriveTest.java
index 2ae74d0..167b63a 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/KeyDeriveTest.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/KeyDeriveTest.java
@@ -6,6 +6,7 @@ import org.apache.kerberos.kerb.crypto.key.CamelliaKeyMaker;
 import org.apache.kerberos.kerb.crypto.key.Des3KeyMaker;
 import org.apache.kerberos.kerb.crypto.key.DkKeyMaker;
 import org.apache.kerberos.kerb.spec.common.EncryptionType;
+import org.haox.util.HexUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -190,16 +191,16 @@ public class KeyDeriveTest {
     }
 
     private boolean testWith(TestCase testCase) throws Exception {
-        byte[] answer = TestUtil.hex2bytes(testCase.answer);
-        byte[] inkey = TestUtil.hex2bytes(testCase.inkey);
-        byte[] constant = TestUtil.hex2bytes(testCase.constant);
+        byte[] answer = HexUtil.hex2bytes(testCase.answer);
+        byte[] inkey = HexUtil.hex2bytes(testCase.inkey);
+        byte[] constant = HexUtil.hex2bytes(testCase.constant);
         byte[] outkey;
 
         DkKeyMaker km = getKeyMaker(testCase.encType);
         outkey = km.dk(inkey, constant);
         if (! Arrays.equals(answer, outkey)) {
             System.err.println("failed with:");
-            System.err.println("outKey:" + TestUtil.bytesToHex(outkey));
+            System.err.println("outKey:" + HexUtil.bytesToHex(outkey));
             System.err.println("answer:" + testCase.answer);
             return false;
         }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/String2keyTest.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/String2keyTest.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/String2keyTest.java
index a18763e..c8b1239 100644
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/String2keyTest.java
+++ b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/String2keyTest.java
@@ -2,6 +2,7 @@ package org.apache.kerberos.kerb.crypto;
 
 import org.apache.kerberos.kerb.spec.common.EncryptionKey;
 import org.apache.kerberos.kerb.spec.common.EncryptionType;
+import org.haox.util.HexUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -417,12 +418,12 @@ public class String2keyTest {
     }
 
     private boolean testWith(TestCase tc) throws Exception {
-        byte[] answer = TestUtil.hex2bytes(tc.answer);
-        byte[] params = tc.param != null ? TestUtil.hex2bytes(tc.param) : null;
+        byte[] answer = HexUtil.hex2bytes(tc.answer);
+        byte[] params = tc.param != null ? HexUtil.hex2bytes(tc.param) : null;
         EncryptionKey outkey = EncryptionHandler.string2Key(tc.string, tc.salt, params, tc.encType);
         if (! Arrays.equals(answer, outkey.getKeyData())) {
             System.err.println("failed with:");
-            System.err.println("outKey:" + TestUtil.bytesToHex(outkey.getKeyData()));
+            System.err.println("outKey:" + HexUtil.bytesToHex(outkey.getKeyData()));
             System.err.println("answer:" + tc.answer);
             // Will un-comment below when passed all the tests.
             //return false;

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/c58ed0ea/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/TestUtil.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/TestUtil.java
b/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/TestUtil.java
deleted file mode 100644
index 45e7e89..0000000
--- a/haox-kerb/kerb-crypto/src/test/java/org/apache/kerberos/kerb/crypto/TestUtil.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.apache.kerberos.kerb.crypto;
-
-public class TestUtil {
-
-    final static String HEX_CHARS_STR = "0123456789ABCDEF";
-    final static char[] HEX_CHARS = HEX_CHARS_STR.toCharArray();
-
-    /**
-     * Convert bytes into format as:
-     * 02020080
-     */
-    public static String bytesToHex(byte[] bytes) {
-        int len = bytes.length * 2;
-        char[] hexChars = new char[len];
-        for ( int j = 0; j < bytes.length; j++ ) {
-            int v = bytes[j] & 0xFF;
-            hexChars[j * 2] = HEX_CHARS[v >>> 4];
-            hexChars[j * 2 + 1] = HEX_CHARS[v & 0x0F];
-        }
-
-        return new String(hexChars);
-    }
-
-    /**
-     * Convert hex string like follows into byte array
-     * 02020080
-     */
-    public static byte[] hex2bytes(String hexString) {
-        hexString = hexString.toUpperCase();
-        int len = hexString.length() / 2;
-        byte[] bytes = new byte[len];
-        char[] hexChars = hexString.toCharArray();
-        for (int i = 0, j = 0; i < len; ++i) {
-            bytes[i] = (byte) ((HEX_CHARS_STR.indexOf(hexChars[j++]) << 4) + HEX_CHARS_STR.indexOf(hexChars[j++]));
-        }
-
-        return bytes;
-    }
-}


Mime
View raw message