You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pl...@apache.org on 2015/12/31 04:12:40 UTC

[1/4] directory-kerby git commit: DIRKRB-519 Check all the tests to use the NameTest format.

Repository: directory-kerby
Updated Branches:
  refs/heads/trunk e0ce27d7d -> d06becfd7


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java
deleted file mode 100644
index 8ad721a..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCompressedData.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.CompressedContentInfo;
-import org.apache.kerby.cms.type.CompressedData;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestCompressedData extends CmsTestBase {
-
-    @Test
-    public void testDump1WithCompressedData() throws IOException {
-        byte[] data = readDataFile("/compressed-data.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            CompressedContentInfo contentInfo = new CompressedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            CompressedData compressedData = contentInfo.getCompressedData();
-            Asn1.dump(compressedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java
deleted file mode 100644
index e30007a..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestEnvelopedData.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.EnvelopedContentInfo;
-import org.apache.kerby.cms.type.EnvelopedData;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestEnvelopedData extends CmsTestBase {
-
-    @Test
-    public void testDecodingKeyTrns() throws IOException {
-        byte[] data = readDataFile("/enveloped-keytrns.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
-            Asn1.dump(envelopedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testDecodingKek() throws IOException {
-        byte[] data = readDataFile("/enveloped-kek.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
-            Asn1.dump(envelopedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testDecodingNestedNDEF() throws IOException {
-        byte[] data = readDataFile("/enveloped-nested-ndef.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-
-            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
-            Asn1.dump(envelopedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
deleted file mode 100644
index 56c44af..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
-import org.apache.kerby.x509.type.Extension;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.*;
-
-public class TestExtension {
-
-    @Test
-    public void testUnsetCritical() throws IOException {
-        Extension extension = new Extension();
-        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
-        extension.setExtnValue("value".getBytes());
-        byte[] encodedBytes = extension.encode();
-        Extension decodedExtension = new Extension();
-        decodedExtension.decode(encodedBytes);
-        assertThat(decodedExtension.getCritical()).isFalse();
-    }
-
-    @Test
-    public void testSetCritical() throws IOException {
-        Extension extension = new Extension();
-        extension.setCritical(true);
-        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
-        extension.setExtnValue("value".getBytes());
-        byte[] encodedBytes = extension.encode();
-        Extension decodedExtension = new Extension();
-        decodedExtension.decode(encodedBytes);
-        assertThat(decodedExtension.getCritical()).isTrue();
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
deleted file mode 100644
index 54b60b7..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.apache.kerby.x509.type.GeneralName;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.*;
-
-public class TestGeneralName {
-    private static final byte[] IPV4 = HexUtil.hex2bytes("87040a090800");
-
-    @Test
-    public void testIpAddress() throws IOException {
-        try {
-            Asn1.parseAndDump(IPV4);
-            GeneralName generalName = new GeneralName();
-            generalName.decode(IPV4);
-            assertThat(generalName.getIPAddress()).isNotNull();
-            byte[] addressBytes = generalName.getIPAddress();
-            // "10.9.8.0"
-            assertThat(addressBytes).isEqualTo(new byte[] {0x0a, 0x09, 0x08, 0x00});
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
deleted file mode 100644
index ab85e93..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.CertificateChoices;
-import org.apache.kerby.cms.type.CertificateSet;
-import org.apache.kerby.cms.type.ContentInfo;
-import org.apache.kerby.cms.type.EncapsulatedContentInfo;
-import org.apache.kerby.cms.type.SignedContentInfo;
-import org.apache.kerby.cms.type.SignedData;
-import org.apache.kerby.x509.type.Certificate;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestSignedData extends CmsTestBase {
-
-    @Test
-    public void testDecoding() throws IOException {
-        byte[] data = readDataFile("/signed-data.txt");
-        try {
-            Asn1.parseAndDump(data);
-            //Asn1.decodeAndDump(data);
-
-            SignedContentInfo contentInfo = new SignedContentInfo();
-            contentInfo.decode(data);
-            //Asn1.dump(contentInfo);
-
-            SignedData signedData = contentInfo.getSignedData();
-            Asn1.dump(signedData);
-
-            Asn1.dump(contentInfo);
-            byte[] encodedData = contentInfo.encode();
-            Asn1.parseAndDump(encodedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testEncoding() throws IOException {
-        SignedContentInfo contentInfo = new SignedContentInfo();
-        contentInfo.setContentType("1.2.840.113549.1.7.2");
-        SignedData signedData = new SignedData();
-        EncapsulatedContentInfo eContentInfo = new EncapsulatedContentInfo();
-        eContentInfo.setContentType("1.3.6.1.5.2.3.1");
-        eContentInfo.setContent("data".getBytes());
-        signedData.setEncapContentInfo(eContentInfo);
-
-        byte[] data = readDataFile("/certificate1.txt");
-        Certificate certificate = new Certificate();
-        certificate.decode(data);
-        CertificateChoices certificateChoices = new CertificateChoices();
-        certificateChoices.setCertificate(certificate);
-        CertificateSet certificateSet = new CertificateSet();
-        certificateSet.addElement(certificateChoices);
-        signedData.setCertificates(certificateSet);
-
-        contentInfo.setSignedData(signedData);
-        Asn1.dump(contentInfo);
-
-        byte[] encodedData = contentInfo.encode();
-        Asn1.parseAndDump(encodedData);
-
-        SignedContentInfo decodedContentInfo = new SignedContentInfo();
-        decodedContentInfo.decode(encodedData);
-        Asn1.dump(decodedContentInfo);
-
-        SignedData decodedSignedData =
-                decodedContentInfo.getSignedData();
-        Asn1.dump(decodedSignedData);
-    }
-
-    @Test
-    public void testContentInfo() throws IOException {
-        byte[] data = readDataFile("/anonymous.txt");
-        try {
-            Asn1.parseAndDump(data);
-
-            ContentInfo contentInfo = new ContentInfo();
-            contentInfo.decode(data);
-            Asn1.dump(contentInfo);
-            SignedData signedData =
-                    contentInfo.getContentAs(SignedData.class);
-            Asn1.dump(signedData);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java b/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java
new file mode 100644
index 0000000..b32e2c7
--- /dev/null
+++ b/kerby-util/src/test/java/org/apache/kerby/util/Base64Test.java
@@ -0,0 +1,90 @@
+package org.apache.kerby.util;
+
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.Random;
+
+import static org.junit.Assert.assertTrue;
+
+
+public class Base64Test {
+
+    @Test
+    public void testOrigBase64() throws Exception {
+        Random random = new Random();
+        for (int i = 0; i < 4567; i++) {
+            byte[] buf = new byte[i];
+            random.nextBytes(buf);
+            byte[] enc = Base64.encodeBase64(buf);
+            ByteArrayInputStream in = new ByteArrayInputStream(enc);
+            enc = Util.streamToBytes(in);
+            byte[] dec = Base64.decodeBase64(enc);
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testOrigBase64 Failed on : " + i);
+            }
+            assertTrue(result);
+        }
+        for (int i = 5; i < 50; i++) {
+            int testSize = i * 1000 + 123;
+            byte[] buf = new byte[testSize];
+            random.nextBytes(buf);
+            byte[] enc = Base64.encodeBase64(buf);
+            ByteArrayInputStream in = new ByteArrayInputStream(enc);
+            enc = Util.streamToBytes(in);            
+            byte[] dec = Base64.decodeBase64(enc);
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testOrigBase64 Failed on : " + testSize);
+            }
+            assertTrue(result);
+        }
+    }
+
+    @Test
+    public void testBase64() throws Exception {
+        Random random = new Random();
+        for (int i = 0; i < 4567; i++) {
+            byte[] buf = new byte[i];
+            random.nextBytes(buf);
+
+            ByteArrayInputStream in = new ByteArrayInputStream(buf);
+            Base64InputStream base64 = new Base64InputStream(in, true);
+            byte[] enc = Util.streamToBytes(base64);
+            in = new ByteArrayInputStream(enc);
+            base64 = new Base64InputStream(in);
+            byte[] dec = Util.streamToBytes(base64);
+
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testBase64 Failed on : " + i);
+            }
+            assertTrue(result);
+        }
+        for (int i = 5; i < 50; i++) {
+            int testSize = i * 1000 + 123;
+            byte[] buf = new byte[testSize];
+            random.nextBytes(buf);
+
+            ByteArrayInputStream in = new ByteArrayInputStream(buf);
+            Base64InputStream base64 = new Base64InputStream(in, true);
+            byte[] enc = Util.streamToBytes(base64);
+            in = new ByteArrayInputStream(enc);
+            base64 = new Base64InputStream(in);
+            byte[] dec = Util.streamToBytes(base64);
+
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("testBase64 Failed on : " + testSize);
+            }
+            assertTrue(result);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java b/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java
new file mode 100644
index 0000000..6607ccc
--- /dev/null
+++ b/kerby-util/src/test/java/org/apache/kerby/util/IPAddressParserTest.java
@@ -0,0 +1,80 @@
+package org.apache.kerby.util;
+
+import org.junit.Test;
+
+import static org.apache.kerby.util.IPAddressParser.parseIPv4Literal;
+import static org.apache.kerby.util.IPAddressParser.parseIPv6Literal;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNull;
+
+public class IPAddressParserTest {
+
+    @Test
+    public void theTest() {
+
+        // bad ones
+        assertNull("ip6 invalid", parseIPv6Literal(":::"));
+        assertNull("ip6 too many zero-expanders", parseIPv6Literal("1::1::"));
+        assertNull("ip6 .256 invalid", parseIPv6Literal("1::1:255.254.253.256"));
+        assertNull("ip6 too small", parseIPv6Literal("1:2:3:4"));
+        assertNull("ip6 no zero-expander after ip4", parseIPv6Literal("1:255.254.253.252::"));
+        assertNull("ip6 no zero-expander if 7 colons (end)", parseIPv6Literal("1:2:3:4:5:6:7:8::"));
+        assertNull("ip6 no zero-expander if 7 colons (begin)", parseIPv6Literal("::1:2:3:4:5:6:7:8"));
+        assertNull("ip6 88888 too many digits", parseIPv6Literal("1:2:3:4:5:6:7:88888"));
+        assertNull("ip6 missing colons", parseIPv6Literal("abcd"));
+        assertNull("ip6 umm, no", parseIPv6Literal("cookie monster"));
+        assertNull("ip6 empty string is invalid", parseIPv6Literal(""));
+        assertNull("ip6 null is invalid", parseIPv6Literal(null));
+
+        assertNull("ip4 not enough dots", parseIPv4Literal("abcd"));
+        assertNull("ip4 umm, no", parseIPv4Literal("cookie monster"));
+        assertNull("ip4 empty string is invalid", parseIPv4Literal(""));
+        assertNull("ip4 null is invalid", parseIPv4Literal(null));
+        assertNull("ip4 not enough dots 0", parseIPv4Literal("1"));
+        assertNull("ip4 not enough dots 1", parseIPv4Literal("1.2"));
+        assertNull("ip4 not enough dots 2", parseIPv4Literal("1.2.3"));
+        assertNull("ip4 needs digit after final dot", parseIPv4Literal("1.2.3."));
+        assertNull("ip4 [0-9] digits only", parseIPv4Literal("1.2.3.a"));
+        assertNull("ip4 too many dots", parseIPv4Literal("1.2.3.4.5"));
+        assertNull("ip4 0-255 range", parseIPv4Literal("1.2.3.444"));
+        assertNull("ip4 no negatives", parseIPv4Literal("1.2.-3.4"));
+        assertNull("ip4 no brackets", parseIPv4Literal("[1.2.3.4]"));
+
+        // good ones
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("::"));
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1::"));
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("::1"));
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("1::1"));
+        assertArrayEquals(new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("100::1"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, -3, -4},
+                parseIPv6Literal("1::1:255.254.253.252"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, -4},
+                parseIPv6Literal("::255.254.253.252"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, -1, -2, -3, -4},
+                parseIPv6Literal("1:2:3:4:5:6:255.254.253.252"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("::1:2:3:4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("1::2:3:4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 4}, parseIPv6Literal("1:2::3:4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}, parseIPv6Literal("1:2:3::4"));
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1:2:3:4::"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
+                parseIPv6Literal("1:2:3:4:5:6:7:8"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("[::]"));
+
+        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
+                parseIPv6Literal("[1:2:3:4:5:6:7:8]"));
+
+        assertArrayEquals(new byte[]{17, 17, 34, 34, 51, 51, 68, 68, 85, 85, 102, 102, 119, 119, -120, -120},
+                parseIPv6Literal("1111:2222:3333:4444:5555:6666:7777:8888"));
+
+        assertArrayEquals(new byte[]{0, 0, 0, 0}, parseIPv4Literal("0.0.0.0"));
+        assertArrayEquals(new byte[]{1, 2, 3, 4}, parseIPv4Literal("1.2.3.4"));
+        assertArrayEquals(new byte[]{-1, -1, -1, -1}, parseIPv4Literal("255.255.255.255"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java b/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java
deleted file mode 100644
index 0eef01d..0000000
--- a/kerby-util/src/test/java/org/apache/kerby/util/TestBase64.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.apache.kerby.util;
-
-import org.junit.Test;
-
-import java.io.ByteArrayInputStream;
-import java.util.Arrays;
-import java.util.Random;
-
-import static org.junit.Assert.assertTrue;
-
-
-public class TestBase64 {
-
-    @Test
-    public void testOrigBase64() throws Exception {
-        Random random = new Random();
-        for (int i = 0; i < 4567; i++) {
-            byte[] buf = new byte[i];
-            random.nextBytes(buf);
-            byte[] enc = Base64.encodeBase64(buf);
-            ByteArrayInputStream in = new ByteArrayInputStream(enc);
-            enc = Util.streamToBytes(in);
-            byte[] dec = Base64.decodeBase64(enc);
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testOrigBase64 Failed on : " + i);
-            }
-            assertTrue(result);
-        }
-        for (int i = 5; i < 50; i++) {
-            int testSize = i * 1000 + 123;
-            byte[] buf = new byte[testSize];
-            random.nextBytes(buf);
-            byte[] enc = Base64.encodeBase64(buf);
-            ByteArrayInputStream in = new ByteArrayInputStream(enc);
-            enc = Util.streamToBytes(in);            
-            byte[] dec = Base64.decodeBase64(enc);
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testOrigBase64 Failed on : " + testSize);
-            }
-            assertTrue(result);
-        }
-    }
-
-    @Test
-    public void testBase64() throws Exception {
-        Random random = new Random();
-        for (int i = 0; i < 4567; i++) {
-            byte[] buf = new byte[i];
-            random.nextBytes(buf);
-
-            ByteArrayInputStream in = new ByteArrayInputStream(buf);
-            Base64InputStream base64 = new Base64InputStream(in, true);
-            byte[] enc = Util.streamToBytes(base64);
-            in = new ByteArrayInputStream(enc);
-            base64 = new Base64InputStream(in);
-            byte[] dec = Util.streamToBytes(base64);
-
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testBase64 Failed on : " + i);
-            }
-            assertTrue(result);
-        }
-        for (int i = 5; i < 50; i++) {
-            int testSize = i * 1000 + 123;
-            byte[] buf = new byte[testSize];
-            random.nextBytes(buf);
-
-            ByteArrayInputStream in = new ByteArrayInputStream(buf);
-            Base64InputStream base64 = new Base64InputStream(in, true);
-            byte[] enc = Util.streamToBytes(base64);
-            in = new ByteArrayInputStream(enc);
-            base64 = new Base64InputStream(in);
-            byte[] dec = Util.streamToBytes(base64);
-
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("testBase64 Failed on : " + testSize);
-            }
-            assertTrue(result);
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java
----------------------------------------------------------------------
diff --git a/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java b/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java
deleted file mode 100644
index b132f7d..0000000
--- a/kerby-util/src/test/java/org/apache/kerby/util/TestIPAddressParser.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.apache.kerby.util;
-
-import org.junit.Test;
-
-import static org.apache.kerby.util.IPAddressParser.parseIPv4Literal;
-import static org.apache.kerby.util.IPAddressParser.parseIPv6Literal;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertNull;
-
-public class TestIPAddressParser {
-
-    @Test
-    public void theTest() {
-
-        // bad ones
-        assertNull("ip6 invalid", parseIPv6Literal(":::"));
-        assertNull("ip6 too many zero-expanders", parseIPv6Literal("1::1::"));
-        assertNull("ip6 .256 invalid", parseIPv6Literal("1::1:255.254.253.256"));
-        assertNull("ip6 too small", parseIPv6Literal("1:2:3:4"));
-        assertNull("ip6 no zero-expander after ip4", parseIPv6Literal("1:255.254.253.252::"));
-        assertNull("ip6 no zero-expander if 7 colons (end)", parseIPv6Literal("1:2:3:4:5:6:7:8::"));
-        assertNull("ip6 no zero-expander if 7 colons (begin)", parseIPv6Literal("::1:2:3:4:5:6:7:8"));
-        assertNull("ip6 88888 too many digits", parseIPv6Literal("1:2:3:4:5:6:7:88888"));
-        assertNull("ip6 missing colons", parseIPv6Literal("abcd"));
-        assertNull("ip6 umm, no", parseIPv6Literal("cookie monster"));
-        assertNull("ip6 empty string is invalid", parseIPv6Literal(""));
-        assertNull("ip6 null is invalid", parseIPv6Literal(null));
-
-        assertNull("ip4 not enough dots", parseIPv4Literal("abcd"));
-        assertNull("ip4 umm, no", parseIPv4Literal("cookie monster"));
-        assertNull("ip4 empty string is invalid", parseIPv4Literal(""));
-        assertNull("ip4 null is invalid", parseIPv4Literal(null));
-        assertNull("ip4 not enough dots 0", parseIPv4Literal("1"));
-        assertNull("ip4 not enough dots 1", parseIPv4Literal("1.2"));
-        assertNull("ip4 not enough dots 2", parseIPv4Literal("1.2.3"));
-        assertNull("ip4 needs digit after final dot", parseIPv4Literal("1.2.3."));
-        assertNull("ip4 [0-9] digits only", parseIPv4Literal("1.2.3.a"));
-        assertNull("ip4 too many dots", parseIPv4Literal("1.2.3.4.5"));
-        assertNull("ip4 0-255 range", parseIPv4Literal("1.2.3.444"));
-        assertNull("ip4 no negatives", parseIPv4Literal("1.2.-3.4"));
-        assertNull("ip4 no brackets", parseIPv4Literal("[1.2.3.4]"));
-
-        // good ones
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("::"));
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1::"));
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("::1"));
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("1::1"));
-        assertArrayEquals(new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, parseIPv6Literal("100::1"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, -3, -4},
-                parseIPv6Literal("1::1:255.254.253.252"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, -4},
-                parseIPv6Literal("::255.254.253.252"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, -1, -2, -3, -4},
-                parseIPv6Literal("1:2:3:4:5:6:255.254.253.252"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("::1:2:3:4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 4}, parseIPv6Literal("1::2:3:4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 4}, parseIPv6Literal("1:2::3:4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}, parseIPv6Literal("1:2:3::4"));
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("1:2:3:4::"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
-                parseIPv6Literal("1:2:3:4:5:6:7:8"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, parseIPv6Literal("[::]"));
-
-        assertArrayEquals(new byte[]{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8},
-                parseIPv6Literal("[1:2:3:4:5:6:7:8]"));
-
-        assertArrayEquals(new byte[]{17, 17, 34, 34, 51, 51, 68, 68, 85, 85, 102, 102, 119, 119, -120, -120},
-                parseIPv6Literal("1111:2222:3333:4444:5555:6666:7777:8888"));
-
-        assertArrayEquals(new byte[]{0, 0, 0, 0}, parseIPv4Literal("0.0.0.0"));
-        assertArrayEquals(new byte[]{1, 2, 3, 4}, parseIPv4Literal("1.2.3.4"));
-        assertArrayEquals(new byte[]{-1, -1, -1, -1}, parseIPv4Literal("255.255.255.255"));
-    }
-}


[2/4] directory-kerby git commit: DIRKRB-519 Check all the tests to use the NameTest format.

Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsReqCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsReqCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsReqCodec.java
deleted file mode 100644
index a5d6efc..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsReqCodec.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.ContentInfo;
-import org.apache.kerby.cms.type.SignedData;
-import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
-import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.type.base.NameType;
-import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
-import org.apache.kerby.kerberos.kerb.type.kdc.AsReq;
-import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
-import org.apache.kerby.kerberos.kerb.type.pa.PaData;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsReq;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.*;
-
-public class TestPkinitRsaAsReqCodec {
-    @Test
-    public void test() throws IOException, ParseException {
-        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_rsa_asreq.token");
-        Asn1.parseAndDump(bytes);
-        ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
-
-        AsReq asReq = new AsReq();
-        asReq.decode(asReqToken);
-        //Asn1.decodeAndDump(asReq);
-
-        assertThat(asReq.getPvno()).isEqualTo(5);
-        assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
-
-        PaData paData = asReq.getPaData();
-
-        PaDataEntry paFxCookieEntry = paData.findEntry(PaDataType.FX_COOKIE);
-        assertThat(paFxCookieEntry.getPaDataType()).isEqualTo(PaDataType.FX_COOKIE);
-        assertThat(paFxCookieEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 38, 41));
-
-        PaDataEntry pkAsReqEntry = paData.findEntry(PaDataType.PK_AS_REQ);
-        assertThat(pkAsReqEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REQ);
-        assertThat(pkAsReqEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 58, 2138));
-
-        PaPkAsReq paPkAsReq = new PaPkAsReq();
-        paPkAsReq.decode(pkAsReqEntry.getPaDataValue());
-        ContentInfo contentInfo = new ContentInfo();
-        //Asn1.parseAndDump(paPkAsReq.getSignedAuthPack());
-        contentInfo.decode(paPkAsReq.getSignedAuthPack());
-        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
-        //Asn1.dump(contentInfo);
-
-        SignedData signedData = contentInfo.getContentAs(SignedData.class);
-        assertThat(signedData.getCertificates().getElements().size()).isEqualTo(1);
-        assertThat(signedData.getEncapContentInfo().getContentType()).isEqualTo("1.3.6.1.5.2.3.1");
-
-        PaDataEntry encpaEntry = paData.findEntry(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
-        assertThat(encpaEntry.getPaDataType()).isEqualTo(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
-        assertThat(encpaEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 2148, 2148));
-
-        KdcReqBody body = asReq.getReqBody();
-        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
-        assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 2161, 2165));
-        PrincipalName cName = body.getCname();
-        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
-        assertThat(body.getRealm()).isEqualTo("EXAMPLE.COM");
-        PrincipalName sName = body.getSname();
-        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
-        assertThat(sName.getNameStrings()).hasSize(2)
-                .contains("krbtgt", "EXAMPLE.COM");
-
-        assertThat(body.getNonce()).isEqualTo(658979657);
-
-        List<EncryptionType> types = body.getEtypes();
-        assertThat(types).hasSize(6);
-        assertThat(types.get(0).getValue()).isEqualTo(0x0012);
-        assertThat(types.get(1).getValue()).isEqualTo(0x0011);
-        assertThat(types.get(2).getValue()).isEqualTo(0x0010);
-        assertThat(types.get(3).getValue()).isEqualTo(0x0017);
-        assertThat(types.get(4).getValue()).isEqualTo(0x0019);
-        assertThat(types.get(5).getValue()).isEqualTo(0x001A);
-
-        // Test encode PaPkAsReq
-        byte[] encodedPaPkAsReq = paPkAsReq.encode();
-        PaPkAsReq decodedPaPkAsReq = new PaPkAsReq();
-        decodedPaPkAsReq.decode(encodedPaPkAsReq);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsRepCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsRepCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsRepCodec.java
deleted file mode 100644
index 48aa83f..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsRepCodec.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.type.base.NameType;
-import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
-import org.apache.kerby.kerberos.kerb.type.kdc.TgsRep;
-import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Test TgsRep message using a real 'correct' network packet captured from MS-AD to detective programming errors
- * and compatibility issues particularly regarding Kerberos crypto.
- */
-public class TestTgsRepCodec {
-
-    @Test
-    public void test() throws IOException {
-        byte[] bytes = CodecTestUtil.readBinaryFile("/tgsrep.token");
-        TgsRep tgsRep = new TgsRep();
-        tgsRep.decode(bytes);
-
-        assertThat(tgsRep.getPvno()).isEqualTo(5);
-        assertThat(tgsRep.getMsgType()).isEqualTo(KrbMessageType.TGS_REP);
-        assertThat(tgsRep.getCrealm()).isEqualTo("DENYDC.COM");
-
-        PrincipalName cName = tgsRep.getCname();
-        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
-        assertThat(cName.getNameStrings()).hasSize(1).contains("des");
-
-        Ticket ticket = tgsRep.getTicket();
-        assertThat(ticket.getTktvno()).isEqualTo(5);
-        assertThat(ticket.getRealm()).isEqualTo("DENYDC.COM");
-        PrincipalName sName = ticket.getSname();
-        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_HST);
-        assertThat(sName.getNameStrings()).hasSize(2)
-                .contains("host", "xp1.denydc.com");
-        //FIXME
-        //EncTicketPart encTicketPart = ticket.getEncPart();
-        //assertThat(encTicketPart.getKey().getKeyType().getValue()).isEqualTo(23);
-        //assertThat(encTicketPart.getKey().getKvno()).isEqualTo(2);
-
-        //EncKdcRepPart encKdcRepPart = tgsRep.getEncPart();
-        //assertThat(encKdcRepPart.getKey().getKeyType().getValue()).isEqualTo(3);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsReqCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsReqCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsReqCodec.java
deleted file mode 100644
index 10dca95..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestTgsReqCodec.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
-import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.type.base.NameType;
-import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
-import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
-import org.apache.kerby.kerberos.kerb.type.kdc.TgsReq;
-import org.apache.kerby.kerberos.kerb.type.pa.PaData;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.SimpleTimeZone;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Test TgsReq message using a real 'correct' network packet captured from MS-AD to detective programming errors
- * and compatibility issues particularly regarding Kerberos crypto.
- */
-public class TestTgsReqCodec {
-
-    @Test
-    public void test() throws IOException, ParseException {
-        byte[] bytes = CodecTestUtil.readBinaryFile("/tgsreq.token");
-        TgsReq tgsReq = new TgsReq();
-        tgsReq.decode(bytes);
-
-        assertThat(tgsReq.getPvno()).isEqualTo(5);
-        assertThat(tgsReq.getMsgType()).isEqualTo(KrbMessageType.TGS_REQ);
-
-        PaData paData = tgsReq.getPaData();
-        assertThat(paData.getElements()).hasSize(1);
-        PaDataEntry entry = paData.getElements().iterator().next();
-        assertThat(entry.getPaDataType()).isEqualTo(PaDataType.TGS_REQ);
-
-        //request body
-        KdcReqBody body = tgsReq.getReqBody();
-        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
-        byte[] kdcOptionsValue = {64, (byte) 128, 0, 0};
-        assertThat(body.getKdcOptions().getValue()).isEqualTo(kdcOptionsValue);
-
-        assertThat(body.getRealm()).isEqualTo("DENYDC.COM");
-
-        PrincipalName sName = body.getSname();
-        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_HST);
-        assertThat(sName.getNameStrings()).hasSize(2)
-                .contains("host", "xp1.denydc.com");
-
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
-        Date date = sdf.parse("20370913024805");
-        assertThat(body.getTill().getTime()).isEqualTo(date.getTime());
-
-        assertThat(body.getNonce()).isEqualTo(197296424);
-
-        List<EncryptionType> eTypes = body.getEtypes();
-        assertThat(eTypes).hasSize(7);
-        assertThat(eTypes.get(0).getValue()).isEqualTo(0x0017);
-        //assertThat(eTypes.get(1).getValue()).isEqualTo(-133);//FIXME
-        //assertThat(eTypes.get(2).getValue()).isEqualTo(-128);//FIXME
-        assertThat(eTypes.get(3).getValue()).isEqualTo(0x0003);
-        assertThat(eTypes.get(4).getValue()).isEqualTo(0x0001);
-        assertThat(eTypes.get(5).getValue()).isEqualTo(0x0018);
-        //assertThat(eTypes.get(6).getValue()).isEqualTo(-135);//FIXME
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsRepCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsRepCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsRepCodecTest.java
new file mode 100644
index 0000000..4e618d5
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsRepCodecTest.java
@@ -0,0 +1,68 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.type.base.NameType;
+import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
+import org.apache.kerby.kerberos.kerb.type.kdc.TgsRep;
+import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test TgsRep message using a real 'correct' network packet captured from MS-AD to detective programming errors
+ * and compatibility issues particularly regarding Kerberos crypto.
+ */
+public class TgsRepCodecTest {
+
+    @Test
+    public void test() throws IOException {
+        byte[] bytes = CodecTestUtil.readBinaryFile("/tgsrep.token");
+        TgsRep tgsRep = new TgsRep();
+        tgsRep.decode(bytes);
+
+        assertThat(tgsRep.getPvno()).isEqualTo(5);
+        assertThat(tgsRep.getMsgType()).isEqualTo(KrbMessageType.TGS_REP);
+        assertThat(tgsRep.getCrealm()).isEqualTo("DENYDC.COM");
+
+        PrincipalName cName = tgsRep.getCname();
+        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
+        assertThat(cName.getNameStrings()).hasSize(1).contains("des");
+
+        Ticket ticket = tgsRep.getTicket();
+        assertThat(ticket.getTktvno()).isEqualTo(5);
+        assertThat(ticket.getRealm()).isEqualTo("DENYDC.COM");
+        PrincipalName sName = ticket.getSname();
+        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_HST);
+        assertThat(sName.getNameStrings()).hasSize(2)
+                .contains("host", "xp1.denydc.com");
+        //FIXME
+        //EncTicketPart encTicketPart = ticket.getEncPart();
+        //assertThat(encTicketPart.getKey().getKeyType().getValue()).isEqualTo(23);
+        //assertThat(encTicketPart.getKey().getKvno()).isEqualTo(2);
+
+        //EncKdcRepPart encKdcRepPart = tgsRep.getEncPart();
+        //assertThat(encKdcRepPart.getKey().getKeyType().getValue()).isEqualTo(3);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsReqCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsReqCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsReqCodecTest.java
new file mode 100644
index 0000000..902e6dd
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TgsReqCodecTest.java
@@ -0,0 +1,92 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
+import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.type.base.NameType;
+import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
+import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
+import org.apache.kerby.kerberos.kerb.type.kdc.TgsReq;
+import org.apache.kerby.kerberos.kerb.type.pa.PaData;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.SimpleTimeZone;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test TgsReq message using a real 'correct' network packet captured from MS-AD to detective programming errors
+ * and compatibility issues particularly regarding Kerberos crypto.
+ */
+public class TgsReqCodecTest {
+
+    @Test
+    public void test() throws IOException, ParseException {
+        byte[] bytes = CodecTestUtil.readBinaryFile("/tgsreq.token");
+        TgsReq tgsReq = new TgsReq();
+        tgsReq.decode(bytes);
+
+        assertThat(tgsReq.getPvno()).isEqualTo(5);
+        assertThat(tgsReq.getMsgType()).isEqualTo(KrbMessageType.TGS_REQ);
+
+        PaData paData = tgsReq.getPaData();
+        assertThat(paData.getElements()).hasSize(1);
+        PaDataEntry entry = paData.getElements().iterator().next();
+        assertThat(entry.getPaDataType()).isEqualTo(PaDataType.TGS_REQ);
+
+        //request body
+        KdcReqBody body = tgsReq.getReqBody();
+        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
+        byte[] kdcOptionsValue = {64, (byte) 128, 0, 0};
+        assertThat(body.getKdcOptions().getValue()).isEqualTo(kdcOptionsValue);
+
+        assertThat(body.getRealm()).isEqualTo("DENYDC.COM");
+
+        PrincipalName sName = body.getSname();
+        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_HST);
+        assertThat(sName.getNameStrings()).hasSize(2)
+                .contains("host", "xp1.denydc.com");
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
+        Date date = sdf.parse("20370913024805");
+        assertThat(body.getTill().getTime()).isEqualTo(date.getTime());
+
+        assertThat(body.getNonce()).isEqualTo(197296424);
+
+        List<EncryptionType> eTypes = body.getEtypes();
+        assertThat(eTypes).hasSize(7);
+        assertThat(eTypes.get(0).getValue()).isEqualTo(0x0017);
+        //assertThat(eTypes.get(1).getValue()).isEqualTo(-133);//FIXME
+        //assertThat(eTypes.get(2).getValue()).isEqualTo(-128);//FIXME
+        assertThat(eTypes.get(3).getValue()).isEqualTo(0x0003);
+        assertThat(eTypes.get(4).getValue()).isEqualTo(0x0001);
+        assertThat(eTypes.get(5).getValue()).isEqualTo(0x0018);
+        //assertThat(eTypes.get(6).getValue()).isEqualTo(-135);//FIXME
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcConfigLoadTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcConfigLoadTest.java b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcConfigLoadTest.java
new file mode 100644
index 0000000..bf761d5
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcConfigLoadTest.java
@@ -0,0 +1,73 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.server;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class KdcConfigLoadTest {
+
+    @Test
+    public void test() throws URISyntaxException, IOException {
+        URL confFileUrl = KdcConfigLoadTest.class.getResource("/kdc.conf");
+        File confFile = new File(confFileUrl.toURI());
+
+        KdcConfig kdcConfig = new KdcConfig();
+        kdcConfig.addIniConfig(confFile);
+
+        assertThat(kdcConfig.getKdcHost()).isEqualTo("localhost");
+        assertThat(kdcConfig.getKdcUdpPort()).isEqualTo(88);
+        assertThat(kdcConfig.getKdcTcpPort()).isEqualTo(8014);
+        assertThat(kdcConfig.getKdcRealm()).isEqualTo("TEST.COM");
+        assertThat(kdcConfig.isRestrictAnonymousToTgt()).isTrue();
+        assertThat(kdcConfig.getKdcMaxDgramReplySize()).isEqualTo(4096);
+    }
+
+    @Test
+    public void testManualConfiguration() {
+        KdcConfig kdcConfig = new KdcConfig();
+
+        kdcConfig.setString(KdcConfigKey.KDC_HOST, "localhost");
+        kdcConfig.setInt(KdcConfigKey.KDC_TCP_PORT, 12345);
+        kdcConfig.setString(KdcConfigKey.KDC_REALM, "TEST2.COM");
+
+        assertThat(kdcConfig.getKdcHost()).isEqualTo("localhost");
+        assertThat(kdcConfig.getKdcTcpPort()).isEqualTo(12345);
+        assertThat(kdcConfig.getKdcRealm()).isEqualTo("TEST2.COM");
+    }
+
+    @Test
+    public void testConfigurationDefaults() {
+        KdcConfig kdcConfig = new KdcConfig();
+
+        assertThat(kdcConfig.getKdcHost()).isEqualTo(
+                KdcConfigKey.KDC_HOST.getDefaultValue());
+        assertThat(kdcConfig.getKdcTcpPort()).isEqualTo(-1);
+        assertThat(kdcConfig.getKdcRealm()).isEqualTo(
+                KdcConfigKey.KDC_REALM.getDefaultValue()
+        );
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
deleted file mode 100644
index 402e256..0000000
--- a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.server;
-
-import org.junit.Test;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestKdcConfigLoad {
-
-    @Test
-    public void test() throws URISyntaxException, IOException {
-        URL confFileUrl = TestKdcConfigLoad.class.getResource("/kdc.conf");
-        File confFile = new File(confFileUrl.toURI());
-
-        KdcConfig kdcConfig = new KdcConfig();
-        kdcConfig.addIniConfig(confFile);
-
-        assertThat(kdcConfig.getKdcHost()).isEqualTo("localhost");
-        assertThat(kdcConfig.getKdcUdpPort()).isEqualTo(88);
-        assertThat(kdcConfig.getKdcTcpPort()).isEqualTo(8014);
-        assertThat(kdcConfig.getKdcRealm()).isEqualTo("TEST.COM");
-        assertThat(kdcConfig.isRestrictAnonymousToTgt()).isTrue();
-        assertThat(kdcConfig.getKdcMaxDgramReplySize()).isEqualTo(4096);
-    }
-
-    @Test
-    public void testManualConfiguration() {
-        KdcConfig kdcConfig = new KdcConfig();
-
-        kdcConfig.setString(KdcConfigKey.KDC_HOST, "localhost");
-        kdcConfig.setInt(KdcConfigKey.KDC_TCP_PORT, 12345);
-        kdcConfig.setString(KdcConfigKey.KDC_REALM, "TEST2.COM");
-
-        assertThat(kdcConfig.getKdcHost()).isEqualTo("localhost");
-        assertThat(kdcConfig.getKdcTcpPort()).isEqualTo(12345);
-        assertThat(kdcConfig.getKdcRealm()).isEqualTo("TEST2.COM");
-    }
-
-    @Test
-    public void testConfigurationDefaults() {
-        KdcConfig kdcConfig = new KdcConfig();
-
-        assertThat(kdcConfig.getKdcHost()).isEqualTo(
-                KdcConfigKey.KDC_HOST.getDefaultValue());
-        assertThat(kdcConfig.getKdcTcpPort()).isEqualTo(-1);
-        assertThat(kdcConfig.getKdcRealm()).isEqualTo(
-                KdcConfigKey.KDC_REALM.getDefaultValue()
-        );
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/CertificatesTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/CertificatesTest.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/CertificatesTest.java
new file mode 100644
index 0000000..4d775b1
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/commons/ssl/CertificatesTest.java
@@ -0,0 +1,84 @@
+package org.apache.commons.ssl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import javax.security.auth.x500.X500Principal;
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.cert.X509Certificate;
+
+import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by julius on 06/09/14.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class CertificatesTest {
+
+    @Mock
+    private X509Certificate x509;
+
+    @Test
+    public void testGetCNsMocked() {
+        X500Principal normal = new X500Principal("CN=abc,OU=ou,O=o,C=canada,EMAILADDRESS=bob@bob.com");
+        X500Principal bad1 = new X500Principal("CN=\"abc,CN=foo.com,\",OU=ou,O=o,C=canada,EMAILADDRESS=bob@bob.com");
+        X500Principal bad2 = new X500Principal("ou=\",CN=evil.ca,\",  CN=good.net");
+
+        when(x509.getSubjectX500Principal()).thenReturn(normal);
+        String[] cns = Certificates.getCNs(x509);
+        Assert.assertEquals(1, cns.length);
+        Assert.assertEquals("abc", cns[0]);
+
+        when(x509.getSubjectX500Principal()).thenReturn(bad2);
+        cns = Certificates.getCNs(x509);
+        Assert.assertEquals(1, cns.length);
+        Assert.assertEquals("good.net", cns[0]);
+
+        when(x509.getSubjectX500Principal()).thenReturn(bad1);
+        cns = Certificates.getCNs(x509);
+        Assert.assertEquals(1, cns.length);
+        Assert.assertEquals("abc,CN=foo.com,", cns[0]);
+    }
+
+    @Test
+    public void testGetCNsReal() throws IOException, GeneralSecurityException {
+        String samplesDir = TEST_HOME + "x509";
+
+        TrustMaterial tm = new TrustMaterial(samplesDir + "/x509_three_cns_foo_bar_hanako.pem");
+        X509Certificate c = (X509Certificate) tm.getCertificates().first();
+        String[] cns = Certificates.getCNs(c);
+        Assert.assertEquals(3, cns.length);
+        Assert.assertEquals("foo.com", cns[0]);
+        Assert.assertEquals("bar.com", cns[1]);
+        //Assert.assertEquals("花子.co.jp", cns[2]);
+
+        tm = new TrustMaterial(samplesDir + "/x509_foo_bar_hanako.pem");
+        c = (X509Certificate) tm.getCertificates().first();
+        cns = Certificates.getCNs(c);
+        Assert.assertEquals(1, cns.length);
+        Assert.assertEquals("foo.com", cns[0]);
+
+        tm = new TrustMaterial(samplesDir + "/x509_wild_co_jp.pem");
+        c = (X509Certificate) tm.getCertificates().first();
+        cns = Certificates.getCNs(c);
+        Assert.assertEquals(1, cns.length);
+        Assert.assertEquals("*.co.jp", cns[0]);
+
+        tm = new TrustMaterial(samplesDir + "/x509_wild_foo_bar_hanako.pem");
+        c = (X509Certificate) tm.getCertificates().first();
+        cns = Certificates.getCNs(c);
+        Assert.assertEquals(1, cns.length);
+        Assert.assertEquals("*.foo.com", cns[0]);
+
+        tm = new TrustMaterial(samplesDir + "/x509_wild_foo.pem");
+        c = (X509Certificate) tm.getCertificates().first();
+        cns = Certificates.getCNs(c);
+        Assert.assertEquals(1, cns.length);
+        Assert.assertEquals("*.foo.com", cns[0]);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/KeyMaterialTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/KeyMaterialTest.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/KeyMaterialTest.java
new file mode 100644
index 0000000..ab58813
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/commons/ssl/KeyMaterialTest.java
@@ -0,0 +1,77 @@
+package org.apache.commons.ssl;
+
+import org.apache.kerby.util.EncryptoUtil;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.junit.Test;
+
+import java.io.File;
+import java.security.Security;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+public class KeyMaterialTest {
+    public static final char[] PASSWORD1 = "changeit".toCharArray();
+    public static final char[] PASSWORD2 = "itchange".toCharArray();
+
+    static {
+        Security.addProvider(new BouncyCastleProvider());
+    }
+
+    @Test
+    public void testKeystores() throws Exception {
+        String samplesDir = TEST_HOME + "keystores";
+        File dir = new File(samplesDir);
+        String[] files = dir.list();
+        Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
+        for (String f : files) {
+            String file = f.toUpperCase(Locale.ENGLISH);
+            if (file.endsWith(".KS") || file.contains("PKCS12")) {
+                examineKeyStore(samplesDir, f, null);
+            } else if (file.endsWith(".PEM")) {
+                examineKeyStore(samplesDir, f, "rsa.key");
+            }
+        }
+    }
+
+    private static void examineKeyStore(String dir, String fileName, String file2) throws Exception {
+        String filename = fileName.toUpperCase(Locale.ENGLISH);
+        boolean hasMultiPassword = filename.contains(".2PASS.");
+
+        System.out.print("Testing KeyMaterial: " + dir + "/" + fileName);        
+        char[] pass1 = PASSWORD1;
+        char[] pass2 = PASSWORD1;
+        if (hasMultiPassword) {
+            pass2 = PASSWORD2;
+        }
+
+        file2 = file2 != null ? dir + "/" + file2 : null;
+
+        Date today = new Date();
+        KeyMaterial km;
+
+
+        try {
+            assumeTrue(EncryptoUtil.isAES256Enabled());
+            km = new KeyMaterial(dir + "/" + fileName, file2, pass1, pass2);
+        } catch (ProbablyBadPasswordException pbpe) {
+            System.out.println("  WARN:  " + pbpe);
+            return;
+        }
+        assertEquals("keymaterial-contains-1-alias", 1, km.getAliases().size());
+        for (X509Certificate[] cert : (List<X509Certificate[]>) km.getAssociatedCertificateChains()) {
+            for (X509Certificate c : cert) {
+                assertTrue("certchain-valid-dates", c.getNotAfter().after(today));
+            }
+        }
+
+        System.out.println("\t SUCCESS! ");
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/OpenSSLTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/OpenSSLTest.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/OpenSSLTest.java
new file mode 100644
index 0000000..7855c11
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/commons/ssl/OpenSSLTest.java
@@ -0,0 +1,166 @@
+package org.apache.commons.ssl;
+
+import org.apache.kerby.util.EncryptoUtil;
+import org.apache.kerby.util.Util;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+import java.util.Random;
+
+import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+public class OpenSSLTest {
+
+    public void encTest(String cipher) throws Exception {
+        Random random = new Random();
+        char[] pwd = {'!', 'E', 'i', 'k', 'o', '?'};
+
+        for (int i = 0; i < 4567; i++) {
+            byte[] buf = new byte[i];
+            random.nextBytes(buf);
+            byte[] enc = OpenSSL.encrypt(cipher, pwd, buf);
+            byte[] dec = OpenSSL.decrypt(cipher, pwd, enc);
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("Failed on : " + i);
+            }
+            assertTrue(result);
+        }
+
+        for (int i = 5; i < 50; i++) {
+            int testSize = i * 1000 + 123;
+            byte[] buf = new byte[testSize];
+            random.nextBytes(buf);
+            byte[] enc = OpenSSL.encrypt(cipher, pwd, buf);
+            byte[] dec = OpenSSL.decrypt(cipher, pwd, enc);
+            boolean result = Arrays.equals(buf, dec);
+            if (!result) {
+                System.out.println();
+                System.out.println("Failed on : " + testSize);
+            }
+            assertTrue(result);
+        }
+
+    }
+
+    @Test
+    public void testDES3Bytes() throws Exception {
+        encTest("des3");
+    }
+
+    @Test
+    public void testAES128Bytes() throws Exception {
+        encTest("aes128");
+    }
+
+    @Test
+    public void testRC2Bytes() throws Exception {
+        encTest("rc2");
+    }
+
+    @Test
+    public void testDESBytes() throws Exception {
+        encTest("des");
+    }
+
+    @Test
+    public void testDecryptPBE() throws Exception {
+        File d = new File(TEST_HOME + "pbe");
+        File[] files = d.listFiles();
+        if (files == null) {
+            fail("No testDecryptPBE() files to test!");
+        }
+        int testCount = 0;
+        Arrays.sort(files);
+        for (File f : files) {
+            testCount += process(f, 0);
+        }
+        System.out.println(testCount + " pbe test files successfully decrypted.");
+    }
+
+    private static int process(File f, int depth) throws Exception {
+        int sum = 0;
+        String name = f.getName();
+        if ("CVS".equalsIgnoreCase(name)) {
+            return 0;
+        }
+        if (".svn".equalsIgnoreCase(name)) {
+            return 0;
+        }
+        if (name.toUpperCase().startsWith("README")) {
+            return 0;
+        }
+
+        if (f.isDirectory()) {
+            if (depth <= 7) {
+                File[] files = f.listFiles();
+                if (files == null) {
+                    return 0;
+                }
+                Arrays.sort(files);
+                for (File ff : files) {
+                    sum += process(ff, depth + 1);
+                }
+            } else {
+                System.out.println("IGNORING [" + f + "].  Directory too deep (" + depth + ").");
+            }
+        } else {
+            if (f.isFile() && f.canRead()) {
+                String fileName = f.getName();
+                int x = fileName.indexOf('.');
+                if (x < 0) {
+                    return 0;
+                }
+                if (fileName.endsWith(".failed")) {
+                    System.out.println("Skipping file marked with failed: " + fileName);
+                    return 0;
+                }
+
+                String cipher = fileName.substring(0, x);
+                String cipherPadded = Util.pad(cipher, 20, false);
+                String filePadded = Util.pad(fileName, 25, false);
+                FileInputStream in = null;
+                try {
+                    in = new FileInputStream(f);
+                    byte[] encrypted = Util.streamToBytes(in);
+                    char[] pwd = "changeit".toCharArray();
+                    try {
+                        assumeTrue(EncryptoUtil.isAES256Enabled());
+                        byte[] result = OpenSSL.decrypt(cipher, pwd, encrypted);
+                        String s = new String(result, "ISO-8859-1");
+                        if (!"Hello World!".equals(s)) {
+                            fail(cipherPadded + "." + filePadded
+                                + " decrypts to 'Hello World!', but actually is" + s);
+                        }
+                        return 1;
+                    } catch (NoSuchAlgorithmException nsae) {
+                        System.out.println("Warn: " + cipherPadded + filePadded
+                            + " NoSuchAlgorithmException");
+                        return 0;
+                    } catch (ArithmeticException ae) {
+                        if (cipherPadded.contains("cfb1")) {
+                            System.out.println("Warn: " + cipherPadded + filePadded
+                                + " BouncyCastle can't handle cfb1 " + ae);
+                            return 0;
+                        } else {
+                            throw ae;
+                        }
+                    }
+                } finally {
+                    if (in != null) {
+                        in.close();
+                    }
+                }
+            }
+        }
+        return sum;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/PKCS8KeyTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/PKCS8KeyTest.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/PKCS8KeyTest.java
new file mode 100644
index 0000000..ef6e38d
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/commons/ssl/PKCS8KeyTest.java
@@ -0,0 +1,61 @@
+package org.apache.commons.ssl;
+
+import org.apache.kerby.util.EncryptoUtil;
+import org.apache.kerby.util.Util;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Arrays;
+import java.util.Locale;
+
+import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+public class PKCS8KeyTest {
+
+    @Test
+    public void testDSA() throws Exception {
+        checkFiles("dsa");
+    }
+
+    @Test
+    public void testRSA() throws Exception {
+        checkFiles("rsa");
+    }
+
+    private static void checkFiles(String type) throws Exception {
+        String password = "changeit";
+        File dir = new File(TEST_HOME + type);
+        File[] files = dir.listFiles();
+        if (files == null) {
+            fail("No files to test!");
+            return;
+        }
+        byte[] original = null;
+        for (File f : files) {
+            String filename = f.getName();
+            String fileName = filename.toUpperCase(Locale.ENGLISH);
+            if (!fileName.endsWith(".PEM") && !fileName.endsWith(".DER")) {
+                // not a sample file
+                continue;
+            }
+
+            System.out.println("Checking PKCS file:" + filename);
+            FileInputStream in = new FileInputStream(f);
+            byte[] bytes = Util.streamToBytes(in);
+            assumeTrue(EncryptoUtil.isAES256Enabled());
+            PKCS8Key key = new PKCS8Key(bytes, password.toCharArray());
+            byte[] decrypted = key.getDecryptedBytes();
+            if (original == null) {
+                original = decrypted;
+            } else {
+                boolean identical = Arrays.equals(original, decrypted);
+                assertTrue(f.getCanonicalPath() + " - all " + type + " resources decrypt to same key", identical);
+            }
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/TestCertificates.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestCertificates.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/TestCertificates.java
deleted file mode 100644
index 2113510..0000000
--- a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestCertificates.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.apache.commons.ssl;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import javax.security.auth.x500.X500Principal;
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-import java.security.cert.X509Certificate;
-
-import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
-import static org.mockito.Mockito.when;
-
-/**
- * Created by julius on 06/09/14.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class TestCertificates {
-
-    @Mock
-    private X509Certificate x509;
-
-    @Test
-    public void testGetCNsMocked() {
-        X500Principal normal = new X500Principal("CN=abc,OU=ou,O=o,C=canada,EMAILADDRESS=bob@bob.com");
-        X500Principal bad1 = new X500Principal("CN=\"abc,CN=foo.com,\",OU=ou,O=o,C=canada,EMAILADDRESS=bob@bob.com");
-        X500Principal bad2 = new X500Principal("ou=\",CN=evil.ca,\",  CN=good.net");
-
-        when(x509.getSubjectX500Principal()).thenReturn(normal);
-        String[] cns = Certificates.getCNs(x509);
-        Assert.assertEquals(1, cns.length);
-        Assert.assertEquals("abc", cns[0]);
-
-        when(x509.getSubjectX500Principal()).thenReturn(bad2);
-        cns = Certificates.getCNs(x509);
-        Assert.assertEquals(1, cns.length);
-        Assert.assertEquals("good.net", cns[0]);
-
-        when(x509.getSubjectX500Principal()).thenReturn(bad1);
-        cns = Certificates.getCNs(x509);
-        Assert.assertEquals(1, cns.length);
-        Assert.assertEquals("abc,CN=foo.com,", cns[0]);
-    }
-
-    @Test
-    public void testGetCNsReal() throws IOException, GeneralSecurityException {
-        String samplesDir = TEST_HOME + "x509";
-
-        TrustMaterial tm = new TrustMaterial(samplesDir + "/x509_three_cns_foo_bar_hanako.pem");
-        X509Certificate c = (X509Certificate) tm.getCertificates().first();
-        String[] cns = Certificates.getCNs(c);
-        Assert.assertEquals(3, cns.length);
-        Assert.assertEquals("foo.com", cns[0]);
-        Assert.assertEquals("bar.com", cns[1]);
-        //Assert.assertEquals("花子.co.jp", cns[2]);
-
-        tm = new TrustMaterial(samplesDir + "/x509_foo_bar_hanako.pem");
-        c = (X509Certificate) tm.getCertificates().first();
-        cns = Certificates.getCNs(c);
-        Assert.assertEquals(1, cns.length);
-        Assert.assertEquals("foo.com", cns[0]);
-
-        tm = new TrustMaterial(samplesDir + "/x509_wild_co_jp.pem");
-        c = (X509Certificate) tm.getCertificates().first();
-        cns = Certificates.getCNs(c);
-        Assert.assertEquals(1, cns.length);
-        Assert.assertEquals("*.co.jp", cns[0]);
-
-        tm = new TrustMaterial(samplesDir + "/x509_wild_foo_bar_hanako.pem");
-        c = (X509Certificate) tm.getCertificates().first();
-        cns = Certificates.getCNs(c);
-        Assert.assertEquals(1, cns.length);
-        Assert.assertEquals("*.foo.com", cns[0]);
-
-        tm = new TrustMaterial(samplesDir + "/x509_wild_foo.pem");
-        c = (X509Certificate) tm.getCertificates().first();
-        cns = Certificates.getCNs(c);
-        Assert.assertEquals(1, cns.length);
-        Assert.assertEquals("*.foo.com", cns[0]);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/TestKeyMaterial.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestKeyMaterial.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/TestKeyMaterial.java
deleted file mode 100644
index 99a98e1..0000000
--- a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestKeyMaterial.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.apache.commons.ssl;
-
-import org.apache.kerby.util.EncryptoUtil;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.Test;
-
-import java.io.File;
-import java.security.Security;
-import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-
-import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-public class TestKeyMaterial {
-    public static final char[] PASSWORD1 = "changeit".toCharArray();
-    public static final char[] PASSWORD2 = "itchange".toCharArray();
-
-    static {
-        Security.addProvider(new BouncyCastleProvider());
-    }
-
-    @Test
-    public void testKeystores() throws Exception {
-        String samplesDir = TEST_HOME + "keystores";
-        File dir = new File(samplesDir);
-        String[] files = dir.list();
-        Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
-        for (String f : files) {
-            String file = f.toUpperCase(Locale.ENGLISH);
-            if (file.endsWith(".KS") || file.contains("PKCS12")) {
-                examineKeyStore(samplesDir, f, null);
-            } else if (file.endsWith(".PEM")) {
-                examineKeyStore(samplesDir, f, "rsa.key");
-            }
-        }
-    }
-
-    private static void examineKeyStore(String dir, String fileName, String file2) throws Exception {
-        String filename = fileName.toUpperCase(Locale.ENGLISH);
-        boolean hasMultiPassword = filename.contains(".2PASS.");
-
-        System.out.print("Testing KeyMaterial: " + dir + "/" + fileName);        
-        char[] pass1 = PASSWORD1;
-        char[] pass2 = PASSWORD1;
-        if (hasMultiPassword) {
-            pass2 = PASSWORD2;
-        }
-
-        file2 = file2 != null ? dir + "/" + file2 : null;
-
-        Date today = new Date();
-        KeyMaterial km;
-
-
-        try {
-            assumeTrue(EncryptoUtil.isAES256Enabled());
-            km = new KeyMaterial(dir + "/" + fileName, file2, pass1, pass2);
-        } catch (ProbablyBadPasswordException pbpe) {
-            System.out.println("  WARN:  " + pbpe);
-            return;
-        }
-        assertEquals("keymaterial-contains-1-alias", 1, km.getAliases().size());
-        for (X509Certificate[] cert : (List<X509Certificate[]>) km.getAssociatedCertificateChains()) {
-            for (X509Certificate c : cert) {
-                assertTrue("certchain-valid-dates", c.getNotAfter().after(today));
-            }
-        }
-
-        System.out.println("\t SUCCESS! ");
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/TestOpenSSL.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestOpenSSL.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/TestOpenSSL.java
deleted file mode 100644
index df6837f..0000000
--- a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestOpenSSL.java
+++ /dev/null
@@ -1,166 +0,0 @@
-package org.apache.commons.ssl;
-
-import org.apache.kerby.util.EncryptoUtil;
-import org.apache.kerby.util.Util;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-import java.util.Random;
-
-import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
-
-public class TestOpenSSL {
-
-    public void encTest(String cipher) throws Exception {
-        Random random = new Random();
-        char[] pwd = {'!', 'E', 'i', 'k', 'o', '?'};
-
-        for (int i = 0; i < 4567; i++) {
-            byte[] buf = new byte[i];
-            random.nextBytes(buf);
-            byte[] enc = OpenSSL.encrypt(cipher, pwd, buf);
-            byte[] dec = OpenSSL.decrypt(cipher, pwd, enc);
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("Failed on : " + i);
-            }
-            assertTrue(result);
-        }
-
-        for (int i = 5; i < 50; i++) {
-            int testSize = i * 1000 + 123;
-            byte[] buf = new byte[testSize];
-            random.nextBytes(buf);
-            byte[] enc = OpenSSL.encrypt(cipher, pwd, buf);
-            byte[] dec = OpenSSL.decrypt(cipher, pwd, enc);
-            boolean result = Arrays.equals(buf, dec);
-            if (!result) {
-                System.out.println();
-                System.out.println("Failed on : " + testSize);
-            }
-            assertTrue(result);
-        }
-
-    }
-
-    @Test
-    public void testDES3Bytes() throws Exception {
-        encTest("des3");
-    }
-
-    @Test
-    public void testAES128Bytes() throws Exception {
-        encTest("aes128");
-    }
-
-    @Test
-    public void testRC2Bytes() throws Exception {
-        encTest("rc2");
-    }
-
-    @Test
-    public void testDESBytes() throws Exception {
-        encTest("des");
-    }
-
-    @Test
-    public void testDecryptPBE() throws Exception {
-        File d = new File(TEST_HOME + "pbe");
-        File[] files = d.listFiles();
-        if (files == null) {
-            fail("No testDecryptPBE() files to test!");
-        }
-        int testCount = 0;
-        Arrays.sort(files);
-        for (File f : files) {
-            testCount += process(f, 0);
-        }
-        System.out.println(testCount + " pbe test files successfully decrypted.");
-    }
-
-    private static int process(File f, int depth) throws Exception {
-        int sum = 0;
-        String name = f.getName();
-        if ("CVS".equalsIgnoreCase(name)) {
-            return 0;
-        }
-        if (".svn".equalsIgnoreCase(name)) {
-            return 0;
-        }
-        if (name.toUpperCase().startsWith("README")) {
-            return 0;
-        }
-
-        if (f.isDirectory()) {
-            if (depth <= 7) {
-                File[] files = f.listFiles();
-                if (files == null) {
-                    return 0;
-                }
-                Arrays.sort(files);
-                for (File ff : files) {
-                    sum += process(ff, depth + 1);
-                }
-            } else {
-                System.out.println("IGNORING [" + f + "].  Directory too deep (" + depth + ").");
-            }
-        } else {
-            if (f.isFile() && f.canRead()) {
-                String fileName = f.getName();
-                int x = fileName.indexOf('.');
-                if (x < 0) {
-                    return 0;
-                }
-                if (fileName.endsWith(".failed")) {
-                    System.out.println("Skipping file marked with failed: " + fileName);
-                    return 0;
-                }
-
-                String cipher = fileName.substring(0, x);
-                String cipherPadded = Util.pad(cipher, 20, false);
-                String filePadded = Util.pad(fileName, 25, false);
-                FileInputStream in = null;
-                try {
-                    in = new FileInputStream(f);
-                    byte[] encrypted = Util.streamToBytes(in);
-                    char[] pwd = "changeit".toCharArray();
-                    try {
-                        assumeTrue(EncryptoUtil.isAES256Enabled());
-                        byte[] result = OpenSSL.decrypt(cipher, pwd, encrypted);
-                        String s = new String(result, "ISO-8859-1");
-                        if (!"Hello World!".equals(s)) {
-                            fail(cipherPadded + "." + filePadded
-                                + " decrypts to 'Hello World!', but actually is" + s);
-                        }
-                        return 1;
-                    } catch (NoSuchAlgorithmException nsae) {
-                        System.out.println("Warn: " + cipherPadded + filePadded
-                            + " NoSuchAlgorithmException");
-                        return 0;
-                    } catch (ArithmeticException ae) {
-                        if (cipherPadded.contains("cfb1")) {
-                            System.out.println("Warn: " + cipherPadded + filePadded
-                                + " BouncyCastle can't handle cfb1 " + ae);
-                            return 0;
-                        } else {
-                            throw ae;
-                        }
-                    }
-                } finally {
-                    if (in != null) {
-                        in.close();
-                    }
-                }
-            }
-        }
-        return sum;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/TestPKCS8Key.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestPKCS8Key.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/TestPKCS8Key.java
deleted file mode 100644
index 59127da..0000000
--- a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestPKCS8Key.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.apache.commons.ssl;
-
-import org.apache.kerby.util.EncryptoUtil;
-import org.apache.kerby.util.Util;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Arrays;
-import java.util.Locale;
-
-import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
-
-public class TestPKCS8Key {
-
-    @Test
-    public void testDSA() throws Exception {
-        checkFiles("dsa");
-    }
-
-    @Test
-    public void testRSA() throws Exception {
-        checkFiles("rsa");
-    }
-
-    private static void checkFiles(String type) throws Exception {
-        String password = "changeit";
-        File dir = new File(TEST_HOME + type);
-        File[] files = dir.listFiles();
-        if (files == null) {
-            fail("No files to test!");
-            return;
-        }
-        byte[] original = null;
-        for (File f : files) {
-            String filename = f.getName();
-            String fileName = filename.toUpperCase(Locale.ENGLISH);
-            if (!fileName.endsWith(".PEM") && !fileName.endsWith(".DER")) {
-                // not a sample file
-                continue;
-            }
-
-            System.out.println("Checking PKCS file:" + filename);
-            FileInputStream in = new FileInputStream(f);
-            byte[] bytes = Util.streamToBytes(in);
-            assumeTrue(EncryptoUtil.isAES256Enabled());
-            PKCS8Key key = new PKCS8Key(bytes, password.toCharArray());
-            byte[] decrypted = key.getDecryptedBytes();
-            if (original == null) {
-                original = decrypted;
-            } else {
-                boolean identical = Arrays.equals(original, decrypted);
-                assertTrue(f.getCanonicalPath() + " - all " + type + " resources decrypt to same key", identical);
-            }
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/TestTrustMaterial.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestTrustMaterial.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/TestTrustMaterial.java
deleted file mode 100644
index b681b0f..0000000
--- a/kerby-pkix/src/test/java/org/apache/commons/ssl/TestTrustMaterial.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.apache.commons.ssl;
-
-import org.apache.kerby.util.Util;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-import java.security.KeyStoreException;
-
-import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
-
-public class TestTrustMaterial {
-
-    File pemFile = new File(TEST_HOME + "x509/certificate.pem");
-    File derFile = new File(TEST_HOME + "x509/certificate.der");
-
-    @Test
-    public void theTest() throws GeneralSecurityException, IOException {
-        // TrustMaterial in 0.3.13 couldn't load cacerts if it contained any private keys.
-        TrustMaterial tm = new TrustMaterial(TEST_HOME + "cacerts-with-78-entries-and-one-private-key.jks");
-        Assert.assertEquals(78, tm.getCertificates().size());
-    }
-
-    @Test
-    public void testLoadByFile() throws GeneralSecurityException, IOException {
-        TrustMaterial tm1 = new TrustMaterial(pemFile);
-        TrustMaterial tm2 = new TrustMaterial(derFile);
-        Assert.assertTrue(equalKeystores(tm1, tm2));
-    }
-
-    @Test
-    public void testLoadByBytes() throws GeneralSecurityException, IOException {
-        TrustMaterial tm1 = new TrustMaterial(Util.fileToBytes(pemFile));
-        TrustMaterial tm2 = new TrustMaterial(Util.fileToBytes(derFile));
-        Assert.assertTrue(equalKeystores(tm1, tm2));
-
-    }
-
-    @Test
-    public void testLoadByURL() throws GeneralSecurityException, IOException {
-        TrustMaterial tm1 = new TrustMaterial(pemFile.toURI().toURL());
-        TrustMaterial tm2 = new TrustMaterial(derFile.toURI().toURL());
-        Assert.assertTrue(equalKeystores(tm1, tm2));
-    }
-
-    @Test
-    public void testLoadByStream() throws GeneralSecurityException, IOException {
-        TrustMaterial tm1 = new TrustMaterial(new FileInputStream(pemFile));
-        TrustMaterial tm2 = new TrustMaterial(new FileInputStream(derFile));
-        Assert.assertTrue(equalKeystores(tm1, tm2));
-
-    }
-
-    @Test
-    public void testLoadByPath() throws GeneralSecurityException, IOException {
-        TrustMaterial tm1 = new TrustMaterial(pemFile.getPath());
-        TrustMaterial tm2 = new TrustMaterial(derFile.getPath());
-        Assert.assertTrue(equalKeystores(tm1, tm2));
-    }
-
-    private static boolean equalKeystores(TrustMaterial tm1, TrustMaterial tm2) throws KeyStoreException {
-        return Util.equals(tm1.getKeyStore(), tm2.getKeyStore());
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/commons/ssl/TrustMaterialTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/commons/ssl/TrustMaterialTest.java b/kerby-pkix/src/test/java/org/apache/commons/ssl/TrustMaterialTest.java
new file mode 100644
index 0000000..2496440
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/commons/ssl/TrustMaterialTest.java
@@ -0,0 +1,67 @@
+package org.apache.commons.ssl;
+
+import org.apache.kerby.util.Util;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.KeyStoreException;
+
+import static org.apache.commons.ssl.JUnitConfig.TEST_HOME;
+
+public class TrustMaterialTest {
+
+    File pemFile = new File(TEST_HOME + "x509/certificate.pem");
+    File derFile = new File(TEST_HOME + "x509/certificate.der");
+
+    @Test
+    public void theTest() throws GeneralSecurityException, IOException {
+        // TrustMaterial in 0.3.13 couldn't load cacerts if it contained any private keys.
+        TrustMaterial tm = new TrustMaterial(TEST_HOME + "cacerts-with-78-entries-and-one-private-key.jks");
+        Assert.assertEquals(78, tm.getCertificates().size());
+    }
+
+    @Test
+    public void testLoadByFile() throws GeneralSecurityException, IOException {
+        TrustMaterial tm1 = new TrustMaterial(pemFile);
+        TrustMaterial tm2 = new TrustMaterial(derFile);
+        Assert.assertTrue(equalKeystores(tm1, tm2));
+    }
+
+    @Test
+    public void testLoadByBytes() throws GeneralSecurityException, IOException {
+        TrustMaterial tm1 = new TrustMaterial(Util.fileToBytes(pemFile));
+        TrustMaterial tm2 = new TrustMaterial(Util.fileToBytes(derFile));
+        Assert.assertTrue(equalKeystores(tm1, tm2));
+
+    }
+
+    @Test
+    public void testLoadByURL() throws GeneralSecurityException, IOException {
+        TrustMaterial tm1 = new TrustMaterial(pemFile.toURI().toURL());
+        TrustMaterial tm2 = new TrustMaterial(derFile.toURI().toURL());
+        Assert.assertTrue(equalKeystores(tm1, tm2));
+    }
+
+    @Test
+    public void testLoadByStream() throws GeneralSecurityException, IOException {
+        TrustMaterial tm1 = new TrustMaterial(new FileInputStream(pemFile));
+        TrustMaterial tm2 = new TrustMaterial(new FileInputStream(derFile));
+        Assert.assertTrue(equalKeystores(tm1, tm2));
+
+    }
+
+    @Test
+    public void testLoadByPath() throws GeneralSecurityException, IOException {
+        TrustMaterial tm1 = new TrustMaterial(pemFile.getPath());
+        TrustMaterial tm2 = new TrustMaterial(derFile.getPath());
+        Assert.assertTrue(equalKeystores(tm1, tm2));
+    }
+
+    private static boolean equalKeystores(TrustMaterial tm1, TrustMaterial tm2) throws KeyStoreException {
+        return Util.equals(tm1.getKeyStore(), tm2.getKeyStore());
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/CertificateTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/CertificateTest.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/CertificateTest.java
new file mode 100644
index 0000000..6b6901c
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/CertificateTest.java
@@ -0,0 +1,76 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.cms;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.x500.type.Name;
+import org.apache.kerby.x509.type.Certificate;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class CertificateTest extends CmsTestBase {
+    @Test
+    public void testDecodingCertificate() throws IOException {
+        byte[] data = readDataFile("/certificate1.txt");
+        try {
+            Asn1.parseAndDump(data);
+            Certificate certificate = new Certificate();
+            certificate.decode(data);
+            Asn1.dump(certificate);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testEncodingCertificate() throws IOException {
+        byte[] data = readDataFile("/certificate1.txt");
+        Asn1.parseAndDump(data);
+        try {
+            Certificate certificate = new Certificate();
+            certificate.decode(data);
+            Asn1.dump(certificate);
+            byte[] encodedData = certificate.encode();
+            Asn1.parseAndDump(encodedData);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testDecodingName() throws IOException {
+        byte[] data = readDataFile("/name.txt");
+        try {
+            Asn1.parseAndDump(data);
+            Name name = new Name();
+            name.decode(data);
+            Asn1.dump(name.getName());
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/CompressedDataTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/CompressedDataTest.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/CompressedDataTest.java
new file mode 100644
index 0000000..9a9aeea
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/CompressedDataTest.java
@@ -0,0 +1,49 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.cms;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.CompressedContentInfo;
+import org.apache.kerby.cms.type.CompressedData;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class CompressedDataTest extends CmsTestBase {
+
+    @Test
+    public void testDump1WithCompressedData() throws IOException {
+        byte[] data = readDataFile("/compressed-data.txt");
+        try {
+            Asn1.parseAndDump(data);
+
+            CompressedContentInfo contentInfo = new CompressedContentInfo();
+            contentInfo.decode(data);
+            Asn1.dump(contentInfo);
+
+            CompressedData compressedData = contentInfo.getCompressedData();
+            Asn1.dump(compressedData);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/EnvelopedDataTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/EnvelopedDataTest.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/EnvelopedDataTest.java
new file mode 100644
index 0000000..532ddaa
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/EnvelopedDataTest.java
@@ -0,0 +1,86 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.cms;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.EnvelopedContentInfo;
+import org.apache.kerby.cms.type.EnvelopedData;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class EnvelopedDataTest extends CmsTestBase {
+
+    @Test
+    public void testDecodingKeyTrns() throws IOException {
+        byte[] data = readDataFile("/enveloped-keytrns.txt");
+        try {
+            Asn1.parseAndDump(data);
+
+            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
+            contentInfo.decode(data);
+            Asn1.dump(contentInfo);
+
+            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
+            Asn1.dump(envelopedData);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testDecodingKek() throws IOException {
+        byte[] data = readDataFile("/enveloped-kek.txt");
+        try {
+            Asn1.parseAndDump(data);
+
+            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
+            contentInfo.decode(data);
+            Asn1.dump(contentInfo);
+
+            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
+            Asn1.dump(envelopedData);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testDecodingNestedNDEF() throws IOException {
+        byte[] data = readDataFile("/enveloped-nested-ndef.txt");
+        try {
+            Asn1.parseAndDump(data);
+
+            EnvelopedContentInfo contentInfo = new EnvelopedContentInfo();
+            contentInfo.decode(data);
+            Asn1.dump(contentInfo);
+
+            EnvelopedData envelopedData = contentInfo.getEnvelopedData();
+            Asn1.dump(envelopedData);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/ExtensionTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/ExtensionTest.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/ExtensionTest.java
new file mode 100644
index 0000000..7799d1d
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/ExtensionTest.java
@@ -0,0 +1,54 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.cms;
+
+import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
+import org.apache.kerby.x509.type.Extension;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.*;
+
+public class ExtensionTest {
+
+    @Test
+    public void testUnsetCritical() throws IOException {
+        Extension extension = new Extension();
+        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
+        extension.setExtnValue("value".getBytes());
+        byte[] encodedBytes = extension.encode();
+        Extension decodedExtension = new Extension();
+        decodedExtension.decode(encodedBytes);
+        assertThat(decodedExtension.getCritical()).isFalse();
+    }
+
+    @Test
+    public void testSetCritical() throws IOException {
+        Extension extension = new Extension();
+        extension.setCritical(true);
+        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
+        extension.setExtnValue("value".getBytes());
+        byte[] encodedBytes = extension.encode();
+        Extension decodedExtension = new Extension();
+        decodedExtension.decode(encodedBytes);
+        assertThat(decodedExtension.getCritical()).isTrue();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/GeneralNameTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/GeneralNameTest.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/GeneralNameTest.java
new file mode 100644
index 0000000..5f6ab7f
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/GeneralNameTest.java
@@ -0,0 +1,50 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.cms;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.apache.kerby.x509.type.GeneralName;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.*;
+
+public class GeneralNameTest {
+    private static final byte[] IPV4 = HexUtil.hex2bytes("87040a090800");
+
+    @Test
+    public void testIpAddress() throws IOException {
+        try {
+            Asn1.parseAndDump(IPV4);
+            GeneralName generalName = new GeneralName();
+            generalName.decode(IPV4);
+            assertThat(generalName.getIPAddress()).isNotNull();
+            byte[] addressBytes = generalName.getIPAddress();
+            // "10.9.8.0"
+            assertThat(addressBytes).isEqualTo(new byte[] {0x0a, 0x09, 0x08, 0x00});
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/SignedDataTest.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/SignedDataTest.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/SignedDataTest.java
new file mode 100644
index 0000000..734d4cc
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/SignedDataTest.java
@@ -0,0 +1,111 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.cms;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.CertificateChoices;
+import org.apache.kerby.cms.type.CertificateSet;
+import org.apache.kerby.cms.type.ContentInfo;
+import org.apache.kerby.cms.type.EncapsulatedContentInfo;
+import org.apache.kerby.cms.type.SignedContentInfo;
+import org.apache.kerby.cms.type.SignedData;
+import org.apache.kerby.x509.type.Certificate;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class SignedDataTest extends CmsTestBase {
+
+    @Test
+    public void testDecoding() throws IOException {
+        byte[] data = readDataFile("/signed-data.txt");
+        try {
+            Asn1.parseAndDump(data);
+            //Asn1.decodeAndDump(data);
+
+            SignedContentInfo contentInfo = new SignedContentInfo();
+            contentInfo.decode(data);
+            //Asn1.dump(contentInfo);
+
+            SignedData signedData = contentInfo.getSignedData();
+            Asn1.dump(signedData);
+
+            Asn1.dump(contentInfo);
+            byte[] encodedData = contentInfo.encode();
+            Asn1.parseAndDump(encodedData);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testEncoding() throws IOException {
+        SignedContentInfo contentInfo = new SignedContentInfo();
+        contentInfo.setContentType("1.2.840.113549.1.7.2");
+        SignedData signedData = new SignedData();
+        EncapsulatedContentInfo eContentInfo = new EncapsulatedContentInfo();
+        eContentInfo.setContentType("1.3.6.1.5.2.3.1");
+        eContentInfo.setContent("data".getBytes());
+        signedData.setEncapContentInfo(eContentInfo);
+
+        byte[] data = readDataFile("/certificate1.txt");
+        Certificate certificate = new Certificate();
+        certificate.decode(data);
+        CertificateChoices certificateChoices = new CertificateChoices();
+        certificateChoices.setCertificate(certificate);
+        CertificateSet certificateSet = new CertificateSet();
+        certificateSet.addElement(certificateChoices);
+        signedData.setCertificates(certificateSet);
+
+        contentInfo.setSignedData(signedData);
+        Asn1.dump(contentInfo);
+
+        byte[] encodedData = contentInfo.encode();
+        Asn1.parseAndDump(encodedData);
+
+        SignedContentInfo decodedContentInfo = new SignedContentInfo();
+        decodedContentInfo.decode(encodedData);
+        Asn1.dump(decodedContentInfo);
+
+        SignedData decodedSignedData =
+                decodedContentInfo.getSignedData();
+        Asn1.dump(decodedSignedData);
+    }
+
+    @Test
+    public void testContentInfo() throws IOException {
+        byte[] data = readDataFile("/anonymous.txt");
+        try {
+            Asn1.parseAndDump(data);
+
+            ContentInfo contentInfo = new ContentInfo();
+            contentInfo.decode(data);
+            Asn1.dump(contentInfo);
+            SignedData signedData =
+                    contentInfo.getContentAs(SignedData.class);
+            Asn1.dump(signedData);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java
deleted file mode 100644
index c62d69a..0000000
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.cms;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.x500.type.Name;
-import org.apache.kerby.x509.type.Certificate;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestCertificate extends CmsTestBase {
-    @Test
-    public void testDecodingCertificate() throws IOException {
-        byte[] data = readDataFile("/certificate1.txt");
-        try {
-            Asn1.parseAndDump(data);
-            Certificate certificate = new Certificate();
-            certificate.decode(data);
-            Asn1.dump(certificate);
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testEncodingCertificate() throws IOException {
-        byte[] data = readDataFile("/certificate1.txt");
-        Asn1.parseAndDump(data);
-        try {
-            Certificate certificate = new Certificate();
-            certificate.decode(data);
-            Asn1.dump(certificate);
-            byte[] encodedData = certificate.encode();
-            Asn1.parseAndDump(encodedData);
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testDecodingName() throws IOException {
-        byte[] data = readDataFile("/name.txt");
-        try {
-            Asn1.parseAndDump(data);
-            Name name = new Name();
-            name.decode(data);
-            Asn1.dump(name.getName());
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}


[3/4] directory-kerby git commit: DIRKRB-519 Check all the tests to use the NameTest format.

Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestTaggingEncoding.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestTaggingEncoding.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestTaggingEncoding.java
deleted file mode 100644
index 2828249..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestTaggingEncoding.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Tagging;
-import org.apache.kerby.asn1.type.Asn1VisibleString;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- Ref. X.690-0207 8.14 Encoding of a tagged value
- EXAMPLE
- With ASN.1 type definitions (in an explicit tagging environment) of:
- Type1 ::= VisibleString
- Type2 ::= [APPLICATION 3] IMPLICIT Type1
- Type3 ::= [2] Type2
- Type4 ::= [APPLICATION 7] IMPLICIT Type3
- Type5 ::= [2] IMPLICIT Type2
- a value of:
- "Jones"
- is encoded as follows:
- For Type1:
- VisibleString Length Contents
- 1A16 0516 4A6F6E657316
- For Type2:
- [Application 3] Length Contents
- 4316 0516 4A6F6E657316
- For Type3:
- [2] Length Contents
- A216 0716
- [APPLICATION 3] Length Contents
- 4316 0516 4A6F6E657316
- For Type4:
- [Application 7] Length Contents
- 6716 0716
- [APPLICATION 3] Length Contents
- 4316 0516 4A6F6E657316
- For Type5:
- [2] Length Contents
- 8216 0516 4A6F6E657316
- */
-
-public class TestTaggingEncoding {
-    static final String TEST_STRING = "Jones";
-    static final byte[] TYPE1_EXPECTED_BYTES = new byte[] {(byte) 0x1A, (byte) 0x05,
-            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
-    static final byte[] TYPE2_EXPECTED_BYTES = new byte[] {(byte) 0x43, (byte) 0x05,
-            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
-    static final byte[] TYPE3_EXPECTED_BYTES = new byte[] {(byte) 0xA2, (byte) 0x07,
-            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
-            (byte) 0x65, (byte) 0x73};
-    static final byte[] TYPE4_EXPECTED_BYTES = new byte[] {(byte) 0x67, (byte) 0x07,
-            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
-            (byte) 0x65, (byte) 0x73};
-    static final byte[] TYPE5_EXPECTED_BYTES = new byte[] {(byte) 0x82, (byte) 0x05,
-            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
-
-
-    public static class Type1 extends Asn1VisibleString {
-        public Type1(String value) {
-            super(value);
-        }
-        public Type1() {
-            this(null);
-        }
-    }
-
-    public static class Type2 extends Asn1Tagging<Type1> {
-        public Type2(Type1 value) {
-            super(3, value, true, true);
-        }
-        public Type2() {
-            this(null);
-        }
-    }
-
-    public static class Type3 extends Asn1Tagging<Type2> {
-        public Type3(Type2 value) {
-            super(2, value, false, false);
-        }
-        public Type3() {
-            this(null);
-        }
-    }
-
-    public static class Type4 extends Asn1Tagging<Type3> {
-        public Type4(Type3 value) {
-            super(7, value, true, true);
-        }
-        public Type4() {
-            this(null);
-        }
-    }
-
-    public static class Type5 extends Asn1Tagging<Type2> {
-        public Type5(Type2 value) {
-            super(2, value, false, true);
-        }
-        public Type5() {
-            this(null);
-        }
-    }
-
-    @Test
-    public void testAsn1TaggingEncoding() throws IOException {
-        Type1 aType1 = new Type1(TEST_STRING);
-        Type2 aType2 = new Type2(aType1);
-        Type3 aType3 = new Type3(aType2);
-        Type4 aType4 = new Type4(aType3);
-        Type5 aType5 = new Type5(aType2);
-
-        assertThat(aType1.encode()).isEqualTo(TYPE1_EXPECTED_BYTES);
-        assertThat(aType2.encode()).isEqualTo(TYPE2_EXPECTED_BYTES);
-        assertThat(aType3.encode()).isEqualTo(TYPE3_EXPECTED_BYTES);
-        assertThat(aType4.encode()).isEqualTo(TYPE4_EXPECTED_BYTES);
-        assertThat(aType5.encode()).isEqualTo(TYPE5_EXPECTED_BYTES);
-    }
-
-    @Test
-    public void testAsn1TaggingDecoding() throws IOException {
-        Type1 aType1 = new Type1();
-        aType1.decode(TYPE1_EXPECTED_BYTES);
-        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
-
-        Type2 aType2 = new Type2();
-        aType2.decode(TYPE2_EXPECTED_BYTES);
-        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
-
-        Type3 aType3 = new Type3();
-        aType3.decode(TYPE3_EXPECTED_BYTES);
-        assertThat(aType3.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
-
-        Type4 aType4 = new Type4();
-        aType4.decode(TYPE4_EXPECTED_BYTES);
-        assertThat(aType4.getValue().getValue().getValue().getValue()).isEqualTo(TEST_STRING);
-
-        Type5 aType5 = new Type5();
-        aType5.decode(TYPE5_EXPECTED_BYTES);
-        assertThat(aType5.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
-    }
-
-    @Test
-    public void testTaggingEncodingOption() throws IOException {
-        Type1 aType1 = new Type1(TEST_STRING);
-        Type2 aType2 = new Type2(aType1);
-        Type3 aType3 = new Type3(aType2);
-
-        assertThat(aType1.encode()).isEqualTo(TYPE1_EXPECTED_BYTES);
-        assertThat(TYPE2_EXPECTED_BYTES)
-                .isEqualTo(aType1.taggedEncode(TaggingOption.newImplicitAppSpecific(3))); // for Type2
-        assertThat(TYPE3_EXPECTED_BYTES)
-                .isEqualTo(aType2.taggedEncode(TaggingOption.newExplicitContextSpecific(2))); // for Type3
-        assertThat(TYPE4_EXPECTED_BYTES)
-                .isEqualTo(aType3.taggedEncode(TaggingOption.newImplicitAppSpecific(7))); // for Type4
-        assertThat(TYPE5_EXPECTED_BYTES)
-                .isEqualTo(aType2.taggedEncode(TaggingOption.newImplicitContextSpecific(2))); // for Type5
-    }
-
-    @Test
-    public void testTaggingDecodingOption() throws IOException {
-        Type1 aType1 = new Type1();
-        aType1.decode(TYPE1_EXPECTED_BYTES);
-        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
-
-        // for Type2
-        aType1 = new Type1();
-        aType1.taggedDecode(TYPE2_EXPECTED_BYTES, TaggingOption.newImplicitAppSpecific(3));
-        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
-
-        // for Type3
-        Type2 aType2 = new Type2();
-        aType2.taggedDecode(TYPE3_EXPECTED_BYTES, TaggingOption.newExplicitContextSpecific(2));
-        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
-
-        // for Type4
-        Type3 aType3 = new Type3();
-        aType3.taggedDecode(TYPE4_EXPECTED_BYTES, TaggingOption.newImplicitAppSpecific(7));
-        assertThat(aType3.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
-
-        // for Type5
-        aType2 = new Type2();
-        aType2.taggedDecode(TYPE5_EXPECTED_BYTES, TaggingOption.newImplicitContextSpecific(2));
-        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbClientSettingTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbClientSettingTest.java b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbClientSettingTest.java
index da0064e..3c65f22 100644
--- a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbClientSettingTest.java
+++ b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbClientSettingTest.java
@@ -30,7 +30,7 @@ public class KrbClientSettingTest {
 
     @Test
     public void testKdcServerMannualSetting() throws Exception {
-        URL confFileUrl = TestKrbConfigLoadForSpecials.class.getResource(
+        URL confFileUrl = KrbConfigLoadForSpecialsTest.class.getResource(
             "/krb5-specials.conf");
         File confFile = new File(confFileUrl.toURI());
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadForSpecialsTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadForSpecialsTest.java b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadForSpecialsTest.java
new file mode 100644
index 0000000..87b6f21
--- /dev/null
+++ b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadForSpecialsTest.java
@@ -0,0 +1,51 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.client;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.net.URL;
+
+import static org.assertj.core.api.Assertions.*;
+
+/**
+ * Test for loading configurations form krb5.conf with default kdc realm.
+ * krb5.conf is the configuration file in MIT Kerberos.
+ */
+public class KrbConfigLoadForSpecialsTest {
+
+    @Test
+    public void test() throws Exception {
+        URL confFileUrl = KrbConfigLoadForSpecialsTest.class.getResource(
+                        "/krb5-specials.conf");
+        File confFile = new File(confFileUrl.toURI());
+
+        KrbConfig krbConfig = new KrbConfig();
+        krbConfig.addIniConfig(confFile);
+        assertThat(krbConfig.getKdcRealm()).isEqualTo("KRB.COM");
+        assertThat(krbConfig.getKdcPort()).isEqualTo(88);
+
+        assertThat(krbConfig.allowUdp()).isEqualTo(true);
+        assertThat(krbConfig.allowTcp()).isEqualTo(true);
+        assertThat(krbConfig.getKdcTcpPort()).isEqualTo(88);
+        assertThat(krbConfig.getKdcUdpPort()).isEqualTo(88);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java
new file mode 100644
index 0000000..967d17d
--- /dev/null
+++ b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java
@@ -0,0 +1,65 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.client;
+
+import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
+import org.junit.Test;
+
+import java.io.File;
+import java.net.URL;
+
+import static org.assertj.core.api.Assertions.*;
+
+/**
+ * Test for loading configurations form krb5.conf.
+ * krb5.conf is the configuration file in MIT Kerberos.
+ */
+public class KrbConfigLoadTest {
+
+    @Test
+    public void test() throws Exception {
+        URL confFileUrl = KrbConfigLoadTest.class.getResource("/krb5.conf");
+        File confFile = new File(confFileUrl.toURI());
+
+        KrbConfig krbConfig = new KrbConfig();
+        krbConfig.addIniConfig(confFile);
+        assertThat(krbConfig.getDefaultRealm()).isEqualTo("KRB.COM");
+        assertThat(krbConfig.getKdcRealm()).isEqualTo("TEST.COM");
+        assertThat(krbConfig.getKdcHost()).isEqualTo("kdc-server.example.com");
+        assertThat(krbConfig.getDnsLookUpKdc()).isFalse();
+        assertThat(krbConfig.getDnsLookUpRealm()).isFalse();
+        assertThat(krbConfig.getAllowWeakCrypto()).isTrue();
+        assertThat(krbConfig.getTicketLifetime()).isEqualTo(24 * 3600);
+        assertThat(krbConfig.getRenewLifetime()).isEqualTo(7 * 24 * 3600);
+        assertThat(krbConfig.isForwardableAllowed()).isTrue();
+        assertThat(krbConfig.getEncryptionTypes()).hasSize(2)
+                .contains(EncryptionType.DES_CBC_CRC,
+                        EncryptionType.AES128_CTS_HMAC_SHA1_96);
+        assertThat(krbConfig.getAllowableClockSkew()).isEqualTo(300);
+        assertThat(krbConfig.isProxiableAllowed()).isTrue();
+        assertThat(krbConfig.getDefaultTgsEnctypes()).hasSize(1)
+                .contains(EncryptionType.DES_CBC_CRC);
+        assertThat(krbConfig.getDefaultTktEnctypes()).hasSize(1)
+                .contains(EncryptionType.DES_CBC_CRC);
+        assertThat(krbConfig.getPkinitAnchors()).hasSize(1);
+        assertThat(krbConfig.getPkinitIdentities()).hasSize(2);
+        assertThat(krbConfig.getPkinitKdcHostName()).isEqualTo("kdc-server.example.com");
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoad.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoad.java b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoad.java
deleted file mode 100644
index 4520e86..0000000
--- a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoad.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.client;
-
-import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
-import org.junit.Test;
-
-import java.io.File;
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.*;
-
-/**
- * Test for loading configurations form krb5.conf.
- * krb5.conf is the configuration file in MIT Kerberos.
- */
-public class TestKrbConfigLoad {
-
-    @Test
-    public void test() throws Exception {
-        URL confFileUrl = TestKrbConfigLoad.class.getResource("/krb5.conf");
-        File confFile = new File(confFileUrl.toURI());
-
-        KrbConfig krbConfig = new KrbConfig();
-        krbConfig.addIniConfig(confFile);
-        assertThat(krbConfig.getDefaultRealm()).isEqualTo("KRB.COM");
-        assertThat(krbConfig.getKdcRealm()).isEqualTo("TEST.COM");
-        assertThat(krbConfig.getKdcHost()).isEqualTo("kdc-server.example.com");
-        assertThat(krbConfig.getDnsLookUpKdc()).isFalse();
-        assertThat(krbConfig.getDnsLookUpRealm()).isFalse();
-        assertThat(krbConfig.getAllowWeakCrypto()).isTrue();
-        assertThat(krbConfig.getTicketLifetime()).isEqualTo(24 * 3600);
-        assertThat(krbConfig.getRenewLifetime()).isEqualTo(7 * 24 * 3600);
-        assertThat(krbConfig.isForwardableAllowed()).isTrue();
-        assertThat(krbConfig.getEncryptionTypes()).hasSize(2)
-                .contains(EncryptionType.DES_CBC_CRC,
-                        EncryptionType.AES128_CTS_HMAC_SHA1_96);
-        assertThat(krbConfig.getAllowableClockSkew()).isEqualTo(300);
-        assertThat(krbConfig.isProxiableAllowed()).isTrue();
-        assertThat(krbConfig.getDefaultTgsEnctypes()).hasSize(1)
-                .contains(EncryptionType.DES_CBC_CRC);
-        assertThat(krbConfig.getDefaultTktEnctypes()).hasSize(1)
-                .contains(EncryptionType.DES_CBC_CRC);
-        assertThat(krbConfig.getPkinitAnchors()).hasSize(1);
-        assertThat(krbConfig.getPkinitIdentities()).hasSize(2);
-        assertThat(krbConfig.getPkinitKdcHostName()).isEqualTo("kdc-server.example.com");
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoadForSpecials.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoadForSpecials.java b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoadForSpecials.java
deleted file mode 100644
index a713e1e..0000000
--- a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/TestKrbConfigLoadForSpecials.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.client;
-
-import org.junit.Test;
-
-import java.io.File;
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.*;
-
-/**
- * Test for loading configurations form krb5.conf with default kdc realm.
- * krb5.conf is the configuration file in MIT Kerberos.
- */
-public class TestKrbConfigLoadForSpecials {
-
-    @Test
-    public void test() throws Exception {
-        URL confFileUrl = TestKrbConfigLoadForSpecials.class.getResource(
-                        "/krb5-specials.conf");
-        File confFile = new File(confFileUrl.toURI());
-
-        KrbConfig krbConfig = new KrbConfig();
-        krbConfig.addIniConfig(confFile);
-        assertThat(krbConfig.getKdcRealm()).isEqualTo("KRB.COM");
-        assertThat(krbConfig.getKdcPort()).isEqualTo(88);
-
-        assertThat(krbConfig.allowUdp()).isEqualTo(true);
-        assertThat(krbConfig.allowTcp()).isEqualTo(true);
-        assertThat(krbConfig.getKdcTcpPort()).isEqualTo(88);
-        assertThat(krbConfig.getKdcUdpPort()).isEqualTo(88);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsRepCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsRepCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsRepCodecTest.java
new file mode 100644
index 0000000..fcf131a
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsRepCodecTest.java
@@ -0,0 +1,72 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.type.base.NameType;
+import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
+import org.apache.kerby.kerberos.kerb.type.kdc.AsRep;
+import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test AsRep message using a real 'correct' network packet captured from MS-AD to detective programming errors
+ * and compatibility issues particularly regarding Kerberos crypto.
+ */
+public class AsRepCodecTest {
+
+    @Test
+    public void test() throws IOException {
+        byte[] bytes = CodecTestUtil.readBinaryFile("/asrep.token");
+        ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
+
+        AsRep asRep = new AsRep();
+        asRep.decode(asRepToken);
+
+        assertThat(asRep.getPvno()).isEqualTo(5);
+        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
+        assertThat(asRep.getCrealm()).isEqualTo("DENYDC.COM");
+
+        PrincipalName cName = asRep.getCname();
+        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
+        assertThat(cName.getNameStrings()).hasSize(1).contains("u5");
+
+        Ticket ticket = asRep.getTicket();
+        assertThat(ticket.getTktvno()).isEqualTo(5);
+        assertThat(ticket.getRealm()).isEqualTo("DENYDC.COM");
+        PrincipalName sName = ticket.getSname();
+        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
+        assertThat(sName.getNameStrings()).hasSize(2)
+                .contains("krbtgt", "DENYDC.COM");
+        //FIXME
+        //EncTicketPart encTicketPart = ticket.getEncPart();
+        //assertThat(encTicketPart.getKey().getKvno()).isEqualTo(2);
+        //assertThat(encTicketPart.getKey().getKeyType().getValue()).isEqualTo(0x0017);
+
+        //EncKdcRepPart encKdcRepPart = asRep.getEncPart();
+        //assertThat(encKdcRepPart.getKey().getKeyType().getValue()).isEqualTo(0x0017);
+        //assertThat(encKdcRepPart.getKey().getKvno()).isEqualTo(7);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsReqCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsReqCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsReqCodecTest.java
new file mode 100644
index 0000000..2ffd960
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/AsReqCodecTest.java
@@ -0,0 +1,104 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.kerberos.kerb.type.base.*;
+import org.apache.kerby.kerberos.kerb.type.kdc.AsReq;
+import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
+import org.apache.kerby.kerberos.kerb.type.pa.PaData;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.SimpleTimeZone;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test AsReq message using a real 'correct' network packet captured from MS-AD
+ * to detective programming errors and compatibility issues particularly
+ * regarding Kerberos crypto.
+ */
+public class AsReqCodecTest {
+
+    @Test
+    public void test() throws IOException, ParseException {
+        byte[] bytes = CodecTestUtil.readBinaryFile("/asreq.token");
+        Asn1.decodeAndDump(bytes);
+        ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
+
+        AsReq asReq = new AsReq();
+        asReq.decode(asReqToken);
+        Asn1.dump(asReq);
+
+        assertThat(asReq.getPvno()).isEqualTo(5);
+        assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
+
+        PaData paData = asReq.getPaData();
+        PaDataEntry encTimestampEntry = paData.findEntry(PaDataType.ENC_TIMESTAMP);
+        assertThat(encTimestampEntry.getPaDataType()).isEqualTo(PaDataType.ENC_TIMESTAMP);
+        assertThat(encTimestampEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 33, 96));
+        PaDataEntry pacRequestEntry = paData.findEntry(PaDataType.PAC_REQUEST);
+        assertThat(pacRequestEntry.getPaDataType()).isEqualTo(PaDataType.PAC_REQUEST);
+        assertThat(pacRequestEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 108, 115));
+
+        KdcReqBody body = asReq.getReqBody();
+        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
+        assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 126, 130));
+        PrincipalName cName = body.getCname();
+        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
+        assertThat(cName.getName()).isEqualTo("des");
+        assertThat(body.getRealm()).isEqualTo("DENYDC");
+        PrincipalName sName = body.getSname();
+        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
+        assertThat(sName.getNameStrings()).hasSize(2)
+                .contains("krbtgt", "DENYDC");
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
+        Date date = sdf.parse("20370913024805");
+        assertThat(body.getTill().getTime()).isEqualTo(date.getTime());
+        assertThat(body.getRtime().getTime()).isEqualTo(date.getTime());
+
+        assertThat(body.getNonce()).isEqualTo(197451134);
+
+        List<EncryptionType> types = body.getEtypes();
+        assertThat(types).hasSize(7);
+        assertThat(types.get(0).getValue()).isEqualTo(0x0017);
+        //assertThat(types.get(1).getValue()).isEqualTo(0xff7b);//FIXME
+        //assertThat(types.get(2).getValue()).isEqualTo(0x0080);//FIXME
+        assertThat(types.get(3).getValue()).isEqualTo(0x0003);
+        assertThat(types.get(4).getValue()).isEqualTo(0x0001);
+        assertThat(types.get(5).getValue()).isEqualTo(0x0018);
+        //assertThat(types.get(6).getValue()).isEqualTo(0xff79);//FIXME
+
+        List<HostAddress> hostAddress = body.getAddresses().getElements();
+        assertThat(hostAddress).hasSize(1);
+        assertThat(hostAddress.get(0).getAddrType()).isEqualTo(HostAddrType.ADDRTYPE_NETBIOS);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PaPkAsRepTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PaPkAsRepTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PaPkAsRepTest.java
new file mode 100644
index 0000000..a35485e
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PaPkAsRepTest.java
@@ -0,0 +1,45 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.ContentInfo;
+import org.apache.kerby.kerberos.kerb.KrbCodec;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.DhRepInfo;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class PaPkAsRepTest {
+
+    @Test
+    public void test() throws IOException, KrbException {
+        PaPkAsRep paPkAsRep = new PaPkAsRep();
+        DhRepInfo dhRepInfo = new DhRepInfo();
+        ContentInfo contentInfo = new ContentInfo();
+        contentInfo.setContentType("1.2.840.113549.1.7.2");
+        dhRepInfo.setDHSignedData(contentInfo.encode());
+        paPkAsRep.setDHRepInfo(dhRepInfo);
+        Asn1.parseAndDump(paPkAsRep.encode());
+        KrbCodec.decode(paPkAsRep.encode(), PaPkAsRep.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsRepCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsRepCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsRepCodecTest.java
new file mode 100644
index 0000000..af24cb9
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsRepCodecTest.java
@@ -0,0 +1,123 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.EncapsulatedContentInfo;
+import org.apache.kerby.cms.type.SignedContentInfo;
+import org.apache.kerby.cms.type.SignedData;
+import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
+import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.type.base.NameType;
+import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
+import org.apache.kerby.kerberos.kerb.type.kdc.AsRep;
+import org.apache.kerby.kerberos.kerb.type.pa.PaData;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.DhRepInfo;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.KdcDhKeyInfo;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
+import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PkinitAnonymousAsRepCodecTest {
+    @Test
+    public void test() throws IOException {
+        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_anonymous_asrep.token");
+        ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
+
+        AsRep asRep = new AsRep();
+        asRep.decode(asRepToken);
+
+        assertThat(asRep.getPvno()).isEqualTo(5);
+        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
+        PaData paData = asRep.getPaData();
+
+        PaDataEntry pkAsRepEntry = paData.findEntry(PaDataType.PK_AS_REP);
+        assertThat(pkAsRepEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REP);
+
+        PaPkAsRep paPkAsRep = new PaPkAsRep();
+        byte[] padataValue = pkAsRepEntry.getPaDataValue();
+        //Asn1.parseAndDump(padataValue);
+        paPkAsRep.decode(padataValue);
+
+        testPaPkAsRep(paPkAsRep);
+
+        PaDataEntry etypeInfo2Entry = paData.findEntry(PaDataType.ETYPE_INFO2);
+        assertThat(etypeInfo2Entry.getPaDataType()).isEqualTo(PaDataType.ETYPE_INFO2);
+
+        PaDataEntry pkinitKxEntry = paData.findEntry(PaDataType.PKINIT_KX);
+        assertThat(pkinitKxEntry.getPaDataType()).isEqualTo(PaDataType.PKINIT_KX);
+
+        assertThat(asRep.getPvno()).isEqualTo(5);
+        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
+        assertThat(asRep.getCrealm()).isEqualTo("WELLKNOWN:ANONYMOUS");
+
+        PrincipalName cName = asRep.getCname();
+        assertThat(cName.getNameType()).isEqualTo(NameType.NT_WELLKNOWN);
+        assertThat(cName.getNameStrings()).hasSize(2).contains("WELLKNOWN", "ANONYMOUS");
+
+        Ticket ticket = asRep.getTicket();
+        assertThat(ticket.getTktvno()).isEqualTo(5);
+        assertThat(ticket.getRealm()).isEqualTo("EXAMPLE.COM");
+        PrincipalName sName = ticket.getSname();
+        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
+        assertThat(sName.getNameStrings()).hasSize(2)
+                .contains("krbtgt", "EXAMPLE.COM");
+
+        EncryptedData encryptedData = ticket.getEncryptedEncPart();
+        assertThat(encryptedData.getKvno()).isEqualTo(1);
+        assertThat(encryptedData.getEType().getValue()).isEqualTo(0x0012);
+
+        // Test encode PaPkAsRep
+        byte[] encodedPaPkAsRep = paPkAsRep.encode();
+        Asn1.parseAndDump(encodedPaPkAsRep);
+        PaPkAsRep decodedPaPkAsRep = new PaPkAsRep();
+        decodedPaPkAsRep.decode(encodedPaPkAsRep);
+        testPaPkAsRep(decodedPaPkAsRep);
+    }
+
+    private void testPaPkAsRep(PaPkAsRep paPkAsRep) throws IOException {
+        assertThat(paPkAsRep.getDHRepInfo()).isNotNull();
+
+        DhRepInfo dhRepInfo = paPkAsRep.getDHRepInfo();
+        byte[] dhSignedData = dhRepInfo.getDHSignedData();
+        SignedContentInfo contentInfo = new SignedContentInfo();
+        contentInfo.decode(dhSignedData);
+        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
+        SignedData signedData = contentInfo.getContentAs(SignedData.class);
+        assertThat(signedData.getCertificates()).isNotNull();
+
+        EncapsulatedContentInfo encapsulatedContentInfo = signedData.getEncapContentInfo();
+        assertThat(encapsulatedContentInfo.getContentType()).isEqualTo("1.3.6.1.5.2.3.2");
+
+        byte[] eContentInfo = encapsulatedContentInfo.getContent();
+        KdcDhKeyInfo kdcDhKeyInfo = new KdcDhKeyInfo();
+        kdcDhKeyInfo.decode(eContentInfo);
+        assertThat(kdcDhKeyInfo.getSubjectPublicKey()).isNotNull();
+        assertThat(kdcDhKeyInfo.getDHKeyExpiration()).isNotNull();
+        assertThat(kdcDhKeyInfo.getNonce()).isNotNull();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsReqCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsReqCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsReqCodecTest.java
new file mode 100644
index 0000000..424a430
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitAnonymousAsReqCodecTest.java
@@ -0,0 +1,151 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.SignedContentInfo;
+import org.apache.kerby.cms.type.SignedData;
+import org.apache.kerby.kerberos.kerb.KrbConstant;
+import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
+import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.type.base.NameType;
+import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
+import org.apache.kerby.kerberos.kerb.type.kdc.AsReq;
+import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
+import org.apache.kerby.kerberos.kerb.type.pa.PaData;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.AuthPack;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsReq;
+import org.apache.kerby.x509.type.DhParameter;
+import org.apache.kerby.x509.type.SubjectPublicKeyInfo;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.*;
+
+public class PkinitAnonymousAsReqCodecTest {
+    @Test
+    public void test() throws IOException, ParseException {
+        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_anonymous_asreq.token");
+        //Asn1.dump(bytes, true);
+        ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
+
+        AsReq asReq = new AsReq();
+        asReq.decode(asReqToken);
+        //Asn1.dump(asReq, false);
+
+        assertThat(asReq.getPvno()).isEqualTo(5);
+        assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
+
+        PaData paData = asReq.getPaData();
+
+        PaDataEntry paFxCookieEntry = paData.findEntry(PaDataType.FX_COOKIE);
+        assertThat(paFxCookieEntry.getPaDataType()).isEqualTo(PaDataType.FX_COOKIE);
+        assertThat(paFxCookieEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 38, 41));
+
+        PaDataEntry pkAsReqEntry = paData.findEntry(PaDataType.PK_AS_REQ);
+        assertThat(pkAsReqEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REQ);
+        assertThat(pkAsReqEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 58, 1366));
+
+        PaPkAsReq paPkAsReq = new PaPkAsReq();
+        paPkAsReq.decode(pkAsReqEntry.getPaDataValue());
+
+        testPaPkAsReq(paPkAsReq);
+
+        PaDataEntry encpaEntry = paData.findEntry(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
+        assertThat(encpaEntry.getPaDataType()).isEqualTo(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
+        assertThat(encpaEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 1376, 1376));
+
+        KdcReqBody body = asReq.getReqBody();
+        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
+        assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 1389, 1393));
+        PrincipalName cName = body.getCname();
+        assertThat(cName.getNameType()).isEqualTo(NameType.NT_WELLKNOWN);
+        assertThat(cName.getName()).isEqualTo(KrbConstant.ANONYMOUS_PRINCIPAL);
+        assertThat(body.getRealm()).isEqualTo("EXAMPLE.COM");
+        PrincipalName sName = body.getSname();
+        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
+        assertThat(sName.getNameStrings()).hasSize(2)
+                .contains("krbtgt", "EXAMPLE.COM");
+
+        assertThat(body.getNonce()).isEqualTo(1797404543);
+
+        List<EncryptionType> types = body.getEtypes();
+        assertThat(types).hasSize(6);
+        assertThat(types.get(0).getValue()).isEqualTo(0x0012);
+        assertThat(types.get(1).getValue()).isEqualTo(0x0011);
+        assertThat(types.get(2).getValue()).isEqualTo(0x0010);
+        assertThat(types.get(3).getValue()).isEqualTo(0x0017);
+        assertThat(types.get(4).getValue()).isEqualTo(0x0019);
+        assertThat(types.get(5).getValue()).isEqualTo(0x001A);
+
+        // Test encode PaPkAsReq
+        byte[] encodedPaPkAsReq = paPkAsReq.encode();
+        PaPkAsReq decodedPaPkAsReq = new PaPkAsReq();
+        decodedPaPkAsReq.decode(encodedPaPkAsReq);
+        testPaPkAsReq(decodedPaPkAsReq);
+    }
+
+    private void testPaPkAsReq(PaPkAsReq paPkAsReq) throws IOException {
+        SignedContentInfo contentInfo = new SignedContentInfo();
+        Asn1.parseAndDump(paPkAsReq.getSignedAuthPack());
+        contentInfo.decode(paPkAsReq.getSignedAuthPack());
+        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
+        Asn1.dump(contentInfo);
+
+        SignedData signedData = contentInfo.getSignedData();
+        assertThat(signedData.getVersion()).isEqualTo(3);
+        assertThat(signedData.getDigestAlgorithms().getElements().isEmpty()).isTrue();
+        assertThat(signedData.getCertificates().getElements().isEmpty()).isTrue();
+        assertThat(signedData.getCrls().getElements().isEmpty()).isTrue();
+        assertThat(signedData.getSignerInfos().getElements().isEmpty()).isTrue();
+        assertThat(signedData.getEncapContentInfo().getContentType())
+                .isEqualTo("1.3.6.1.5.2.3.1");
+
+        AuthPack authPack = new AuthPack();
+        Asn1.parseAndDump(signedData.getEncapContentInfo().getContent());
+        authPack.decode(signedData.getEncapContentInfo().getContent());
+        assertThat(authPack.getsupportedCmsTypes().getElements().size()).isEqualTo(1);
+        assertThat(authPack.getsupportedCmsTypes().getElements().get(0).getAlgorithm())
+                .isEqualTo("1.2.840.113549.3.7");
+        SubjectPublicKeyInfo subjectPublicKeyInfo = authPack.getClientPublicValue();
+        assertThat(subjectPublicKeyInfo.getAlgorithm().getAlgorithm())
+                .isEqualTo("1.2.840.10046.2.1");
+        DhParameter dhParameter =
+            subjectPublicKeyInfo.getAlgorithm().getParametersAs(DhParameter.class);
+        assertThat(dhParameter.getG()).isEqualTo(BigInteger.valueOf(2));
+
+        assertThat(authPack.getsupportedKDFs().getElements().size()).isEqualTo(3);
+
+        assertThat(authPack.getsupportedKDFs().getElements().get(0).getKdfId())
+                .isEqualTo("1.3.6.1.5.2.3.6.2");
+        assertThat(authPack.getsupportedKDFs().getElements().get(1).getKdfId())
+                .isEqualTo("1.3.6.1.5.2.3.6.1");
+        assertThat(authPack.getsupportedKDFs().getElements().get(2).getKdfId())
+                .isEqualTo("1.3.6.1.5.2.3.6.3");
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsRepCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsRepCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsRepCodecTest.java
new file mode 100644
index 0000000..6590d9c
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsRepCodecTest.java
@@ -0,0 +1,68 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.ContentInfo;
+import org.apache.kerby.cms.type.EnvelopedData;
+import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.type.kdc.AsRep;
+import org.apache.kerby.kerberos.kerb.type.pa.PaData;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import static org.assertj.core.api.Assertions.*;
+
+public class PkinitRsaAsRepCodecTest {
+    @Test
+    public void test() throws IOException {
+        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_rsa_asrep.token");
+        ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
+
+        AsRep asRep = new AsRep();
+        asRep.decode(asRepToken);
+
+        assertThat(asRep.getPvno()).isEqualTo(5);
+        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
+        PaData paData = asRep.getPaData();
+
+        PaDataEntry pkAsRepEntry = paData.findEntry(PaDataType.PK_AS_REP);
+        assertThat(pkAsRepEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REP);
+
+        PaPkAsRep paPkAsRep = new PaPkAsRep();
+        byte[] padataValue = pkAsRepEntry.getPaDataValue();
+        paPkAsRep.decode(padataValue);
+
+        assertThat(paPkAsRep.getEncKeyPack()).isNotNull();
+
+        byte[] encKeyPack = paPkAsRep.getEncKeyPack();
+        Asn1.parseAndDump(encKeyPack);
+        ContentInfo contentInfo = new ContentInfo();
+        contentInfo.decode(encKeyPack);
+        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.3");
+        EnvelopedData envelopedData = contentInfo.getContentAs(EnvelopedData.class);
+        Asn1.dump(envelopedData);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsReqCodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsReqCodecTest.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsReqCodecTest.java
new file mode 100644
index 0000000..10666f5
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/PkinitRsaAsReqCodecTest.java
@@ -0,0 +1,112 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.codec;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.ContentInfo;
+import org.apache.kerby.cms.type.SignedData;
+import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
+import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.type.base.NameType;
+import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
+import org.apache.kerby.kerberos.kerb.type.kdc.AsReq;
+import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
+import org.apache.kerby.kerberos.kerb.type.pa.PaData;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
+import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
+import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsReq;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.*;
+
+public class PkinitRsaAsReqCodecTest {
+    @Test
+    public void test() throws IOException, ParseException {
+        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_rsa_asreq.token");
+        Asn1.parseAndDump(bytes);
+        ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
+
+        AsReq asReq = new AsReq();
+        asReq.decode(asReqToken);
+        //Asn1.decodeAndDump(asReq);
+
+        assertThat(asReq.getPvno()).isEqualTo(5);
+        assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
+
+        PaData paData = asReq.getPaData();
+
+        PaDataEntry paFxCookieEntry = paData.findEntry(PaDataType.FX_COOKIE);
+        assertThat(paFxCookieEntry.getPaDataType()).isEqualTo(PaDataType.FX_COOKIE);
+        assertThat(paFxCookieEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 38, 41));
+
+        PaDataEntry pkAsReqEntry = paData.findEntry(PaDataType.PK_AS_REQ);
+        assertThat(pkAsReqEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REQ);
+        assertThat(pkAsReqEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 58, 2138));
+
+        PaPkAsReq paPkAsReq = new PaPkAsReq();
+        paPkAsReq.decode(pkAsReqEntry.getPaDataValue());
+        ContentInfo contentInfo = new ContentInfo();
+        //Asn1.parseAndDump(paPkAsReq.getSignedAuthPack());
+        contentInfo.decode(paPkAsReq.getSignedAuthPack());
+        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
+        //Asn1.dump(contentInfo);
+
+        SignedData signedData = contentInfo.getContentAs(SignedData.class);
+        assertThat(signedData.getCertificates().getElements().size()).isEqualTo(1);
+        assertThat(signedData.getEncapContentInfo().getContentType()).isEqualTo("1.3.6.1.5.2.3.1");
+
+        PaDataEntry encpaEntry = paData.findEntry(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
+        assertThat(encpaEntry.getPaDataType()).isEqualTo(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
+        assertThat(encpaEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 2148, 2148));
+
+        KdcReqBody body = asReq.getReqBody();
+        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
+        assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 2161, 2165));
+        PrincipalName cName = body.getCname();
+        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
+        assertThat(body.getRealm()).isEqualTo("EXAMPLE.COM");
+        PrincipalName sName = body.getSname();
+        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
+        assertThat(sName.getNameStrings()).hasSize(2)
+                .contains("krbtgt", "EXAMPLE.COM");
+
+        assertThat(body.getNonce()).isEqualTo(658979657);
+
+        List<EncryptionType> types = body.getEtypes();
+        assertThat(types).hasSize(6);
+        assertThat(types.get(0).getValue()).isEqualTo(0x0012);
+        assertThat(types.get(1).getValue()).isEqualTo(0x0011);
+        assertThat(types.get(2).getValue()).isEqualTo(0x0010);
+        assertThat(types.get(3).getValue()).isEqualTo(0x0017);
+        assertThat(types.get(4).getValue()).isEqualTo(0x0019);
+        assertThat(types.get(5).getValue()).isEqualTo(0x001A);
+
+        // Test encode PaPkAsReq
+        byte[] encodedPaPkAsReq = paPkAsReq.encode();
+        PaPkAsReq decodedPaPkAsReq = new PaPkAsReq();
+        decodedPaPkAsReq.decode(encodedPaPkAsReq);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsRepCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsRepCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsRepCodec.java
deleted file mode 100644
index 24f0ab0..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsRepCodec.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.type.base.NameType;
-import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
-import org.apache.kerby.kerberos.kerb.type.kdc.AsRep;
-import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Test AsRep message using a real 'correct' network packet captured from MS-AD to detective programming errors
- * and compatibility issues particularly regarding Kerberos crypto.
- */
-public class TestAsRepCodec {
-
-    @Test
-    public void test() throws IOException {
-        byte[] bytes = CodecTestUtil.readBinaryFile("/asrep.token");
-        ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
-
-        AsRep asRep = new AsRep();
-        asRep.decode(asRepToken);
-
-        assertThat(asRep.getPvno()).isEqualTo(5);
-        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
-        assertThat(asRep.getCrealm()).isEqualTo("DENYDC.COM");
-
-        PrincipalName cName = asRep.getCname();
-        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
-        assertThat(cName.getNameStrings()).hasSize(1).contains("u5");
-
-        Ticket ticket = asRep.getTicket();
-        assertThat(ticket.getTktvno()).isEqualTo(5);
-        assertThat(ticket.getRealm()).isEqualTo("DENYDC.COM");
-        PrincipalName sName = ticket.getSname();
-        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
-        assertThat(sName.getNameStrings()).hasSize(2)
-                .contains("krbtgt", "DENYDC.COM");
-        //FIXME
-        //EncTicketPart encTicketPart = ticket.getEncPart();
-        //assertThat(encTicketPart.getKey().getKvno()).isEqualTo(2);
-        //assertThat(encTicketPart.getKey().getKeyType().getValue()).isEqualTo(0x0017);
-
-        //EncKdcRepPart encKdcRepPart = asRep.getEncPart();
-        //assertThat(encKdcRepPart.getKey().getKeyType().getValue()).isEqualTo(0x0017);
-        //assertThat(encKdcRepPart.getKey().getKvno()).isEqualTo(7);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsReqCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsReqCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsReqCodec.java
deleted file mode 100644
index 6319e55..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestAsReqCodec.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.kerberos.kerb.type.base.*;
-import org.apache.kerby.kerberos.kerb.type.kdc.AsReq;
-import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
-import org.apache.kerby.kerberos.kerb.type.pa.PaData;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.SimpleTimeZone;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Test AsReq message using a real 'correct' network packet captured from MS-AD
- * to detective programming errors and compatibility issues particularly
- * regarding Kerberos crypto.
- */
-public class TestAsReqCodec {
-
-    @Test
-    public void test() throws IOException, ParseException {
-        byte[] bytes = CodecTestUtil.readBinaryFile("/asreq.token");
-        Asn1.decodeAndDump(bytes);
-        ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
-
-        AsReq asReq = new AsReq();
-        asReq.decode(asReqToken);
-        Asn1.dump(asReq);
-
-        assertThat(asReq.getPvno()).isEqualTo(5);
-        assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
-
-        PaData paData = asReq.getPaData();
-        PaDataEntry encTimestampEntry = paData.findEntry(PaDataType.ENC_TIMESTAMP);
-        assertThat(encTimestampEntry.getPaDataType()).isEqualTo(PaDataType.ENC_TIMESTAMP);
-        assertThat(encTimestampEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 33, 96));
-        PaDataEntry pacRequestEntry = paData.findEntry(PaDataType.PAC_REQUEST);
-        assertThat(pacRequestEntry.getPaDataType()).isEqualTo(PaDataType.PAC_REQUEST);
-        assertThat(pacRequestEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 108, 115));
-
-        KdcReqBody body = asReq.getReqBody();
-        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
-        assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 126, 130));
-        PrincipalName cName = body.getCname();
-        assertThat(cName.getNameType()).isEqualTo(NameType.NT_PRINCIPAL);
-        assertThat(cName.getName()).isEqualTo("des");
-        assertThat(body.getRealm()).isEqualTo("DENYDC");
-        PrincipalName sName = body.getSname();
-        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
-        assertThat(sName.getNameStrings()).hasSize(2)
-                .contains("krbtgt", "DENYDC");
-
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
-        Date date = sdf.parse("20370913024805");
-        assertThat(body.getTill().getTime()).isEqualTo(date.getTime());
-        assertThat(body.getRtime().getTime()).isEqualTo(date.getTime());
-
-        assertThat(body.getNonce()).isEqualTo(197451134);
-
-        List<EncryptionType> types = body.getEtypes();
-        assertThat(types).hasSize(7);
-        assertThat(types.get(0).getValue()).isEqualTo(0x0017);
-        //assertThat(types.get(1).getValue()).isEqualTo(0xff7b);//FIXME
-        //assertThat(types.get(2).getValue()).isEqualTo(0x0080);//FIXME
-        assertThat(types.get(3).getValue()).isEqualTo(0x0003);
-        assertThat(types.get(4).getValue()).isEqualTo(0x0001);
-        assertThat(types.get(5).getValue()).isEqualTo(0x0018);
-        //assertThat(types.get(6).getValue()).isEqualTo(0xff79);//FIXME
-
-        List<HostAddress> hostAddress = body.getAddresses().getElements();
-        assertThat(hostAddress).hasSize(1);
-        assertThat(hostAddress.get(0).getAddrType()).isEqualTo(HostAddrType.ADDRTYPE_NETBIOS);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPaPkAsRep.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPaPkAsRep.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPaPkAsRep.java
deleted file mode 100644
index 8af6fe8..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPaPkAsRep.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.ContentInfo;
-import org.apache.kerby.kerberos.kerb.KrbCodec;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.DhRepInfo;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestPaPkAsRep {
-
-    @Test
-    public void test() throws IOException, KrbException {
-        PaPkAsRep paPkAsRep = new PaPkAsRep();
-        DhRepInfo dhRepInfo = new DhRepInfo();
-        ContentInfo contentInfo = new ContentInfo();
-        contentInfo.setContentType("1.2.840.113549.1.7.2");
-        dhRepInfo.setDHSignedData(contentInfo.encode());
-        paPkAsRep.setDHRepInfo(dhRepInfo);
-        Asn1.parseAndDump(paPkAsRep.encode());
-        KrbCodec.decode(paPkAsRep.encode(), PaPkAsRep.class);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsRepCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsRepCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsRepCodec.java
deleted file mode 100644
index ac660f5..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsRepCodec.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.EncapsulatedContentInfo;
-import org.apache.kerby.cms.type.SignedContentInfo;
-import org.apache.kerby.cms.type.SignedData;
-import org.apache.kerby.kerberos.kerb.type.base.EncryptedData;
-import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.type.base.NameType;
-import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
-import org.apache.kerby.kerberos.kerb.type.kdc.AsRep;
-import org.apache.kerby.kerberos.kerb.type.pa.PaData;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.DhRepInfo;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.KdcDhKeyInfo;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
-import org.apache.kerby.kerberos.kerb.type.ticket.Ticket;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestPkinitAnonymousAsRepCodec {
-    @Test
-    public void test() throws IOException {
-        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_anonymous_asrep.token");
-        ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
-
-        AsRep asRep = new AsRep();
-        asRep.decode(asRepToken);
-
-        assertThat(asRep.getPvno()).isEqualTo(5);
-        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
-        PaData paData = asRep.getPaData();
-
-        PaDataEntry pkAsRepEntry = paData.findEntry(PaDataType.PK_AS_REP);
-        assertThat(pkAsRepEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REP);
-
-        PaPkAsRep paPkAsRep = new PaPkAsRep();
-        byte[] padataValue = pkAsRepEntry.getPaDataValue();
-        //Asn1.parseAndDump(padataValue);
-        paPkAsRep.decode(padataValue);
-
-        testPaPkAsRep(paPkAsRep);
-
-        PaDataEntry etypeInfo2Entry = paData.findEntry(PaDataType.ETYPE_INFO2);
-        assertThat(etypeInfo2Entry.getPaDataType()).isEqualTo(PaDataType.ETYPE_INFO2);
-
-        PaDataEntry pkinitKxEntry = paData.findEntry(PaDataType.PKINIT_KX);
-        assertThat(pkinitKxEntry.getPaDataType()).isEqualTo(PaDataType.PKINIT_KX);
-
-        assertThat(asRep.getPvno()).isEqualTo(5);
-        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
-        assertThat(asRep.getCrealm()).isEqualTo("WELLKNOWN:ANONYMOUS");
-
-        PrincipalName cName = asRep.getCname();
-        assertThat(cName.getNameType()).isEqualTo(NameType.NT_WELLKNOWN);
-        assertThat(cName.getNameStrings()).hasSize(2).contains("WELLKNOWN", "ANONYMOUS");
-
-        Ticket ticket = asRep.getTicket();
-        assertThat(ticket.getTktvno()).isEqualTo(5);
-        assertThat(ticket.getRealm()).isEqualTo("EXAMPLE.COM");
-        PrincipalName sName = ticket.getSname();
-        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
-        assertThat(sName.getNameStrings()).hasSize(2)
-                .contains("krbtgt", "EXAMPLE.COM");
-
-        EncryptedData encryptedData = ticket.getEncryptedEncPart();
-        assertThat(encryptedData.getKvno()).isEqualTo(1);
-        assertThat(encryptedData.getEType().getValue()).isEqualTo(0x0012);
-
-        // Test encode PaPkAsRep
-        byte[] encodedPaPkAsRep = paPkAsRep.encode();
-        Asn1.parseAndDump(encodedPaPkAsRep);
-        PaPkAsRep decodedPaPkAsRep = new PaPkAsRep();
-        decodedPaPkAsRep.decode(encodedPaPkAsRep);
-        testPaPkAsRep(decodedPaPkAsRep);
-    }
-
-    private void testPaPkAsRep(PaPkAsRep paPkAsRep) throws IOException {
-        assertThat(paPkAsRep.getDHRepInfo()).isNotNull();
-
-        DhRepInfo dhRepInfo = paPkAsRep.getDHRepInfo();
-        byte[] dhSignedData = dhRepInfo.getDHSignedData();
-        SignedContentInfo contentInfo = new SignedContentInfo();
-        contentInfo.decode(dhSignedData);
-        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
-        SignedData signedData = contentInfo.getContentAs(SignedData.class);
-        assertThat(signedData.getCertificates()).isNotNull();
-
-        EncapsulatedContentInfo encapsulatedContentInfo = signedData.getEncapContentInfo();
-        assertThat(encapsulatedContentInfo.getContentType()).isEqualTo("1.3.6.1.5.2.3.2");
-
-        byte[] eContentInfo = encapsulatedContentInfo.getContent();
-        KdcDhKeyInfo kdcDhKeyInfo = new KdcDhKeyInfo();
-        kdcDhKeyInfo.decode(eContentInfo);
-        assertThat(kdcDhKeyInfo.getSubjectPublicKey()).isNotNull();
-        assertThat(kdcDhKeyInfo.getDHKeyExpiration()).isNotNull();
-        assertThat(kdcDhKeyInfo.getNonce()).isNotNull();
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsReqCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsReqCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsReqCodec.java
deleted file mode 100644
index 442bb7d..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitAnonymousAsReqCodec.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.SignedContentInfo;
-import org.apache.kerby.cms.type.SignedData;
-import org.apache.kerby.kerberos.kerb.KrbConstant;
-import org.apache.kerby.kerberos.kerb.type.base.EncryptionType;
-import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.type.base.NameType;
-import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
-import org.apache.kerby.kerberos.kerb.type.kdc.AsReq;
-import org.apache.kerby.kerberos.kerb.type.kdc.KdcReqBody;
-import org.apache.kerby.kerberos.kerb.type.pa.PaData;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.AuthPack;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsReq;
-import org.apache.kerby.x509.type.DhParameter;
-import org.apache.kerby.x509.type.SubjectPublicKeyInfo;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.*;
-
-public class TestPkinitAnonymousAsReqCodec {
-    @Test
-    public void test() throws IOException, ParseException {
-        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_anonymous_asreq.token");
-        //Asn1.dump(bytes, true);
-        ByteBuffer asReqToken = ByteBuffer.wrap(bytes);
-
-        AsReq asReq = new AsReq();
-        asReq.decode(asReqToken);
-        //Asn1.dump(asReq, false);
-
-        assertThat(asReq.getPvno()).isEqualTo(5);
-        assertThat(asReq.getMsgType()).isEqualTo(KrbMessageType.AS_REQ);
-
-        PaData paData = asReq.getPaData();
-
-        PaDataEntry paFxCookieEntry = paData.findEntry(PaDataType.FX_COOKIE);
-        assertThat(paFxCookieEntry.getPaDataType()).isEqualTo(PaDataType.FX_COOKIE);
-        assertThat(paFxCookieEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 38, 41));
-
-        PaDataEntry pkAsReqEntry = paData.findEntry(PaDataType.PK_AS_REQ);
-        assertThat(pkAsReqEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REQ);
-        assertThat(pkAsReqEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 58, 1366));
-
-        PaPkAsReq paPkAsReq = new PaPkAsReq();
-        paPkAsReq.decode(pkAsReqEntry.getPaDataValue());
-
-        testPaPkAsReq(paPkAsReq);
-
-        PaDataEntry encpaEntry = paData.findEntry(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
-        assertThat(encpaEntry.getPaDataType()).isEqualTo(PaDataType.ENCPADATA_REQ_ENC_PA_REP);
-        assertThat(encpaEntry.getPaDataValue()).isEqualTo(Arrays.copyOfRange(bytes, 1376, 1376));
-
-        KdcReqBody body = asReq.getReqBody();
-        assertThat(body.getKdcOptions().getPadding()).isEqualTo(0);
-        assertThat(body.getKdcOptions().getValue()).isEqualTo(Arrays.copyOfRange(bytes, 1389, 1393));
-        PrincipalName cName = body.getCname();
-        assertThat(cName.getNameType()).isEqualTo(NameType.NT_WELLKNOWN);
-        assertThat(cName.getName()).isEqualTo(KrbConstant.ANONYMOUS_PRINCIPAL);
-        assertThat(body.getRealm()).isEqualTo("EXAMPLE.COM");
-        PrincipalName sName = body.getSname();
-        assertThat(sName.getNameType()).isEqualTo(NameType.NT_SRV_INST);
-        assertThat(sName.getNameStrings()).hasSize(2)
-                .contains("krbtgt", "EXAMPLE.COM");
-
-        assertThat(body.getNonce()).isEqualTo(1797404543);
-
-        List<EncryptionType> types = body.getEtypes();
-        assertThat(types).hasSize(6);
-        assertThat(types.get(0).getValue()).isEqualTo(0x0012);
-        assertThat(types.get(1).getValue()).isEqualTo(0x0011);
-        assertThat(types.get(2).getValue()).isEqualTo(0x0010);
-        assertThat(types.get(3).getValue()).isEqualTo(0x0017);
-        assertThat(types.get(4).getValue()).isEqualTo(0x0019);
-        assertThat(types.get(5).getValue()).isEqualTo(0x001A);
-
-        // Test encode PaPkAsReq
-        byte[] encodedPaPkAsReq = paPkAsReq.encode();
-        PaPkAsReq decodedPaPkAsReq = new PaPkAsReq();
-        decodedPaPkAsReq.decode(encodedPaPkAsReq);
-        testPaPkAsReq(decodedPaPkAsReq);
-    }
-
-    private void testPaPkAsReq(PaPkAsReq paPkAsReq) throws IOException {
-        SignedContentInfo contentInfo = new SignedContentInfo();
-        Asn1.parseAndDump(paPkAsReq.getSignedAuthPack());
-        contentInfo.decode(paPkAsReq.getSignedAuthPack());
-        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.2");
-        Asn1.dump(contentInfo);
-
-        SignedData signedData = contentInfo.getSignedData();
-        assertThat(signedData.getVersion()).isEqualTo(3);
-        assertThat(signedData.getDigestAlgorithms().getElements().isEmpty()).isTrue();
-        assertThat(signedData.getCertificates().getElements().isEmpty()).isTrue();
-        assertThat(signedData.getCrls().getElements().isEmpty()).isTrue();
-        assertThat(signedData.getSignerInfos().getElements().isEmpty()).isTrue();
-        assertThat(signedData.getEncapContentInfo().getContentType())
-                .isEqualTo("1.3.6.1.5.2.3.1");
-
-        AuthPack authPack = new AuthPack();
-        Asn1.parseAndDump(signedData.getEncapContentInfo().getContent());
-        authPack.decode(signedData.getEncapContentInfo().getContent());
-        assertThat(authPack.getsupportedCmsTypes().getElements().size()).isEqualTo(1);
-        assertThat(authPack.getsupportedCmsTypes().getElements().get(0).getAlgorithm())
-                .isEqualTo("1.2.840.113549.3.7");
-        SubjectPublicKeyInfo subjectPublicKeyInfo = authPack.getClientPublicValue();
-        assertThat(subjectPublicKeyInfo.getAlgorithm().getAlgorithm())
-                .isEqualTo("1.2.840.10046.2.1");
-        DhParameter dhParameter =
-            subjectPublicKeyInfo.getAlgorithm().getParametersAs(DhParameter.class);
-        assertThat(dhParameter.getG()).isEqualTo(BigInteger.valueOf(2));
-
-        assertThat(authPack.getsupportedKDFs().getElements().size()).isEqualTo(3);
-
-        assertThat(authPack.getsupportedKDFs().getElements().get(0).getKdfId())
-                .isEqualTo("1.3.6.1.5.2.3.6.2");
-        assertThat(authPack.getsupportedKDFs().getElements().get(1).getKdfId())
-                .isEqualTo("1.3.6.1.5.2.3.6.1");
-        assertThat(authPack.getsupportedKDFs().getElements().get(2).getKdfId())
-                .isEqualTo("1.3.6.1.5.2.3.6.3");
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsRepCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsRepCodec.java b/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsRepCodec.java
deleted file mode 100644
index 9e96cef..0000000
--- a/kerby-kerb/kerb-core/src/test/java/org/apache/kerby/kerberos/kerb/codec/TestPkinitRsaAsRepCodec.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.kerberos.kerb.codec;
-
-import org.apache.kerby.asn1.Asn1;
-import org.apache.kerby.cms.type.ContentInfo;
-import org.apache.kerby.cms.type.EnvelopedData;
-import org.apache.kerby.kerberos.kerb.type.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.type.kdc.AsRep;
-import org.apache.kerby.kerberos.kerb.type.pa.PaData;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
-import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
-import org.apache.kerby.kerberos.kerb.type.pa.pkinit.PaPkAsRep;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import static org.assertj.core.api.Assertions.*;
-
-public class TestPkinitRsaAsRepCodec {
-    @Test
-    public void test() throws IOException {
-        byte[] bytes = CodecTestUtil.readDataFile("/pkinit_rsa_asrep.token");
-        ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
-
-        AsRep asRep = new AsRep();
-        asRep.decode(asRepToken);
-
-        assertThat(asRep.getPvno()).isEqualTo(5);
-        assertThat(asRep.getMsgType()).isEqualTo(KrbMessageType.AS_REP);
-        PaData paData = asRep.getPaData();
-
-        PaDataEntry pkAsRepEntry = paData.findEntry(PaDataType.PK_AS_REP);
-        assertThat(pkAsRepEntry.getPaDataType()).isEqualTo(PaDataType.PK_AS_REP);
-
-        PaPkAsRep paPkAsRep = new PaPkAsRep();
-        byte[] padataValue = pkAsRepEntry.getPaDataValue();
-        paPkAsRep.decode(padataValue);
-
-        assertThat(paPkAsRep.getEncKeyPack()).isNotNull();
-
-        byte[] encKeyPack = paPkAsRep.getEncKeyPack();
-        Asn1.parseAndDump(encKeyPack);
-        ContentInfo contentInfo = new ContentInfo();
-        contentInfo.decode(encKeyPack);
-        assertThat(contentInfo.getContentType()).isEqualTo("1.2.840.113549.1.7.3");
-        EnvelopedData envelopedData = contentInfo.getContentAs(EnvelopedData.class);
-        Asn1.dump(envelopedData);
-    }
-}


[4/4] directory-kerby git commit: DIRKRB-519 Check all the tests to use the NameTest format.

Posted by pl...@apache.org.
DIRKRB-519 Check all the tests to use the NameTest format.


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

Branch: refs/heads/trunk
Commit: d06becfd72909a224c065197cf947f8f87917d2d
Parents: e0ce27d
Author: plusplusjiajia <ji...@intel.com>
Authored: Thu Dec 31 11:19:34 2015 +0800
Committer: plusplusjiajia <ji...@intel.com>
Committed: Thu Dec 31 11:19:34 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/asn1/Asn1BooleanTest.java  |  70 +++++++
 .../apache/kerby/asn1/Asn1CollectionTest.java   |  60 ++++++
 .../asn1/Asn1ConstructedOctetStringTest.java    |  36 ++++
 .../org/apache/kerby/asn1/Asn1DumpTest.java     |  95 +++++++++
 .../org/apache/kerby/asn1/Asn1FlagsTest.java    | 158 ++++++++++++++
 .../org/apache/kerby/asn1/Asn1IntegerTest.java  |  72 +++++++
 .../kerby/asn1/Asn1ObjectIdentifierTest.java    |  66 ++++++
 .../org/apache/kerby/asn1/Asn1UtcTimeTest.java  |  72 +++++++
 .../java/org/apache/kerby/asn1/DataTest.java    | 127 ++++++++++++
 .../apache/kerby/asn1/PersonnelRecordTest.java  | 121 +++++++++++
 .../apache/kerby/asn1/TaggingEncodingTest.java  | 205 +++++++++++++++++++
 .../org/apache/kerby/asn1/TestAsn1Boolean.java  |  70 -------
 .../apache/kerby/asn1/TestAsn1Collection.java   |  60 ------
 .../asn1/TestAsn1ConstructedOctetString.java    |  36 ----
 .../org/apache/kerby/asn1/TestAsn1Dump.java     |  95 ---------
 .../org/apache/kerby/asn1/TestAsn1Flags.java    | 158 --------------
 .../org/apache/kerby/asn1/TestAsn1Integer.java  |  72 -------
 .../kerby/asn1/TestAsn1ObjectIdentifier.java    |  66 ------
 .../org/apache/kerby/asn1/TestAsn1UtcTime.java  |  72 -------
 .../java/org/apache/kerby/asn1/TestData.java    | 127 ------------
 .../apache/kerby/asn1/TestPersonnelRecord.java  | 121 -----------
 .../apache/kerby/asn1/TestTaggingEncoding.java  | 205 -------------------
 .../kerb/client/KrbClientSettingTest.java       |   2 +-
 .../client/KrbConfigLoadForSpecialsTest.java    |  51 +++++
 .../kerberos/kerb/client/KrbConfigLoadTest.java |  65 ++++++
 .../kerberos/kerb/client/TestKrbConfigLoad.java |  65 ------
 .../client/TestKrbConfigLoadForSpecials.java    |  51 -----
 .../kerberos/kerb/codec/AsRepCodecTest.java     |  72 +++++++
 .../kerberos/kerb/codec/AsReqCodecTest.java     | 104 ++++++++++
 .../kerberos/kerb/codec/PaPkAsRepTest.java      |  45 ++++
 .../codec/PkinitAnonymousAsRepCodecTest.java    | 123 +++++++++++
 .../codec/PkinitAnonymousAsReqCodecTest.java    | 151 ++++++++++++++
 .../kerb/codec/PkinitRsaAsRepCodecTest.java     |  68 ++++++
 .../kerb/codec/PkinitRsaAsReqCodecTest.java     | 112 ++++++++++
 .../kerberos/kerb/codec/TestAsRepCodec.java     |  72 -------
 .../kerberos/kerb/codec/TestAsReqCodec.java     | 104 ----------
 .../kerberos/kerb/codec/TestPaPkAsRep.java      |  45 ----
 .../codec/TestPkinitAnonymousAsRepCodec.java    | 123 -----------
 .../codec/TestPkinitAnonymousAsReqCodec.java    | 151 --------------
 .../kerb/codec/TestPkinitRsaAsRepCodec.java     |  68 ------
 .../kerb/codec/TestPkinitRsaAsReqCodec.java     | 112 ----------
 .../kerberos/kerb/codec/TestTgsRepCodec.java    |  68 ------
 .../kerberos/kerb/codec/TestTgsReqCodec.java    |  92 ---------
 .../kerberos/kerb/codec/TgsRepCodecTest.java    |  68 ++++++
 .../kerberos/kerb/codec/TgsReqCodecTest.java    |  92 +++++++++
 .../kerberos/kerb/server/KdcConfigLoadTest.java |  73 +++++++
 .../kerberos/kerb/server/TestKdcConfigLoad.java |  73 -------
 .../apache/commons/ssl/CertificatesTest.java    |  84 ++++++++
 .../org/apache/commons/ssl/KeyMaterialTest.java |  77 +++++++
 .../org/apache/commons/ssl/OpenSSLTest.java     | 166 +++++++++++++++
 .../org/apache/commons/ssl/PKCS8KeyTest.java    |  61 ++++++
 .../apache/commons/ssl/TestCertificates.java    |  84 --------
 .../org/apache/commons/ssl/TestKeyMaterial.java |  77 -------
 .../org/apache/commons/ssl/TestOpenSSL.java     | 166 ---------------
 .../org/apache/commons/ssl/TestPKCS8Key.java    |  61 ------
 .../apache/commons/ssl/TestTrustMaterial.java   |  67 ------
 .../apache/commons/ssl/TrustMaterialTest.java   |  67 ++++++
 .../org/apache/kerby/cms/CertificateTest.java   |  76 +++++++
 .../apache/kerby/cms/CompressedDataTest.java    |  49 +++++
 .../org/apache/kerby/cms/EnvelopedDataTest.java |  86 ++++++++
 .../org/apache/kerby/cms/ExtensionTest.java     |  54 +++++
 .../org/apache/kerby/cms/GeneralNameTest.java   |  50 +++++
 .../org/apache/kerby/cms/SignedDataTest.java    | 111 ++++++++++
 .../org/apache/kerby/cms/TestCertificate.java   |  76 -------
 .../apache/kerby/cms/TestCompressedData.java    |  49 -----
 .../org/apache/kerby/cms/TestEnvelopedData.java |  86 --------
 .../org/apache/kerby/cms/TestExtension.java     |  54 -----
 .../org/apache/kerby/cms/TestGeneralName.java   |  50 -----
 .../org/apache/kerby/cms/TestSignedData.java    | 111 ----------
 .../java/org/apache/kerby/util/Base64Test.java  |  90 ++++++++
 .../apache/kerby/util/IPAddressParserTest.java  |  80 ++++++++
 .../java/org/apache/kerby/util/TestBase64.java  |  90 --------
 .../apache/kerby/util/TestIPAddressParser.java  |  80 --------
 73 files changed, 3158 insertions(+), 3158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java
new file mode 100644
index 0000000..5557975
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java
@@ -0,0 +1,70 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Boolean;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1BooleanTest {
+
+    @Test
+    public void testEncoding() throws IOException {
+        testEncodingWith(true, "0x01 01 FF", true);
+        testEncodingWith(false, "0x01 01 00", true);
+    }
+
+    private void testEncodingWith(Boolean value, String expectedEncoding,
+                                  boolean isDer) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1Boolean aValue = new Asn1Boolean(value);
+        if (isDer) {
+            aValue.useDER();
+        } else {
+            aValue.useBER();
+        }
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws IOException {
+        testDecodingWith(true, "0x01 01 FF", true);
+        testDecodingWith(false, "0x01 01 7F", true);
+        testDecodingWith(true, "0x01 01 7F", false);
+        testDecodingWith(false, "0x01 01 00", true);
+    }
+
+    private void testDecodingWith(Boolean expectedValue, String content,
+                                  boolean isDer) throws IOException {
+        Asn1Boolean decoded = new Asn1Boolean();
+        if (isDer) {
+            decoded.useDER();
+        } else {
+            decoded.useBER();
+        }
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java
new file mode 100644
index 0000000..50d51af
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java
@@ -0,0 +1,60 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Boolean;
+import org.apache.kerby.asn1.type.Asn1IA5String;
+import org.apache.kerby.asn1.type.Asn1Sequence;
+import org.apache.kerby.asn1.type.Asn1String;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1CollectionTest {
+    static final String TEST_STR = "Jones";
+    static final Boolean TEST_BOOL = true;
+    static final byte[] EXPECTED_BYTES = new byte[] {(byte) 0x30, (byte) 0x0A,
+            (byte) 0x16, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73, (byte) 0x01, (byte) 0x01, (byte) 0xFF
+    };
+
+    @Test
+    public void testSequenceEncoding() throws IOException {
+        Asn1Sequence seq = new Asn1Sequence();
+        seq.addItem(new Asn1IA5String(TEST_STR));
+        seq.addItem(new Asn1Boolean(TEST_BOOL));
+
+        assertThat(seq.encode()).isEqualTo(EXPECTED_BYTES);
+    }
+
+    @Test
+    public void testSequenceDecoding() throws IOException {
+        Asn1Sequence seq = new Asn1Sequence();
+        seq.decode(EXPECTED_BYTES);
+        Asn1String field =
+            (Asn1String) seq.getValue().get(0);
+        assertThat(field.getValue()).isEqualTo(TEST_STR);
+
+        Asn1Boolean field2 = (Asn1Boolean) seq.getValue().get(1);
+        assertThat(field2.getValue()).isEqualTo(TEST_BOOL);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java
new file mode 100644
index 0000000..7b110a9
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java
@@ -0,0 +1,36 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1OctetString;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class Asn1ConstructedOctetStringTest {
+
+    @Test
+    public void testDecoding() throws IOException {
+        byte[] data = TestUtil.readBytesFromTxtFile("/constructed-octet-string.txt");
+        Asn1OctetString octetString = new Asn1OctetString();
+        octetString.decode(data);
+        Asn1.dump(octetString);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java
new file mode 100644
index 0000000..fb83fc0
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java
@@ -0,0 +1,95 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class Asn1DumpTest {
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithPersonnelRecord() throws IOException {
+        try {
+            PersonnelRecord pr = DataTest.createSamplePersonnel();
+            Asn1.dump(pr);
+
+            byte[] data = DataTest.createSammplePersonnelEncodingData();
+            Asn1.parseAndDump(data);
+            Asn1.decodeAndDump(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithCompressedData() throws IOException {
+        String hexStr = TestUtil.readStringFromTxtFile("/compressed-data.txt");
+        try {
+            Asn1.parseAndDump(hexStr);
+            Asn1.decodeAndDump(hexStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithSignedData() throws IOException {
+        String hexStr = TestUtil.readStringFromTxtFile("/signed-data.txt");
+        try {
+            Asn1.parseAndDump(hexStr);
+            Asn1.decodeAndDump(hexStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithDerData() throws IOException {
+        byte[] data = TestUtil.readBytesFromBinFile("/der-data.dat");
+        try {
+            Asn1.parseAndDump(data);
+            Asn1.decodeAndDump(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testDumpWithEmptyContainer() throws IOException {
+        byte[] data = TestUtil.readBytesFromTxtFile("/empty-container.txt");
+        try {
+            Asn1.parseAndDump(data);
+            Asn1.decodeAndDump(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java
new file mode 100644
index 0000000..3182811
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java
@@ -0,0 +1,158 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Flags;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class Asn1FlagsTest {
+  
+  public static final int FLAG_0 = 0b00000000000000000000000000000001;
+  public static final int FLAG_1 = 0b00000000000000000000000000000010;
+  public static final int FLAG_2 = 0x00000004;
+  public static final int FLAG_3 = 0x00000008;
+  public static final int FLAG_4 = 16;
+  public static final int FLAG_5 = 32;
+  
+  public enum TestEnum implements EnumType {
+    FLAG_0(0x00000001),
+    FLAG_1(0x00000002),
+    FLAG_2(0x00000004),
+    FLAG_3(0x00000008),
+    FLAG_4(0x00000010),
+    FLAG_5(0x00000020);
+    
+    private int value;
+    
+    private TestEnum(int value) {
+      this.value = value;
+    }
+
+    @Override
+    public int getValue() {
+      return value;
+    }
+
+
+    @Override
+    public String getName() {
+      return name();
+    }
+  }
+  
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+  
+  private Asn1Flags flags;
+  
+  @Before
+  public void setUp() {
+    flags = new Asn1Flags(FLAG_5 | FLAG_3 | FLAG_1);
+  }
+
+  @Test
+  public void testToValue() throws IOException {
+    byte[] value = {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF};
+    flags.setValue(value);
+    assertEquals(0b11011110101011011011111011101111, flags.getFlags());
+  }
+
+  @Test
+  public void testFlags() {
+    flags = new Asn1Flags();
+    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
+  }
+
+  @Test
+  public void testFlagsInt() {
+    flags = new Asn1Flags(FLAG_4 | FLAG_2 | FLAG_0);
+    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
+  }
+
+  @Test
+  public void testSetFlags() {
+    flags.setFlags(FLAG_4 | FLAG_2 | FLAG_0);
+    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
+  }
+
+  @Test
+  public void testGetFlags() {
+    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
+  }
+
+  @Test
+  public void testIsFlagSetInt() {
+    assertTrue(flags.isFlagSet(FLAG_5));
+    assertFalse(flags.isFlagSet(FLAG_4));
+  }
+
+  @Test
+  public void testSetFlagInt() {
+    flags.setFlag(FLAG_4);
+    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
+  }
+
+  @Test
+  public void testClearFlagInt() {
+    flags.clearFlag(FLAG_3);
+    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
+  }
+
+  @Test
+  public void testClear() {
+    flags.clear();
+    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
+  }
+
+  @Test
+  public void testIsFlagSetEnum() {
+    assertTrue(flags.isFlagSet(TestEnum.FLAG_5));
+    assertFalse(flags.isFlagSet(TestEnum.FLAG_4));
+  }
+
+  @Test
+  public void testSetFlagEnum() {
+    flags.setFlag(TestEnum.FLAG_4);
+    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
+  }
+
+  @Test
+  public void testSetFlagEnumBoolean() {
+    flags.setFlag(TestEnum.FLAG_4, true);
+    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
+    flags.setFlag(TestEnum.FLAG_4, false);
+    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
+  }
+
+  @Test
+  public void testClearFlagEnum() {
+    flags.clearFlag(TestEnum.FLAG_3);
+    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
+  }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java
new file mode 100644
index 0000000..04bb11f
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java
@@ -0,0 +1,72 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Integer;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1IntegerTest {
+
+    @Test
+    public void testEncoding() throws IOException {
+        testEncodingWith(0, "0x02 01 00");
+        testEncodingWith(1, "0x02 01 01");
+        testEncodingWith(2, "0x02 01 02");
+        testEncodingWith(127, "0x02 01 7F");
+        testEncodingWith(128, "0x02 02 00 80");
+        testEncodingWith(-1, "0x02 01 FF");
+        testEncodingWith(-128, "0x02 01 80");
+        testEncodingWith(-32768, "0x02 02 80 00");
+        testEncodingWith(1234567890, "0x02 04 49 96 02 D2");
+    }
+
+    private void testEncodingWith(int value, String expectedEncoding) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1Integer aValue = new Asn1Integer(value);
+        aValue.useDER();
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws IOException {
+        testDecodingWith(0, "0x02 01 00");
+        testDecodingWith(1, "0x02 01 01");
+        testDecodingWith(2, "0x02 01 02");
+        testDecodingWith(127, "0x02 01 7F");
+        testDecodingWith(128, "0x02 02 00 80");
+        testDecodingWith(-1, "0x02 01 FF");
+        testDecodingWith(-128, "0x02 01 80");
+        testDecodingWith(-32768, "0x02 02 80 00");
+        testDecodingWith(1234567890, "0x02 04 49 96 02 D2");
+    }
+
+    private void testDecodingWith(int expectedValue, String content) throws IOException {
+        Asn1Integer decoded = new Asn1Integer();
+        decoded.useDER();
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue().intValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java
new file mode 100644
index 0000000..9106dc7
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java
@@ -0,0 +1,66 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1ObjectIdentifierTest {
+
+    @Test
+    public void testEncoding() throws Exception {
+        /**
+         * Cryptography for Developers -> ASN.1 UTCTIME Type
+         * Applying this to the MD5 OID, we first transform the dotted decimal form into the
+         * array of words.Thus, 1.2.840.113549.2.5 becomes {42, 840, 113549, 2, 5}, and then further
+         * 404_CRYPTO_02.qxd 10/27/06 3:40 PM Page 36split into seven-bit digits with the proper most significant bits as
+         * {{0x2A}, {0x86, 0x48},{0x86, 0xF7, 0x0D}, {0x02}, {0x05}}.Therefore, the full encoding for MD5 is 0x06 08 2A
+         * 86 48 86 F7 0D 02 05.
+         */
+        testEncodingWith("1.2.840.113549.2.5",
+                "0x06 08 2A 86 48 86 F7 0D 02 05");
+    }
+
+    private void testEncodingWith(String oid, String expectedEncoding) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1ObjectIdentifier aValue = new Asn1ObjectIdentifier(oid);
+        aValue.useDER();
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws Exception {
+        testDecodingWith("1.2.840.113549.2.5",
+                "0x06 08 2A 86 48 86 F7 0D 02 05");
+    }
+
+    private void testDecodingWith(String expectedValue, String content) throws IOException {
+        Asn1ObjectIdentifier decoded = new Asn1ObjectIdentifier();
+        decoded.useDER();
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java
new file mode 100644
index 0000000..271abff
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java
@@ -0,0 +1,72 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1UtcTime;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.SimpleTimeZone;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1UtcTimeTest {
+
+    @Test
+    public void testEncoding() throws Exception {
+        /**
+         * Cryptography for Developers -> ASN.1 UTCTIME Type
+         * the encoding of July 4, 2003 at 11:33 and 28 seconds would be
+         “030704113328Z” and be encoded as 0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A.
+         */
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
+        String dateInString = "2003-07-04 11:33:28";
+        Date date = sdf.parse(dateInString);
+        testEncodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
+    }
+
+    private void testEncodingWith(Date value, String expectedEncoding) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1UtcTime aValue = new Asn1UtcTime(value);
+        aValue.useDER();
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws Exception {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String dateInString = "2003-07-04 11:33:28";
+        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
+        Date date = sdf.parse(dateInString);
+        testDecodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
+    }
+
+    private void testDecodingWith(Date expectedValue, String content) throws IOException {
+        Asn1UtcTime decoded = new Asn1UtcTime();
+        decoded.useDER();
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java
new file mode 100644
index 0000000..4e5c0a5
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java
@@ -0,0 +1,127 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+
+public class DataTest {
+
+    public static PersonnelRecord createSamplePersonnel() {
+        PersonnelRecord pr = new PersonnelRecord();
+
+        pr.setName(new PersonnelRecord.Name("John", "P", "Smith"));
+
+        pr.setTitle("Director");
+
+        pr.setEmployeeNumber(new PersonnelRecord.EmployeeNumber(51));
+
+        pr.setDateOfHire(new PersonnelRecord.Date("19710917"));
+
+        pr.setNameOfSpouse(new PersonnelRecord.Name("Mary", "T", "Smith"));
+
+        PersonnelRecord.ChildInformation child1 = new PersonnelRecord.ChildInformation();
+        child1.setName(new PersonnelRecord.Name("Ralph", "T", "Smith"));
+        child1.setDateOfBirth(new PersonnelRecord.Date("19571111"));
+
+        PersonnelRecord.ChildInformation child2 = new PersonnelRecord.ChildInformation();
+        child2.setName(new PersonnelRecord.Name("Susan", "B", "Jones"));
+        child2.setDateOfBirth(new PersonnelRecord.Date("19590717"));
+
+        pr.setChildren(new PersonnelRecord.Children(child1, child2));
+
+        return pr;
+    }
+
+    public static byte[] createSammplePersonnelEncodingData() {
+        class BufferOutput {
+            ByteBuffer buffer;
+
+            void put(byte ... bytes) {
+                buffer.put(bytes);
+            }
+
+            void put(String s) {
+                byte[] bytes = s.getBytes(StandardCharsets.US_ASCII);
+                buffer.put(bytes);
+            }
+
+            public byte[] output() {
+                int len = (int) 0x85 + 3;
+                buffer = ByteBuffer.allocate(len);
+
+                // personnel record
+                put((byte) 0x60, (byte) 0x81, (byte) 0x85);
+
+                // -name
+                put((byte) 0x61, (byte) 0x10);
+                put((byte) 0x1A, (byte) 0x04); put("John");
+                put((byte) 0x1A, (byte) 0x01); put("P");
+                put((byte) 0x1A, (byte) 0x05); put("Smith");
+
+                //-title
+                put((byte) 0xA0, (byte) 0x0A);
+                put((byte) 0x1A, (byte) 0x08); put("Director");
+
+                //-employee number
+                put((byte) 0x42, (byte) 0x01, (byte) 0x33);
+
+                //-date of hire
+                put((byte) 0xA1, (byte) 0x0A);
+                put((byte) 0x43, (byte) 0x08); put("19710917");
+
+                //-spouse
+                put((byte) 0xA2, (byte) 0x12);
+                put((byte) 0x61, (byte) 0x10);
+                put((byte) 0x1A, (byte) 0x04); put("Mary");
+                put((byte) 0x1A, (byte) 0x01); put("T");
+                put((byte) 0x1A, (byte) 0x05); put("Smith");
+
+                //-children
+                put((byte) 0xA3, (byte) 0x42);
+                //--child 1
+                put((byte) 0x31, (byte) 0x1F);
+                //---name
+                put((byte) 0x61, (byte) 0x11);
+                put((byte) 0x1A, (byte) 0x05); put("Ralph");
+                put((byte) 0x1A, (byte) 0x01); put("T");
+                put((byte) 0x1A, (byte) 0x05); put("Smith");
+                //-date of birth
+                put((byte) 0xA0, (byte) 0x0A);
+                put((byte) 0x43, (byte) 0x08); put("19571111");
+                //--child 2
+                put((byte) 0x31, (byte) 0x1F);
+                //---name
+                put((byte) 0x61, (byte) 0x11);
+                put((byte) 0x1A, (byte) 0x05); put("Susan");
+                put((byte) 0x1A, (byte) 0x01); put("B");
+                put((byte) 0x1A, (byte) 0x05); put("Jones");
+                //-date of birth
+                put((byte) 0xA0, (byte) 0x0A);
+                put((byte) 0x43, (byte) 0x08); put("19590717");
+
+                return buffer.array();
+            }
+        }
+
+        BufferOutput buffer = new BufferOutput();
+        return buffer.output();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java
new file mode 100644
index 0000000..514b82b
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java
@@ -0,0 +1,121 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Ref. X.690-0207(http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf),
+ * Annex A, A.1 ASN.1 description of the record structure
+ */
+public class PersonnelRecordTest {
+
+    static boolean verbose = false;
+
+    @Test
+    public void testEncoding() throws IOException {
+        PersonnelRecord pr = DataTest.createSamplePersonnel();
+
+        if (verbose) {
+            System.out.println("Name:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getName().encode()));
+
+            System.out.println("DateOfHire:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getDateOfHire().encode()));
+
+            System.out.println("SpouseName:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getNameOfSpouse().encode()));
+
+            System.out.println("Child1:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(0).encode()));
+
+            System.out.println("Child2:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(1).encode()));
+
+            System.out.println("Children:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().encode()));
+        }
+
+        byte[] data = DataTest.createSammplePersonnelEncodingData();
+        byte[] encoded = pr.encode();
+
+        if (verbose) {
+            System.out.println("ExpectedData:");
+            System.out.println(HexUtil.bytesToHexFriendly(data));
+
+            System.out.println("Encoded:");
+            System.out.println(HexUtil.bytesToHexFriendly(encoded));
+        }
+
+        assertThat(encoded).isEqualTo(data);
+    }
+
+    @Test
+    public void testDecoding() throws IOException {
+        PersonnelRecord expected = DataTest.createSamplePersonnel();
+        byte[] data = DataTest.createSammplePersonnelEncodingData();
+        Asn1.parseAndDump(data);
+        PersonnelRecord decoded = new PersonnelRecord();
+        decoded.decode(data);
+        Asn1.dump(decoded);
+
+        assertThat(decoded.getName().getGivenName())
+                .isEqualTo(expected.getName().getGivenName());
+        assertThat(decoded.getName().getInitial())
+                .isEqualTo(expected.getName().getInitial());
+        assertThat(decoded.getName().getFamilyName())
+                .isEqualTo(expected.getName().getFamilyName());
+        assertThat(decoded.getDateOfHire().getValue().getValue())
+                .isEqualTo(expected.getDateOfHire().getValue().getValue());
+        assertThat(decoded.getTitle())
+                .isEqualTo(expected.getTitle());
+        assertThat(decoded.getEmployeeNumber().getValue().getValue())
+                .isEqualTo(expected.getEmployeeNumber().getValue().getValue());
+        assertThat(decoded.getNameOfSpouse().getGivenName())
+                .isEqualTo(expected.getNameOfSpouse().getGivenName());
+        assertThat(decoded.getNameOfSpouse().getInitial())
+                .isEqualTo(expected.getNameOfSpouse().getInitial());
+        assertThat(decoded.getNameOfSpouse().getFamilyName())
+                .isEqualTo(expected.getNameOfSpouse().getFamilyName());
+        assertThat(decoded.getChildren().getElements().size())
+            .isEqualTo(expected.getChildren().getElements().size());
+        assertThat(decoded.getChildren().getElements().get(0).getName().getGivenName())
+                .isEqualTo(expected.getChildren().getElements().get(0).getName().getGivenName());
+        assertThat(decoded.getChildren().getElements().get(0).getName().getInitial())
+                .isEqualTo(expected.getChildren().getElements().get(0).getName().getInitial());
+        assertThat(decoded.getChildren().getElements().get(0).getName().getFamilyName())
+                .isEqualTo(expected.getChildren().getElements().get(0).getName().getFamilyName());
+        assertThat(decoded.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue())
+                .isEqualTo(expected.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue());
+        assertThat(decoded.getChildren().getElements().get(1).getName().getGivenName())
+                .isEqualTo(expected.getChildren().getElements().get(1).getName().getGivenName());
+        assertThat(decoded.getChildren().getElements().get(1).getName().getInitial())
+                .isEqualTo(expected.getChildren().getElements().get(1).getName().getInitial());
+        assertThat(decoded.getChildren().getElements().get(1).getName().getFamilyName())
+                .isEqualTo(expected.getChildren().getElements().get(1).getName().getFamilyName());
+        assertThat(decoded.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue())
+                .isEqualTo(expected.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue());
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java
new file mode 100644
index 0000000..ad9be01
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java
@@ -0,0 +1,205 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Tagging;
+import org.apache.kerby.asn1.type.Asn1VisibleString;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ Ref. X.690-0207 8.14 Encoding of a tagged value
+ EXAMPLE
+ With ASN.1 type definitions (in an explicit tagging environment) of:
+ Type1 ::= VisibleString
+ Type2 ::= [APPLICATION 3] IMPLICIT Type1
+ Type3 ::= [2] Type2
+ Type4 ::= [APPLICATION 7] IMPLICIT Type3
+ Type5 ::= [2] IMPLICIT Type2
+ a value of:
+ "Jones"
+ is encoded as follows:
+ For Type1:
+ VisibleString Length Contents
+ 1A16 0516 4A6F6E657316
+ For Type2:
+ [Application 3] Length Contents
+ 4316 0516 4A6F6E657316
+ For Type3:
+ [2] Length Contents
+ A216 0716
+ [APPLICATION 3] Length Contents
+ 4316 0516 4A6F6E657316
+ For Type4:
+ [Application 7] Length Contents
+ 6716 0716
+ [APPLICATION 3] Length Contents
+ 4316 0516 4A6F6E657316
+ For Type5:
+ [2] Length Contents
+ 8216 0516 4A6F6E657316
+ */
+
+public class TaggingEncodingTest {
+    static final String TEST_STRING = "Jones";
+    static final byte[] TYPE1_EXPECTED_BYTES = new byte[] {(byte) 0x1A, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE2_EXPECTED_BYTES = new byte[] {(byte) 0x43, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE3_EXPECTED_BYTES = new byte[] {(byte) 0xA2, (byte) 0x07,
+            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE4_EXPECTED_BYTES = new byte[] {(byte) 0x67, (byte) 0x07,
+            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE5_EXPECTED_BYTES = new byte[] {(byte) 0x82, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+
+
+    public static class Type1 extends Asn1VisibleString {
+        public Type1(String value) {
+            super(value);
+        }
+        public Type1() {
+            this(null);
+        }
+    }
+
+    public static class Type2 extends Asn1Tagging<Type1> {
+        public Type2(Type1 value) {
+            super(3, value, true, true);
+        }
+        public Type2() {
+            this(null);
+        }
+    }
+
+    public static class Type3 extends Asn1Tagging<Type2> {
+        public Type3(Type2 value) {
+            super(2, value, false, false);
+        }
+        public Type3() {
+            this(null);
+        }
+    }
+
+    public static class Type4 extends Asn1Tagging<Type3> {
+        public Type4(Type3 value) {
+            super(7, value, true, true);
+        }
+        public Type4() {
+            this(null);
+        }
+    }
+
+    public static class Type5 extends Asn1Tagging<Type2> {
+        public Type5(Type2 value) {
+            super(2, value, false, true);
+        }
+        public Type5() {
+            this(null);
+        }
+    }
+
+    @Test
+    public void testAsn1TaggingEncoding() throws IOException {
+        Type1 aType1 = new Type1(TEST_STRING);
+        Type2 aType2 = new Type2(aType1);
+        Type3 aType3 = new Type3(aType2);
+        Type4 aType4 = new Type4(aType3);
+        Type5 aType5 = new Type5(aType2);
+
+        assertThat(aType1.encode()).isEqualTo(TYPE1_EXPECTED_BYTES);
+        assertThat(aType2.encode()).isEqualTo(TYPE2_EXPECTED_BYTES);
+        assertThat(aType3.encode()).isEqualTo(TYPE3_EXPECTED_BYTES);
+        assertThat(aType4.encode()).isEqualTo(TYPE4_EXPECTED_BYTES);
+        assertThat(aType5.encode()).isEqualTo(TYPE5_EXPECTED_BYTES);
+    }
+
+    @Test
+    public void testAsn1TaggingDecoding() throws IOException {
+        Type1 aType1 = new Type1();
+        aType1.decode(TYPE1_EXPECTED_BYTES);
+        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
+
+        Type2 aType2 = new Type2();
+        aType2.decode(TYPE2_EXPECTED_BYTES);
+        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
+
+        Type3 aType3 = new Type3();
+        aType3.decode(TYPE3_EXPECTED_BYTES);
+        assertThat(aType3.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+
+        Type4 aType4 = new Type4();
+        aType4.decode(TYPE4_EXPECTED_BYTES);
+        assertThat(aType4.getValue().getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+
+        Type5 aType5 = new Type5();
+        aType5.decode(TYPE5_EXPECTED_BYTES);
+        assertThat(aType5.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+    }
+
+    @Test
+    public void testTaggingEncodingOption() throws IOException {
+        Type1 aType1 = new Type1(TEST_STRING);
+        Type2 aType2 = new Type2(aType1);
+        Type3 aType3 = new Type3(aType2);
+
+        assertThat(aType1.encode()).isEqualTo(TYPE1_EXPECTED_BYTES);
+        assertThat(TYPE2_EXPECTED_BYTES)
+                .isEqualTo(aType1.taggedEncode(TaggingOption.newImplicitAppSpecific(3))); // for Type2
+        assertThat(TYPE3_EXPECTED_BYTES)
+                .isEqualTo(aType2.taggedEncode(TaggingOption.newExplicitContextSpecific(2))); // for Type3
+        assertThat(TYPE4_EXPECTED_BYTES)
+                .isEqualTo(aType3.taggedEncode(TaggingOption.newImplicitAppSpecific(7))); // for Type4
+        assertThat(TYPE5_EXPECTED_BYTES)
+                .isEqualTo(aType2.taggedEncode(TaggingOption.newImplicitContextSpecific(2))); // for Type5
+    }
+
+    @Test
+    public void testTaggingDecodingOption() throws IOException {
+        Type1 aType1 = new Type1();
+        aType1.decode(TYPE1_EXPECTED_BYTES);
+        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
+
+        // for Type2
+        aType1 = new Type1();
+        aType1.taggedDecode(TYPE2_EXPECTED_BYTES, TaggingOption.newImplicitAppSpecific(3));
+        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
+
+        // for Type3
+        Type2 aType2 = new Type2();
+        aType2.taggedDecode(TYPE3_EXPECTED_BYTES, TaggingOption.newExplicitContextSpecific(2));
+        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
+
+        // for Type4
+        Type3 aType3 = new Type3();
+        aType3.taggedDecode(TYPE4_EXPECTED_BYTES, TaggingOption.newImplicitAppSpecific(7));
+        assertThat(aType3.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+
+        // for Type5
+        aType2 = new Type2();
+        aType2.taggedDecode(TYPE5_EXPECTED_BYTES, TaggingOption.newImplicitContextSpecific(2));
+        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
deleted file mode 100644
index 22dd8a0..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Boolean;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1Boolean {
-
-    @Test
-    public void testEncoding() throws IOException {
-        testEncodingWith(true, "0x01 01 FF", true);
-        testEncodingWith(false, "0x01 01 00", true);
-    }
-
-    private void testEncodingWith(Boolean value, String expectedEncoding,
-                                  boolean isDer) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1Boolean aValue = new Asn1Boolean(value);
-        if (isDer) {
-            aValue.useDER();
-        } else {
-            aValue.useBER();
-        }
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws IOException {
-        testDecodingWith(true, "0x01 01 FF", true);
-        testDecodingWith(false, "0x01 01 7F", true);
-        testDecodingWith(true, "0x01 01 7F", false);
-        testDecodingWith(false, "0x01 01 00", true);
-    }
-
-    private void testDecodingWith(Boolean expectedValue, String content,
-                                  boolean isDer) throws IOException {
-        Asn1Boolean decoded = new Asn1Boolean();
-        if (isDer) {
-            decoded.useDER();
-        } else {
-            decoded.useBER();
-        }
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java
deleted file mode 100644
index ffa4a95..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Boolean;
-import org.apache.kerby.asn1.type.Asn1IA5String;
-import org.apache.kerby.asn1.type.Asn1Sequence;
-import org.apache.kerby.asn1.type.Asn1String;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1Collection {
-    static final String TEST_STR = "Jones";
-    static final Boolean TEST_BOOL = true;
-    static final byte[] EXPECTED_BYTES = new byte[] {(byte) 0x30, (byte) 0x0A,
-            (byte) 0x16, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
-            (byte) 0x65, (byte) 0x73, (byte) 0x01, (byte) 0x01, (byte) 0xFF
-    };
-
-    @Test
-    public void testSequenceEncoding() throws IOException {
-        Asn1Sequence seq = new Asn1Sequence();
-        seq.addItem(new Asn1IA5String(TEST_STR));
-        seq.addItem(new Asn1Boolean(TEST_BOOL));
-
-        assertThat(seq.encode()).isEqualTo(EXPECTED_BYTES);
-    }
-
-    @Test
-    public void testSequenceDecoding() throws IOException {
-        Asn1Sequence seq = new Asn1Sequence();
-        seq.decode(EXPECTED_BYTES);
-        Asn1String field =
-            (Asn1String) seq.getValue().get(0);
-        assertThat(field.getValue()).isEqualTo(TEST_STR);
-
-        Asn1Boolean field2 = (Asn1Boolean) seq.getValue().get(1);
-        assertThat(field2.getValue()).isEqualTo(TEST_BOOL);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java
deleted file mode 100644
index e7b40be..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1OctetString;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestAsn1ConstructedOctetString {
-
-    @Test
-    public void testDecoding() throws IOException {
-        byte[] data = TestUtil.readBytesFromTxtFile("/constructed-octet-string.txt");
-        Asn1OctetString octetString = new Asn1OctetString();
-        octetString.decode(data);
-        Asn1.dump(octetString);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java
deleted file mode 100644
index 04c0de3..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestAsn1Dump {
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithPersonnelRecord() throws IOException {
-        try {
-            PersonnelRecord pr = TestData.createSamplePersonnel();
-            Asn1.dump(pr);
-
-            byte[] data = TestData.createSammplePersonnelEncodingData();
-            Asn1.parseAndDump(data);
-            Asn1.decodeAndDump(data);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithCompressedData() throws IOException {
-        String hexStr = TestUtil.readStringFromTxtFile("/compressed-data.txt");
-        try {
-            Asn1.parseAndDump(hexStr);
-            Asn1.decodeAndDump(hexStr);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithSignedData() throws IOException {
-        String hexStr = TestUtil.readStringFromTxtFile("/signed-data.txt");
-        try {
-            Asn1.parseAndDump(hexStr);
-            Asn1.decodeAndDump(hexStr);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithDerData() throws IOException {
-        byte[] data = TestUtil.readBytesFromBinFile("/der-data.dat");
-        try {
-            Asn1.parseAndDump(data);
-            Asn1.decodeAndDump(data);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testDumpWithEmptyContainer() throws IOException {
-        byte[] data = TestUtil.readBytesFromTxtFile("/empty-container.txt");
-        try {
-            Asn1.parseAndDump(data);
-            Asn1.decodeAndDump(data);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java
deleted file mode 100644
index 8300f6e..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- *
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Flags;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class TestAsn1Flags {
-  
-  public static final int FLAG_0 = 0b00000000000000000000000000000001;
-  public static final int FLAG_1 = 0b00000000000000000000000000000010;
-  public static final int FLAG_2 = 0x00000004;
-  public static final int FLAG_3 = 0x00000008;
-  public static final int FLAG_4 = 16;
-  public static final int FLAG_5 = 32;
-  
-  public enum TestEnum implements EnumType {
-    FLAG_0(0x00000001),
-    FLAG_1(0x00000002),
-    FLAG_2(0x00000004),
-    FLAG_3(0x00000008),
-    FLAG_4(0x00000010),
-    FLAG_5(0x00000020);
-    
-    private int value;
-    
-    private TestEnum(int value) {
-      this.value = value;
-    }
-
-    @Override
-    public int getValue() {
-      return value;
-    }
-
-
-    @Override
-    public String getName() {
-      return name();
-    }
-  }
-  
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-  
-  private Asn1Flags flags;
-  
-  @Before
-  public void setUp() {
-    flags = new Asn1Flags(FLAG_5 | FLAG_3 | FLAG_1);
-  }
-
-  @Test
-  public void testToValue() throws IOException {
-    byte[] value = {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF};
-    flags.setValue(value);
-    assertEquals(0b11011110101011011011111011101111, flags.getFlags());
-  }
-
-  @Test
-  public void testFlags() {
-    flags = new Asn1Flags();
-    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
-  }
-
-  @Test
-  public void testFlagsInt() {
-    flags = new Asn1Flags(FLAG_4 | FLAG_2 | FLAG_0);
-    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
-  }
-
-  @Test
-  public void testSetFlags() {
-    flags.setFlags(FLAG_4 | FLAG_2 | FLAG_0);
-    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
-  }
-
-  @Test
-  public void testGetFlags() {
-    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
-  }
-
-  @Test
-  public void testIsFlagSetInt() {
-    assertTrue(flags.isFlagSet(FLAG_5));
-    assertFalse(flags.isFlagSet(FLAG_4));
-  }
-
-  @Test
-  public void testSetFlagInt() {
-    flags.setFlag(FLAG_4);
-    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
-  }
-
-  @Test
-  public void testClearFlagInt() {
-    flags.clearFlag(FLAG_3);
-    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
-  }
-
-  @Test
-  public void testClear() {
-    flags.clear();
-    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
-  }
-
-  @Test
-  public void testIsFlagSetEnum() {
-    assertTrue(flags.isFlagSet(TestEnum.FLAG_5));
-    assertFalse(flags.isFlagSet(TestEnum.FLAG_4));
-  }
-
-  @Test
-  public void testSetFlagEnum() {
-    flags.setFlag(TestEnum.FLAG_4);
-    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
-  }
-
-  @Test
-  public void testSetFlagEnumBoolean() {
-    flags.setFlag(TestEnum.FLAG_4, true);
-    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
-    flags.setFlag(TestEnum.FLAG_4, false);
-    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
-  }
-
-  @Test
-  public void testClearFlagEnum() {
-    flags.clearFlag(TestEnum.FLAG_3);
-    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
-  }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
deleted file mode 100644
index 16b5852..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Integer;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1Integer {
-
-    @Test
-    public void testEncoding() throws IOException {
-        testEncodingWith(0, "0x02 01 00");
-        testEncodingWith(1, "0x02 01 01");
-        testEncodingWith(2, "0x02 01 02");
-        testEncodingWith(127, "0x02 01 7F");
-        testEncodingWith(128, "0x02 02 00 80");
-        testEncodingWith(-1, "0x02 01 FF");
-        testEncodingWith(-128, "0x02 01 80");
-        testEncodingWith(-32768, "0x02 02 80 00");
-        testEncodingWith(1234567890, "0x02 04 49 96 02 D2");
-    }
-
-    private void testEncodingWith(int value, String expectedEncoding) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1Integer aValue = new Asn1Integer(value);
-        aValue.useDER();
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws IOException {
-        testDecodingWith(0, "0x02 01 00");
-        testDecodingWith(1, "0x02 01 01");
-        testDecodingWith(2, "0x02 01 02");
-        testDecodingWith(127, "0x02 01 7F");
-        testDecodingWith(128, "0x02 02 00 80");
-        testDecodingWith(-1, "0x02 01 FF");
-        testDecodingWith(-128, "0x02 01 80");
-        testDecodingWith(-32768, "0x02 02 80 00");
-        testDecodingWith(1234567890, "0x02 04 49 96 02 D2");
-    }
-
-    private void testDecodingWith(int expectedValue, String content) throws IOException {
-        Asn1Integer decoded = new Asn1Integer();
-        decoded.useDER();
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue().intValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
deleted file mode 100644
index b6b400f..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1ObjectIdentifier {
-
-    @Test
-    public void testEncoding() throws Exception {
-        /**
-         * Cryptography for Developers -> ASN.1 UTCTIME Type
-         * Applying this to the MD5 OID, we first transform the dotted decimal form into the
-         * array of words.Thus, 1.2.840.113549.2.5 becomes {42, 840, 113549, 2, 5}, and then further
-         * 404_CRYPTO_02.qxd 10/27/06 3:40 PM Page 36split into seven-bit digits with the proper most significant bits as
-         * {{0x2A}, {0x86, 0x48},{0x86, 0xF7, 0x0D}, {0x02}, {0x05}}.Therefore, the full encoding for MD5 is 0x06 08 2A
-         * 86 48 86 F7 0D 02 05.
-         */
-        testEncodingWith("1.2.840.113549.2.5",
-                "0x06 08 2A 86 48 86 F7 0D 02 05");
-    }
-
-    private void testEncodingWith(String oid, String expectedEncoding) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1ObjectIdentifier aValue = new Asn1ObjectIdentifier(oid);
-        aValue.useDER();
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws Exception {
-        testDecodingWith("1.2.840.113549.2.5",
-                "0x06 08 2A 86 48 86 F7 0D 02 05");
-    }
-
-    private void testDecodingWith(String expectedValue, String content) throws IOException {
-        Asn1ObjectIdentifier decoded = new Asn1ObjectIdentifier();
-        decoded.useDER();
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
deleted file mode 100644
index 7cfb377..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1UtcTime;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.SimpleTimeZone;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1UtcTime {
-
-    @Test
-    public void testEncoding() throws Exception {
-        /**
-         * Cryptography for Developers -> ASN.1 UTCTIME Type
-         * the encoding of July 4, 2003 at 11:33 and 28 seconds would be
-         “030704113328Z” and be encoded as 0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A.
-         */
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
-        String dateInString = "2003-07-04 11:33:28";
-        Date date = sdf.parse(dateInString);
-        testEncodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
-    }
-
-    private void testEncodingWith(Date value, String expectedEncoding) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1UtcTime aValue = new Asn1UtcTime(value);
-        aValue.useDER();
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws Exception {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        String dateInString = "2003-07-04 11:33:28";
-        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
-        Date date = sdf.parse(dateInString);
-        testDecodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
-    }
-
-    private void testDecodingWith(Date expectedValue, String content) throws IOException {
-        Asn1UtcTime decoded = new Asn1UtcTime();
-        decoded.useDER();
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java
deleted file mode 100644
index 875288a..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.kerby.asn1;
-
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-
-public class TestData {
-
-    public static PersonnelRecord createSamplePersonnel() {
-        PersonnelRecord pr = new PersonnelRecord();
-
-        pr.setName(new PersonnelRecord.Name("John", "P", "Smith"));
-
-        pr.setTitle("Director");
-
-        pr.setEmployeeNumber(new PersonnelRecord.EmployeeNumber(51));
-
-        pr.setDateOfHire(new PersonnelRecord.Date("19710917"));
-
-        pr.setNameOfSpouse(new PersonnelRecord.Name("Mary", "T", "Smith"));
-
-        PersonnelRecord.ChildInformation child1 = new PersonnelRecord.ChildInformation();
-        child1.setName(new PersonnelRecord.Name("Ralph", "T", "Smith"));
-        child1.setDateOfBirth(new PersonnelRecord.Date("19571111"));
-
-        PersonnelRecord.ChildInformation child2 = new PersonnelRecord.ChildInformation();
-        child2.setName(new PersonnelRecord.Name("Susan", "B", "Jones"));
-        child2.setDateOfBirth(new PersonnelRecord.Date("19590717"));
-
-        pr.setChildren(new PersonnelRecord.Children(child1, child2));
-
-        return pr;
-    }
-
-    public static byte[] createSammplePersonnelEncodingData() {
-        class BufferOutput {
-            ByteBuffer buffer;
-
-            void put(byte ... bytes) {
-                buffer.put(bytes);
-            }
-
-            void put(String s) {
-                byte[] bytes = s.getBytes(StandardCharsets.US_ASCII);
-                buffer.put(bytes);
-            }
-
-            public byte[] output() {
-                int len = (int) 0x85 + 3;
-                buffer = ByteBuffer.allocate(len);
-
-                // personnel record
-                put((byte) 0x60, (byte) 0x81, (byte) 0x85);
-
-                // -name
-                put((byte) 0x61, (byte) 0x10);
-                put((byte) 0x1A, (byte) 0x04); put("John");
-                put((byte) 0x1A, (byte) 0x01); put("P");
-                put((byte) 0x1A, (byte) 0x05); put("Smith");
-
-                //-title
-                put((byte) 0xA0, (byte) 0x0A);
-                put((byte) 0x1A, (byte) 0x08); put("Director");
-
-                //-employee number
-                put((byte) 0x42, (byte) 0x01, (byte) 0x33);
-
-                //-date of hire
-                put((byte) 0xA1, (byte) 0x0A);
-                put((byte) 0x43, (byte) 0x08); put("19710917");
-
-                //-spouse
-                put((byte) 0xA2, (byte) 0x12);
-                put((byte) 0x61, (byte) 0x10);
-                put((byte) 0x1A, (byte) 0x04); put("Mary");
-                put((byte) 0x1A, (byte) 0x01); put("T");
-                put((byte) 0x1A, (byte) 0x05); put("Smith");
-
-                //-children
-                put((byte) 0xA3, (byte) 0x42);
-                //--child 1
-                put((byte) 0x31, (byte) 0x1F);
-                //---name
-                put((byte) 0x61, (byte) 0x11);
-                put((byte) 0x1A, (byte) 0x05); put("Ralph");
-                put((byte) 0x1A, (byte) 0x01); put("T");
-                put((byte) 0x1A, (byte) 0x05); put("Smith");
-                //-date of birth
-                put((byte) 0xA0, (byte) 0x0A);
-                put((byte) 0x43, (byte) 0x08); put("19571111");
-                //--child 2
-                put((byte) 0x31, (byte) 0x1F);
-                //---name
-                put((byte) 0x61, (byte) 0x11);
-                put((byte) 0x1A, (byte) 0x05); put("Susan");
-                put((byte) 0x1A, (byte) 0x01); put("B");
-                put((byte) 0x1A, (byte) 0x05); put("Jones");
-                //-date of birth
-                put((byte) 0xA0, (byte) 0x0A);
-                put((byte) 0x43, (byte) 0x08); put("19590717");
-
-                return buffer.array();
-            }
-        }
-
-        BufferOutput buffer = new BufferOutput();
-        return buffer.output();
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java
deleted file mode 100644
index 4dcb5be..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *
- */
-package org.apache.kerby.asn1;
-
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Ref. X.690-0207(http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf),
- * Annex A, A.1 ASN.1 description of the record structure
- */
-public class TestPersonnelRecord {
-
-    static boolean verbose = false;
-
-    @Test
-    public void testEncoding() throws IOException {
-        PersonnelRecord pr = TestData.createSamplePersonnel();
-
-        if (verbose) {
-            System.out.println("Name:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getName().encode()));
-
-            System.out.println("DateOfHire:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getDateOfHire().encode()));
-
-            System.out.println("SpouseName:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getNameOfSpouse().encode()));
-
-            System.out.println("Child1:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(0).encode()));
-
-            System.out.println("Child2:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(1).encode()));
-
-            System.out.println("Children:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().encode()));
-        }
-
-        byte[] data = TestData.createSammplePersonnelEncodingData();
-        byte[] encoded = pr.encode();
-
-        if (verbose) {
-            System.out.println("ExpectedData:");
-            System.out.println(HexUtil.bytesToHexFriendly(data));
-
-            System.out.println("Encoded:");
-            System.out.println(HexUtil.bytesToHexFriendly(encoded));
-        }
-
-        assertThat(encoded).isEqualTo(data);
-    }
-
-    @Test
-    public void testDecoding() throws IOException {
-        PersonnelRecord expected = TestData.createSamplePersonnel();
-        byte[] data = TestData.createSammplePersonnelEncodingData();
-        Asn1.parseAndDump(data);
-        PersonnelRecord decoded = new PersonnelRecord();
-        decoded.decode(data);
-        Asn1.dump(decoded);
-
-        assertThat(decoded.getName().getGivenName())
-                .isEqualTo(expected.getName().getGivenName());
-        assertThat(decoded.getName().getInitial())
-                .isEqualTo(expected.getName().getInitial());
-        assertThat(decoded.getName().getFamilyName())
-                .isEqualTo(expected.getName().getFamilyName());
-        assertThat(decoded.getDateOfHire().getValue().getValue())
-                .isEqualTo(expected.getDateOfHire().getValue().getValue());
-        assertThat(decoded.getTitle())
-                .isEqualTo(expected.getTitle());
-        assertThat(decoded.getEmployeeNumber().getValue().getValue())
-                .isEqualTo(expected.getEmployeeNumber().getValue().getValue());
-        assertThat(decoded.getNameOfSpouse().getGivenName())
-                .isEqualTo(expected.getNameOfSpouse().getGivenName());
-        assertThat(decoded.getNameOfSpouse().getInitial())
-                .isEqualTo(expected.getNameOfSpouse().getInitial());
-        assertThat(decoded.getNameOfSpouse().getFamilyName())
-                .isEqualTo(expected.getNameOfSpouse().getFamilyName());
-        assertThat(decoded.getChildren().getElements().size())
-            .isEqualTo(expected.getChildren().getElements().size());
-        assertThat(decoded.getChildren().getElements().get(0).getName().getGivenName())
-                .isEqualTo(expected.getChildren().getElements().get(0).getName().getGivenName());
-        assertThat(decoded.getChildren().getElements().get(0).getName().getInitial())
-                .isEqualTo(expected.getChildren().getElements().get(0).getName().getInitial());
-        assertThat(decoded.getChildren().getElements().get(0).getName().getFamilyName())
-                .isEqualTo(expected.getChildren().getElements().get(0).getName().getFamilyName());
-        assertThat(decoded.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue())
-                .isEqualTo(expected.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue());
-        assertThat(decoded.getChildren().getElements().get(1).getName().getGivenName())
-                .isEqualTo(expected.getChildren().getElements().get(1).getName().getGivenName());
-        assertThat(decoded.getChildren().getElements().get(1).getName().getInitial())
-                .isEqualTo(expected.getChildren().getElements().get(1).getName().getInitial());
-        assertThat(decoded.getChildren().getElements().get(1).getName().getFamilyName())
-                .isEqualTo(expected.getChildren().getElements().get(1).getName().getFamilyName());
-        assertThat(decoded.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue())
-                .isEqualTo(expected.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue());
-    }
-}