directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [1/2] directory-kerby git commit: Initial codes
Date Fri, 08 Jan 2016 22:43:28 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/kadmin-remote bb9b05bc1 -> a90b4f728


Initial codes


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

Branch: refs/heads/kadmin-remote
Commit: d797a80dab6e91adc545e7070f151c9b570c9bb6
Parents: 63dcb1a
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Sat Jan 9 06:28:58 2016 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Sat Jan 9 06:28:58 2016 +0800

----------------------------------------------------------------------
 kerby-asn1/pom.xml                              |   3 -
 .../java/org/apache/kerby/asn1/EnumType.java    |   2 +-
 kerby-xdr/pom.xml                               |  29 ++
 .../java/org/apache/kerby/xdr/EnumType.java     |  37 +++
 .../java/org/apache/kerby/xdr/XdrDataType.java  |  50 ++++
 .../java/org/apache/kerby/xdr/XdrFieldInfo.java |  45 +++
 .../apache/kerby/xdr/type/AbstractXdrType.java  | 104 +++++++
 .../org/apache/kerby/xdr/type/XdrBoolean.java   |  58 ++++
 .../org/apache/kerby/xdr/type/XdrBytes.java     |  34 +++
 .../org/apache/kerby/xdr/type/XdrInteger.java   |  51 ++++
 .../org/apache/kerby/xdr/type/XdrSimple.java    |  98 +++++++
 .../org/apache/kerby/xdr/type/XdrString.java    | 292 +++++++++++++++++++
 .../apache/kerby/xdr/type/XdrStructType.java    |  40 +++
 .../java/org/apache/kerby/xdr/type/XdrType.java |  62 ++++
 .../java/org/apache/kerby/xdr/util/HexUtil.java | 113 +++++++
 .../java/org/apache/kerby/xdr/util/IOUtil.java  | 109 +++++++
 .../java/org/apache/kerby/xdr/util/Utf8.java    |  34 +++
 .../java/org/apache/kerby/xdr/util/XdrUtil.java |  26 ++
 .../java/org/apache/kerby/xdr/TestUtil.java     |  47 +++
 .../org/apache/kerby/xdr/XdrBooleanTest.java    |  24 ++
 pom.xml                                         |   1 +
 21 files changed, 1255 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-asn1/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-asn1/pom.xml b/kerby-asn1/pom.xml
index b89e06a..72d038f 100644
--- a/kerby-asn1/pom.xml
+++ b/kerby-asn1/pom.xml
@@ -26,7 +26,4 @@
   <name>Kerby ASN1 Project</name>
   <description>Kerby ASN1 Project</description>
 
-  <dependencies>
-  </dependencies>
-
 </project>

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-asn1/src/main/java/org/apache/kerby/asn1/EnumType.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/EnumType.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/EnumType.java
index e0166ec..5b9a65f 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/EnumType.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/EnumType.java
@@ -20,7 +20,7 @@
 package org.apache.kerby.asn1;
 
 /**
- * A helper interface used by Asn1Enumerated.
+ * A helper interface for enum types.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-xdr/pom.xml b/kerby-xdr/pom.xml
new file mode 100644
index 0000000..48cf4ce
--- /dev/null
+++ b/kerby-xdr/pom.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed 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. See accompanying LICENSE file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <parent>
+    <groupId>org.apache.kerby</groupId>
+    <artifactId>kerby-all</artifactId>
+    <version>1.0.0-RC2-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>kerby-xdr</artifactId>
+  <name>Kerby XDR Project</name>
+  <description>Kerby XDR Project</description>
+
+</project>

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/EnumType.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/EnumType.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/EnumType.java
new file mode 100644
index 0000000..0936863
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/EnumType.java
@@ -0,0 +1,37 @@
+/**
+ *  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.xdr;
+
+/**
+ * A helper interface for enum types.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface EnumType {
+    /**
+     * @return the Enum element value
+     */
+    int getValue();
+    
+    /**
+     * @return The enum element name
+     */
+    String getName();
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrDataType.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrDataType.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrDataType.java
new file mode 100644
index 0000000..05aaba1
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrDataType.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.xdr;
+
+/**
+ * An enumeration for every XDR type.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum XdrDataType {
+    UNKNOWN             (-1),
+    BOOLEAN             (0x01),
+    INTEGER             (0x02),
+    BYTES               (0x03),
+    STRING              (0X04);
+
+    /** The dataType value */
+    private int value;
+
+    /**
+     * Create an instance of this class
+     */
+    private XdrDataType(int value) {
+        this.value = value;
+    }
+
+    /**
+     * @return The associated dataType value
+     */
+    public int getValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrFieldInfo.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrFieldInfo.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrFieldInfo.java
new file mode 100644
index 0000000..eece615
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/XdrFieldInfo.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.xdr;
+
+import org.apache.kerby.xdr.type.XdrType;
+
+/**
+ * Representing a field in a XDR struct.
+ */
+public class XdrFieldInfo {
+    private EnumType index;
+    private Class<? extends XdrType> type;
+
+    /**
+     * Constructor.
+     * @param index
+     * @param type
+     */
+    public XdrFieldInfo(EnumType index, Class<? extends XdrType> type) {
+        this.index = index;
+        this.type = type;
+    }
+
+    public EnumType getIndex() {
+        return index;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/AbstractXdrType.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/AbstractXdrType.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/AbstractXdrType.java
new file mode 100644
index 0000000..2b956a0
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/AbstractXdrType.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.xdr.type;
+
+import org.apache.kerby.xdr.XdrDataType;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * The abstract XDR type for all the XDR types. It provides basic
+ * encoding and decoding utilities.
+ *
+ * @param <T> the type of the value encoded/decoded or wrapped by this
+ */
+public abstract class AbstractXdrType<T> implements XdrType {
+    private XdrDataType dataType;
+
+    // The wrapped real value.
+    private T value;
+
+    private int bodyLength = -1;
+
+    /**
+     * Default constructor.
+     * @param dataType the dataType
+     * @param value the value
+     */
+    public AbstractXdrType(XdrDataType dataType, T value) {
+        this(dataType);
+        this.value = value;
+    }
+
+    /**
+     * Default constructor.
+     * @param dataType the dataType
+     */
+    public AbstractXdrType(XdrDataType dataType) {
+        this.dataType = dataType;
+    }
+
+    @Override
+    public byte[] encode() throws IOException {
+        int len = encodingLength();
+        ByteBuffer byteBuffer = ByteBuffer.allocate(len);
+        encode(byteBuffer);
+        byteBuffer.flip();
+        return byteBuffer.array();
+    }
+
+    @Override
+    public void encode(ByteBuffer buffer) throws IOException {
+
+    }
+
+    protected void encodeBody(ByteBuffer buffer) throws IOException {
+    }
+
+    @Override
+    public void decode(byte[] content) throws IOException {
+        decode(ByteBuffer.wrap(content));
+    }
+
+    @Override
+    public int encodingLength() {
+        return -1;
+    }
+
+    protected int encodingHeaderLength() throws IOException {
+        return -1;
+    }
+
+    protected abstract int encodingBodyLength() throws IOException;
+
+    @Override
+    public void decode(ByteBuffer content) throws IOException {
+
+    }
+
+    public T getValue() {
+        return value;
+    }
+
+    public void setValue(T value) {
+        this.value = value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBoolean.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBoolean.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBoolean.java
new file mode 100644
index 0000000..b6d8d04
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBoolean.java
@@ -0,0 +1,58 @@
+/**
+ *  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.xdr.type;
+
+import org.apache.kerby.xdr.XdrDataType;
+
+/**
+ * ASN1 Boolean type
+ */
+public class XdrBoolean extends XdrSimple<Boolean> {
+    private static final byte[] TRUE_BYTE = new byte[] {(byte) 0xff};
+    private static final byte[] FALSE_BYTE = new byte[] {(byte) 0x00};
+
+    public static final XdrBoolean TRUE = new XdrBoolean(true);
+    public static final XdrBoolean FALSE = new XdrBoolean(false);
+
+    /**
+     * Default constructor, generally for decoding as a container
+     */
+    public XdrBoolean() {
+        this(null);
+    }
+
+    /**
+     * Constructor with a value, generally for encoding of the value
+     * @param value The boolean value
+     */
+    public XdrBoolean(Boolean value) {
+        super(XdrDataType.BOOLEAN, value);
+    }
+
+    @Override
+    protected int encodingBodyLength() {
+        return 1;
+    }
+
+    @Override
+    protected void toBytes() {
+        setBytes(getValue() ? TRUE_BYTE : FALSE_BYTE);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBytes.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBytes.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBytes.java
new file mode 100644
index 0000000..dcceb91
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrBytes.java
@@ -0,0 +1,34 @@
+/**
+ *  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.xdr.type;
+
+import org.apache.kerby.xdr.XdrDataType;
+
+public class XdrBytes extends XdrSimple<byte[]> {
+    private int padding;
+
+    public XdrBytes() {
+        this(null);
+    }
+
+    public XdrBytes(byte[] value) {
+        super(XdrDataType.BYTES, value);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrInteger.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrInteger.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrInteger.java
new file mode 100644
index 0000000..e1099a4
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrInteger.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.xdr.type;
+
+import org.apache.kerby.xdr.XdrDataType;
+
+import java.io.IOException;
+import java.math.BigInteger;
+
+public class XdrInteger extends XdrSimple<BigInteger> {
+    public XdrInteger() {
+        this((BigInteger) null);
+    }
+
+    public XdrInteger(Integer value) {
+        this(BigInteger.valueOf(value));
+    }
+
+    public XdrInteger(Long value) {
+        this(BigInteger.valueOf(value));
+    }
+
+    public XdrInteger(BigInteger value) {
+        super(XdrDataType.INTEGER, value);
+    }
+
+    protected void toBytes() {
+        setBytes(getValue().toByteArray());
+    }
+
+    protected void toValue() throws IOException {
+        setValue(new BigInteger(getBytes()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrSimple.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrSimple.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrSimple.java
new file mode 100644
index 0000000..b9526bd
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrSimple.java
@@ -0,0 +1,98 @@
+/**
+ *  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.xdr.type;
+
+import org.apache.kerby.xdr.XdrDataType;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * ASN1 simple type, of single value other than complex type of multiple values.
+ */
+public abstract class XdrSimple<T> extends AbstractXdrType<T> {
+    private byte[] bytes;
+
+    /**
+     * Default constructor, generally for decoding as a value container
+     * @param dataTypeNo The dataType number
+     */
+    public XdrSimple(XdrDataType dataTypeNo) {
+        this(dataTypeNo, null);
+    }
+
+    /**
+     * Constructor with a value, generally for encoding of the value
+     * @param xdrDataType The dataType number
+     * @param value The value
+     */
+    public XdrSimple(XdrDataType xdrDataType, T value) {
+        super(xdrDataType, value);
+    }
+
+    protected byte[] getBytes() {
+        return bytes;
+    }
+
+    protected void setBytes(byte[] bytes) {
+        this.bytes = bytes;
+    }
+
+    protected byte[] encodeBody() {
+        if (bytes == null) {
+            toBytes();
+        }
+        return bytes;
+    }
+
+    @Override
+    protected void encodeBody(ByteBuffer buffer) {
+        byte[] body = encodeBody();
+        if (body != null) {
+            buffer.put(body);
+        }
+    }
+
+    @Override
+    protected int encodingBodyLength() {
+        if (getValue() == null) {
+            return 0;
+        }
+        if (bytes == null) {
+            toBytes();
+        }
+        return bytes.length;
+    }
+
+    protected void toValue() throws IOException { }
+
+    protected void toBytes() { }
+
+    public static boolean isSimple(XdrDataType dataType) {
+        switch (dataType) {
+            case BOOLEAN:
+            case INTEGER:
+            case STRING:
+                return true;
+            default:
+                return false;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java
new file mode 100644
index 0000000..949d3cf
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java
@@ -0,0 +1,292 @@
+/**
+ *  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.xdr.type;
+
+import org.apache.kerby.xdr.XdrDataType;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class XdrString extends XdrSimple<String> {
+    public XdrString(XdrDataType xdrDataType) {
+        super(xdrDataType, null);
+    }
+
+    public XdrString(XdrDataType dataTypeNo, String value) {
+        super(dataTypeNo, value);
+    }
+
+    @Override
+    protected void toBytes() {
+        if (getValue() != null) {
+            byte[] bytes = getValue().getBytes(StandardCharsets.US_ASCII);
+            setBytes(bytes);
+        }
+    }
+
+    @Override
+    protected int encodingBodyLength() {
+        if (getValue() != null) {
+            return getValue().length();
+        }
+        return 0;
+    }
+
+    protected void toValue() throws IOException {
+        byte[] bytes = getBytes();
+        setValue(new String(bytes, StandardCharsets.US_ASCII));
+    }
+
+    public static String fromUTF8ByteArray(byte[] bytes) {
+        int i = 0;
+        int length = 0;
+
+        while (i < bytes.length) {
+            length++;
+            if ((bytes[i] & 0xf0) == 0xf0) {
+                // surrogate pair
+                length++;
+                i += 4;
+            } else if ((bytes[i] & 0xe0) == 0xe0) {
+                i += 3;
+            } else if ((bytes[i] & 0xc0) == 0xc0) {
+                i += 2;
+            } else {
+                i += 1;
+            }
+        }
+
+        char[] cs = new char[length];
+        i = 0;
+        length = 0;
+
+        while (i < bytes.length) {
+            char ch;
+
+            if ((bytes[i] & 0xf0) == 0xf0) {
+                int codePoint = ((bytes[i] & 0x03) << 18) | ((bytes[i + 1] & 0x3F) << 12)
+                        | ((bytes[i + 2] & 0x3F) << 6) | (bytes[i + 3] & 0x3F);
+                int u = codePoint - 0x10000;
+                char w1 = (char) (0xD800 | (u >> 10));
+                char w2 = (char) (0xDC00 | (u & 0x3FF));
+                cs[length++] = w1;
+                ch = w2;
+                i += 4;
+            } else if ((bytes[i] & 0xe0) == 0xe0) {
+                ch = (char) (((bytes[i] & 0x0f) << 12)
+                        | ((bytes[i + 1] & 0x3f) << 6) | (bytes[i + 2] & 0x3f));
+                i += 3;
+            } else if ((bytes[i] & 0xd0) == 0xd0) {
+                ch = (char) (((bytes[i] & 0x1f) << 6) | (bytes[i + 1] & 0x3f));
+                i += 2;
+            } else if ((bytes[i] & 0xc0) == 0xc0) {
+                ch = (char) (((bytes[i] & 0x1f) << 6) | (bytes[i + 1] & 0x3f));
+                i += 2;
+            } else {
+                ch = (char) (bytes[i] & 0xff);
+                i += 1;
+            }
+
+            cs[length++] = ch;
+        }
+
+        return new String(cs);
+    }
+
+    public static byte[] toUTF8ByteArray(String string) {
+        return toUTF8ByteArray(string.toCharArray());
+    }
+
+    public static byte[] toUTF8ByteArray(char[] string) {
+        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+        try {
+            toUTF8ByteArray(string, bOut);
+        } catch (IOException e) {
+            throw new IllegalStateException("cannot encode string to byte array!");
+        }
+
+        return bOut.toByteArray();
+    }
+
+    public static void toUTF8ByteArray(char[] string, OutputStream sOut) throws IOException {
+        char[] c = string;
+        int i = 0;
+
+        while (i < c.length) {
+            char ch = c[i];
+
+            if (ch < 0x0080) {
+                sOut.write(ch);
+            } else if (ch < 0x0800) {
+                sOut.write(0xc0 | (ch >> 6));
+                sOut.write(0x80 | (ch & 0x3f));
+            } else if (ch >= 0xD800 && ch <= 0xDFFF) {
+                // in error - can only happen, if the Java String class has a
+                // bug.
+                if (i + 1 >= c.length) {
+                    throw new IllegalStateException("invalid UTF-16 codepoint");
+                }
+                char w1 = ch;
+                ch = c[++i];
+                char w2 = ch;
+                // in error - can only happen, if the Java String class has a
+                // bug.
+                if (w1 > 0xDBFF) {
+                    throw new IllegalStateException("invalid UTF-16 codepoint");
+                }
+                int codePoint = ((w1 & 0x03FF) << 10) | (w2 & 0x03FF) + 0x10000;
+                sOut.write(0xf0 | (codePoint >> 18));
+                sOut.write(0x80 | ((codePoint >> 12) & 0x3F));
+                sOut.write(0x80 | ((codePoint >> 6) & 0x3F));
+                sOut.write(0x80 | (codePoint & 0x3F));
+            } else {
+                sOut.write(0xe0 | (ch >> 12));
+                sOut.write(0x80 | ((ch >> 6) & 0x3F));
+                sOut.write(0x80 | (ch & 0x3F));
+            }
+
+            i++;
+        }
+    }
+
+    /**
+     * A locale independent version of toUpperCase.
+     *
+     * @param string input to be converted
+     * @return a US Ascii uppercase version
+     */
+    public static String toUpperCase(String string) {
+        boolean changed = false;
+        char[] chars = string.toCharArray();
+
+        for (int i = 0; i != chars.length; i++) {
+            char ch = chars[i];
+            if ('a' <= ch && 'z' >= ch) {
+                changed = true;
+                chars[i] = (char) (ch - 'a' + 'A');
+            }
+        }
+
+        if (changed) {
+            return new String(chars);
+        }
+
+        return string;
+    }
+
+    /**
+     * A locale independent version of toLowerCase.
+     *
+     * @param string input to be converted
+     * @return a US ASCII lowercase version
+     */
+    public static String toLowerCase(String string) {
+        boolean changed = false;
+        char[] chars = string.toCharArray();
+
+        for (int i = 0; i != chars.length; i++) {
+            char ch = chars[i];
+            if ('A' <= ch && 'Z' >= ch) {
+                changed = true;
+                chars[i] = (char) (ch - 'A' + 'a');
+            }
+        }
+
+        if (changed) {
+            return new String(chars);
+        }
+
+        return string;
+    }
+
+    public static byte[] toByteArray(char[] chars) {
+        byte[] bytes = new byte[chars.length];
+
+        for (int i = 0; i != bytes.length; i++) {
+            bytes[i] = (byte) chars[i];
+        }
+
+        return bytes;
+    }
+
+    public static byte[] toByteArray(String string) {
+        byte[] bytes = new byte[string.length()];
+
+        for (int i = 0; i != bytes.length; i++) {
+            char ch = string.charAt(i);
+
+            bytes[i] = (byte) ch;
+        }
+
+        return bytes;
+    }
+
+    /**
+     * Convert an array of 8 bit characters into a string.
+     *
+     * @param bytes 8 bit characters.
+     * @return resulting String.
+     */
+    public static String fromByteArray(byte[] bytes) {
+        return new String(asCharArray(bytes));
+    }
+
+    /**
+     * Do a simple conversion of an array of 8 bit characters into a string.
+     *
+     * @param bytes 8 bit characters.
+     * @return resulting String.
+     */
+    public static char[] asCharArray(byte[] bytes) {
+        char[] chars = new char[bytes.length];
+
+        for (int i = 0; i != chars.length; i++) {
+            chars[i] = (char) (bytes[i] & 0xff);
+        }
+
+        return chars;
+    }
+
+    public static String[] split(String input, char delimiter) {
+        List<String> v = new ArrayList<String>();
+        boolean moreTokens = true;
+        String subString;
+
+        while (moreTokens) {
+            int tokenLocation = input.indexOf(delimiter);
+            if (tokenLocation > 0) {
+                subString = input.substring(0, tokenLocation);
+                v.add(subString);
+                input = input.substring(tokenLocation + 1);
+            } else {
+                moreTokens = false;
+                v.add(input);
+            }
+        }
+
+        return v.toArray(new String[v.size()]);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrStructType.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrStructType.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrStructType.java
new file mode 100644
index 0000000..3793674
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrStructType.java
@@ -0,0 +1,40 @@
+/**
+ *  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.xdr.type;
+
+import org.apache.kerby.xdr.XdrDataType;
+import org.apache.kerby.xdr.XdrFieldInfo;
+
+/**
+ * For collection type that may consist of dataTypeged fields
+ */
+public abstract class XdrStructType extends AbstractXdrType<XdrStructType> {
+    private final XdrFieldInfo[] fieldInfos;
+    private final XdrType[] fields;
+
+    public XdrStructType(XdrDataType xdrDataType,
+                         final XdrFieldInfo[] fieldInfos) {
+        super(xdrDataType);
+
+        setValue(this);
+        this.fieldInfos = fieldInfos;
+        this.fields = new XdrType[fieldInfos.length];
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrType.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrType.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrType.java
new file mode 100644
index 0000000..6840e59
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrType.java
@@ -0,0 +1,62 @@
+/**
+ *  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.xdr.type;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * The ASN1 type interface for all ASN1 types.
+ */
+public interface XdrType {
+
+    /**
+     * Get length of encoding bytes by just calculating without real encoding.
+     * Generally it's called to prepare for the encoding buffer.
+     * @return length of encoding bytes
+     */
+    int encodingLength() throws IOException;
+
+    /**
+     * Encode the type, by recursively.
+     * @return encoded bytes
+     */
+    byte[] encode() throws IOException;
+
+    /**
+     * Encode the type, by recursively, using the provided buffer.
+     * @param buffer The byte buffer
+     */
+    void encode(ByteBuffer buffer) throws IOException;
+
+    /**
+     * Decode the content bytes into this type.
+     * @param content The content bytes
+     * @throws IOException e
+     */
+    void decode(byte[] content) throws IOException;
+
+    /**
+     * Decode the content bytes into this type.
+     * @param content The content bytes
+     * @throws IOException e
+     */
+    void decode(ByteBuffer content) throws IOException;
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/HexUtil.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/HexUtil.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/HexUtil.java
new file mode 100644
index 0000000..70a2b1c
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/HexUtil.java
@@ -0,0 +1,113 @@
+/**
+ *  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.xdr.util;
+
+/**
+ * This is only for test, be careful when use in production codes.
+ */
+public class HexUtil {
+
+    static final String HEX_CHARS_STR = "0123456789ABCDEF";
+    static final char[] HEX_CHARS = HEX_CHARS_STR.toCharArray();
+
+    /**
+     * Convert bytes into friendly format as:
+     * 0x02 02 00 80
+     */
+    public static String bytesToHexFriendly(byte[] bytes) {
+        int len = bytes.length * 2;
+        len += bytes.length; // for ' ' appended for each char
+        len += 2; // for '0x' prefix
+        char[] hexChars = new char[len];
+        hexChars[0] = '0';
+        hexChars[1] = 'x';
+        for (int j = 0; j < bytes.length; j++) {
+            int v = bytes[j] & 0xFF;
+            hexChars[j * 3 + 2] = HEX_CHARS[v >>> 4];
+            hexChars[j * 3 + 3] = HEX_CHARS[v & 0x0F];
+            hexChars[j * 3 + 4] = ' ';
+        }
+
+        return new String(hexChars);
+    }
+
+    /**
+     * Convert friendly hex string like follows into byte array
+     * 0x02 02 00 80
+     */
+    public static byte[] hex2bytesFriendly(String hexString) {
+        hexString = hexString.toUpperCase();
+        String hexStr = hexString;
+        if (hexString.startsWith("0X")) {
+            hexStr = hexString.substring(2);
+        }
+        String[] hexParts = hexStr.split(" ");
+
+        byte[] bytes = new byte[hexParts.length];
+        char[] hexPart;
+        for (int i = 0; i < hexParts.length; ++i) {
+            hexPart = hexParts[i].toCharArray();
+            if (hexPart.length != 2) {
+                throw new IllegalArgumentException("Invalid hex string to convert");
+            }
+            bytes[i] = (byte) ((HEX_CHARS_STR.indexOf(hexPart[0]) << 4)
+                + HEX_CHARS_STR.indexOf(hexPart[1]));
+        }
+
+        return bytes;
+    }
+
+    /**
+     * Convert bytes into format as:
+     * 02020080
+     * @param bytes The bytes
+     * @return The hex string
+     */
+    public static String bytesToHex(byte[] bytes) {
+        int len = bytes.length * 2;
+        char[] hexChars = new char[len];
+        for (int j = 0; j < bytes.length; j++) {
+            int v = bytes[j] & 0xFF;
+            hexChars[j * 2] = HEX_CHARS[v >>> 4];
+            hexChars[j * 2 + 1] = HEX_CHARS[v & 0x0F];
+        }
+
+        return new String(hexChars);
+    }
+
+    /**
+     * Convert hex string like follows into byte array
+     * 02020080
+     * @param hexString The hex string
+     * @return The bytes
+     */
+    public static byte[] hex2bytes(String hexString) {
+        hexString = hexString.toUpperCase();
+        int len = hexString.length() / 2;
+        byte[] bytes = new byte[len];
+        char[] hexChars = hexString.toCharArray();
+        for (int i = 0, j = 0; i < len; ++i) {
+            bytes[i] = (byte) ((HEX_CHARS_STR.indexOf(hexChars[j++]) << 4)
+                + HEX_CHARS_STR.indexOf(hexChars[j++]));
+        }
+
+        return bytes;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/IOUtil.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/IOUtil.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/IOUtil.java
new file mode 100644
index 0000000..2136511
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/IOUtil.java
@@ -0,0 +1,109 @@
+/**
+ *  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.xdr.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+
+/**
+ * Some IO and file related utilities.
+ */
+public final class IOUtil {
+    private IOUtil() { }
+
+    public static byte[] readInputStream(InputStream in) throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] buffer = new byte[1024];
+        int length = 0;
+        while ((length = in.read(buffer)) != -1) {
+            baos.write(buffer, 0, length);
+        }
+        in.close();
+        return baos.toByteArray();
+    }
+
+    public static void readInputStream(InputStream in,
+                                       byte[] buf) throws IOException {
+        int toRead = buf.length;
+        int off = 0;
+        while (toRead > 0) {
+            int ret = in.read(buf, off, toRead);
+            if (ret < 0) {
+                throw new IOException("Bad inputStream, premature EOF");
+            }
+            toRead -= ret;
+            off += ret;
+        }
+        in.close();
+    }
+
+    /**
+     * Read an input stream and return the content as string assuming UTF8.
+     * @param in The input stream
+     * @return The content
+     * @throws IOException e
+     */
+    public static String readInput(InputStream in) throws IOException {
+        byte[] content = readInputStream(in);
+        return Utf8.toString(content);
+    }
+
+    /**
+     * Read a file and return the content as string assuming UTF8.
+     * @param file The file to read
+     * @return The content
+     * @throws IOException e
+     */
+    public static String readFile(File file) throws IOException {
+        long len = 0;
+        if (file.length() >= Integer.MAX_VALUE) {
+            throw new IOException("Too large file, unexpected!");
+        } else {
+            len = file.length();
+        }
+        byte[] buf = new byte[(int) len];
+
+        InputStream is = new FileInputStream(file);
+        readInputStream(is, buf);
+
+        return Utf8.toString(buf);
+    }
+
+    /**
+     * Write a file with the content assuming UTF8.
+     * @param content The content
+     * @param file The file to write
+     * @throws IOException e
+     */
+    public static void writeFile(String content, File file) throws IOException {
+        FileOutputStream outputStream = new FileOutputStream(file);
+        FileChannel fc = outputStream.getChannel();
+
+        ByteBuffer buffer = ByteBuffer.wrap(Utf8.toBytes(content));
+        fc.write(buffer);
+        outputStream.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/Utf8.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/Utf8.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/Utf8.java
new file mode 100644
index 0000000..374c16f
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/Utf8.java
@@ -0,0 +1,34 @@
+/**
+ *  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.xdr.util;
+
+import java.nio.charset.StandardCharsets;
+
+public final class Utf8 {
+    private Utf8() { }
+
+    public static String toString(byte[] bytes) {
+        return new String(bytes, StandardCharsets.UTF_8);
+    }
+
+    public static byte[] toBytes(String s) {
+        return s.getBytes(StandardCharsets.UTF_8);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/XdrUtil.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/XdrUtil.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/XdrUtil.java
new file mode 100644
index 0000000..880bbb0
--- /dev/null
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/util/XdrUtil.java
@@ -0,0 +1,26 @@
+/**
+ *  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.xdr.util;
+
+public final class XdrUtil {
+    private XdrUtil() {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/test/java/org/apache/kerby/xdr/TestUtil.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/test/java/org/apache/kerby/xdr/TestUtil.java b/kerby-xdr/src/test/java/org/apache/kerby/xdr/TestUtil.java
new file mode 100644
index 0000000..6a3d9e8
--- /dev/null
+++ b/kerby-xdr/src/test/java/org/apache/kerby/xdr/TestUtil.java
@@ -0,0 +1,47 @@
+/**
+ *  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.xdr;
+
+import org.apache.kerby.xdr.util.HexUtil;
+import org.apache.kerby.xdr.util.IOUtil;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public final class TestUtil {
+    private TestUtil() {
+
+    }
+
+    static byte[] readBytesFromTxtFile(String resource) throws IOException {
+        String hexStr = readStringFromTxtFile(resource);
+        return HexUtil.hex2bytes(hexStr);
+    }
+
+    static String readStringFromTxtFile(String resource) throws IOException {
+        InputStream is = TestUtil.class.getResourceAsStream(resource);
+        return IOUtil.readInput(is);
+    }
+
+    static byte[] readBytesFromBinFile(String resource) throws IOException {
+        InputStream is = TestUtil.class.getResourceAsStream(resource);
+        return IOUtil.readInputStream(is);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/kerby-xdr/src/test/java/org/apache/kerby/xdr/XdrBooleanTest.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/test/java/org/apache/kerby/xdr/XdrBooleanTest.java b/kerby-xdr/src/test/java/org/apache/kerby/xdr/XdrBooleanTest.java
new file mode 100644
index 0000000..003403b
--- /dev/null
+++ b/kerby-xdr/src/test/java/org/apache/kerby/xdr/XdrBooleanTest.java
@@ -0,0 +1,24 @@
+/**
+ *  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.xdr;
+
+public class XdrBooleanTest {
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d797a80d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 21a6d04..a5023dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
     <module>kerby-config</module>
     <module>kerby-util</module>
     <module>kerby-asn1</module>
+    <module>kerby-xdr</module>
     <module>kerby-pkix</module>
     <module>kerby-kerb</module>
     <module>kerby-kdc</module>


Mime
View raw message