directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [15/19] directory-kerby git commit: ASN1. Introduced Asn1Encodeable for encode/decode methods, leaving Asn1Object of tag things so to be used in parser side
Date Wed, 09 Dec 2015 02:13:27 GMT
ASN1. Introduced Asn1Encodeable for encode/decode methods, leaving Asn1Object of tag things
so to be used in parser side


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

Branch: refs/heads/pkinit-support
Commit: 6487cf5bdebfc3a2e12c9fee0ea35536876a55b2
Parents: 2df85a4
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Wed Dec 9 06:47:26 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Wed Dec 9 06:47:26 2015 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/kerby/asn1/Asn1.java   |   2 +-
 .../java/org/apache/kerby/asn1/Asn1Binder.java  |   6 +-
 .../org/apache/kerby/asn1/Asn1Converter.java    |   6 +-
 .../java/org/apache/kerby/asn1/Asn1Dumper.java  |   2 +-
 .../kerby/asn1/type/AbstractAsn1Type.java       |   2 +-
 .../org/apache/kerby/asn1/type/Asn1Any.java     |   6 +-
 .../apache/kerby/asn1/type/Asn1Encodeable.java  | 252 +++++++++++++++++++
 .../org/apache/kerby/asn1/type/Asn1Object.java  | 200 +--------------
 .../org/apache/kerby/asn1/type/Asn1Simple.java  |   4 +-
 .../org/apache/kerby/asn1/type/Asn1Tagging.java |   6 +-
 .../kerberos/kerb/common/CheckSumUtil.java      |   6 +-
 .../kerberos/kerb/common/EncryptionUtil.java    |   4 +-
 12 files changed, 279 insertions(+), 217 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
index 4d4d51b..80bf9db 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
@@ -19,8 +19,8 @@
  */
 package org.apache.kerby.asn1;
 
-import org.apache.kerby.asn1.parse.Asn1Parser;
 import org.apache.kerby.asn1.parse.Asn1ParseResult;
+import org.apache.kerby.asn1.parse.Asn1Parser;
 import org.apache.kerby.asn1.type.Asn1Type;
 import org.apache.kerby.asn1.util.HexUtil;
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Binder.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Binder.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Binder.java
index 79c4db4..afbb3c9 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Binder.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Binder.java
@@ -1,7 +1,7 @@
 package org.apache.kerby.asn1;
 
 import org.apache.kerby.asn1.parse.Asn1ParseResult;
-import org.apache.kerby.asn1.type.Asn1Object;
+import org.apache.kerby.asn1.type.Asn1Encodeable;
 import org.apache.kerby.asn1.type.Asn1Type;
 
 import java.io.IOException;
@@ -18,7 +18,7 @@ public final class Asn1Binder {
     public static void bind(Asn1ParseResult parseResult,
                             Asn1Type value) throws IOException {
         value.useDefinitiveLength(parseResult.isDefinitiveLength());
-        ((Asn1Object) value).decode(parseResult);
+        ((Asn1Encodeable) value).decode(parseResult);
     }
 
     public static void bindWithTagging(Asn1ParseResult parseResult,
@@ -27,6 +27,6 @@ public final class Asn1Binder {
             throw new IllegalArgumentException(
                 "Attempting to decode non-tagged value using tagging way");
         }
-        ((Asn1Object) value).taggedDecode(parseResult, taggingOption);
+        ((Asn1Encodeable) value).taggedDecode(parseResult, taggingOption);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Converter.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Converter.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Converter.java
index 89af899..b1efd93 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Converter.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Converter.java
@@ -22,7 +22,7 @@ package org.apache.kerby.asn1;
 import org.apache.kerby.asn1.parse.Asn1ParseResult;
 import org.apache.kerby.asn1.type.Asn1Collection;
 import org.apache.kerby.asn1.type.Asn1Constructed;
-import org.apache.kerby.asn1.type.Asn1Object;
+import org.apache.kerby.asn1.type.Asn1Encodeable;
 import org.apache.kerby.asn1.type.Asn1Simple;
 import org.apache.kerby.asn1.type.Asn1Type;
 
@@ -43,7 +43,7 @@ public final class Asn1Converter {
         } else if (Asn1Collection.isCollection(parseResult.tag())) {
             return Asn1Converter.convertAsCollection(parseResult);
         } else if (!parseResult.tag().isPrimitive()) {
-            Asn1Object tmpValue = new Asn1Constructed(parseResult.tag());
+            Asn1Encodeable tmpValue = new Asn1Constructed(parseResult.tag());
             tmpValue.decode(parseResult);
             return tmpValue;
         } else {
@@ -52,7 +52,7 @@ public final class Asn1Converter {
     }
 
     public static Asn1Type convertAsSimple(Asn1ParseResult parseResult) throws IOException
{
-        Asn1Object value = (Asn1Object) Asn1Simple.createSimple(parseResult.tagNo());
+        Asn1Encodeable value = Asn1Simple.createSimple(parseResult.tagNo());
         value.useDefinitiveLength(parseResult.isDefinitiveLength());
         Asn1Binder.bind(parseResult, value);
         return value;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
index 27dcb08..73d3321 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
@@ -20,8 +20,8 @@
 package org.apache.kerby.asn1;
 
 import org.apache.kerby.asn1.parse.Asn1Item;
-import org.apache.kerby.asn1.parse.Asn1Parser;
 import org.apache.kerby.asn1.parse.Asn1ParseResult;
+import org.apache.kerby.asn1.parse.Asn1Parser;
 import org.apache.kerby.asn1.type.Asn1Any;
 import org.apache.kerby.asn1.type.Asn1Simple;
 import org.apache.kerby.asn1.type.Asn1Type;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/AbstractAsn1Type.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/AbstractAsn1Type.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/AbstractAsn1Type.java
index b12c67d..105aed6 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/AbstractAsn1Type.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/AbstractAsn1Type.java
@@ -28,7 +28,7 @@ import org.apache.kerby.asn1.UniversalTag;
  *
  * @param <T> the type of the value encoded/decoded or wrapped by this
  */
-public abstract class AbstractAsn1Type<T> extends Asn1Object {
+public abstract class AbstractAsn1Type<T> extends Asn1Encodeable {
     // The wrapped real value.
     private T value;
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
index 3bce491..0debce1 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
@@ -57,17 +57,17 @@ public class Asn1Any extends AbstractAsn1Type<Asn1Type> {
 
     @Override
     protected int encodingBodyLength() {
-        return ((Asn1Object) getValue()).encodingBodyLength();
+        return ((Asn1Encodeable) getValue()).encodingBodyLength();
     }
 
     @Override
     protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
-        ((Asn1Object) getValue()).decodeBody(parseResult);
+        ((Asn1Encodeable) getValue()).decodeBody(parseResult);
     }
 
     @Override
     protected void encodeBody(ByteBuffer buffer) {
-        ((Asn1Object) getValue()).encodeBody(buffer);
+        ((Asn1Encodeable) getValue()).encodeBody(buffer);
     }
 
     protected <T extends Asn1Type> T getValueAs(Class<T> t) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Encodeable.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Encodeable.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Encodeable.java
new file mode 100644
index 0000000..07ec4c9
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Encodeable.java
@@ -0,0 +1,252 @@
+/**
+ *  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.type;
+
+import org.apache.kerby.asn1.Tag;
+import org.apache.kerby.asn1.TaggingOption;
+import org.apache.kerby.asn1.UniversalTag;
+import org.apache.kerby.asn1.parse.Asn1Container;
+import org.apache.kerby.asn1.parse.Asn1ParseResult;
+import org.apache.kerby.asn1.parse.Asn1Parser;
+import org.apache.kerby.asn1.util.Asn1Util;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * The abstract ASN1 object for all the ASN1 types. It provides basic
+ * encoding and decoding utilities.
+ */
+public abstract class Asn1Encodeable extends Asn1Object implements Asn1Type {
+
+    private int bodyLength = -1;
+
+    // encoding options
+    private EncodingType encodingType = EncodingType.BER;
+    private boolean isImplicit = true;
+    private boolean isDefinitiveLength = true; // by default!!
+
+    /**
+     * Constructor with a tag
+     * @param tag The tag
+     */
+    public Asn1Encodeable(Tag tag) {
+        super(tag);
+    }
+
+    /**
+     * Default constructor with an universal tag.
+     * @param tag the tag
+     */
+    public Asn1Encodeable(UniversalTag tag) {
+        super(tag);
+    }
+
+    /**
+     * Constructor with a tag
+     * @param tag The tag
+     */
+    public Asn1Encodeable(int tag) {
+        super(tag);
+    }
+
+    @Override
+    public void usePrimitive(boolean isPrimitive) {
+        tag().usePrimitive(isPrimitive);
+    }
+
+    @Override
+    public boolean isPrimitive() {
+        return tag().isPrimitive();
+    }
+
+    @Override
+    public void useDefinitiveLength(boolean isDefinitiveLength) {
+        this.isDefinitiveLength = isDefinitiveLength;
+    }
+
+    @Override
+    public boolean isDefinitiveLength() {
+        return isDefinitiveLength;
+    }
+
+    @Override
+    public void useImplicit(boolean isImplicit) {
+        this.isImplicit = isImplicit;
+    }
+
+    @Override
+    public boolean isImplicit() {
+        return isImplicit;
+    }
+
+    @Override
+    public void useDER() {
+        this.encodingType = EncodingType.DER;
+    }
+
+    @Override
+    public boolean isDER() {
+        return encodingType == EncodingType.DER;
+    }
+
+    @Override
+    public void useBER() {
+        this.encodingType = EncodingType.BER;
+    }
+
+    @Override
+    public boolean isBER() {
+        return encodingType == EncodingType.BER;
+    }
+
+    @Override
+    public void useCER() {
+        this.encodingType = EncodingType.CER;
+    }
+
+    @Override
+    public boolean isCER() {
+        return encodingType == EncodingType.CER;
+    }
+
+    @Override
+    public byte[] encode() {
+        ByteBuffer byteBuffer = ByteBuffer.allocate(encodingLength());
+        encode(byteBuffer);
+        byteBuffer.flip();
+        return byteBuffer.array();
+    }
+
+    @Override
+    public void encode(ByteBuffer buffer) {
+        Asn1Util.encodeTag(buffer, tag());
+        Asn1Util.encodeLength(buffer, encodingBodyLength());
+        encodeBody(buffer);
+    }
+
+    protected void encodeBody(ByteBuffer buffer) { }
+
+    @Override
+    public void decode(byte[] content) throws IOException {
+        decode(ByteBuffer.wrap(content));
+    }
+
+    @Override
+    public int encodingLength() {
+        return encodingHeaderLength() + getBodyLength();
+    }
+
+    private int getBodyLength() {
+        if (bodyLength == -1) {
+            bodyLength = encodingBodyLength();
+        }
+        return bodyLength;
+    }
+
+    protected int encodingHeaderLength() {
+        int bodyLen = getBodyLength();
+        int headerLen = Asn1Util.lengthOfTagLength(tagNo());
+        headerLen += (isDefinitiveLength()
+            ? Asn1Util.lengthOfBodyLength(bodyLen) : 1);
+        return headerLen;
+    }
+
+    protected abstract int encodingBodyLength();
+
+    @Override
+    public void decode(ByteBuffer content) throws IOException {
+        Asn1ParseResult parseResult = Asn1Parser.parse(content);
+        decode(parseResult);
+    }
+
+    public void decode(Asn1ParseResult parseResult) throws IOException {
+        if (!tag().equals(parseResult.tag())) {
+            throw new IOException("Unexpected tag " + parseResult.tag()
+                + ", expecting " + tag());
+        }
+
+        decodeBody(parseResult);
+    }
+
+    protected abstract void decodeBody(Asn1ParseResult parseResult) throws IOException;
+
+    protected int taggedEncodingLength(TaggingOption taggingOption) {
+        int taggingTagNo = taggingOption.getTagNo();
+        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength()
+                : encodingLength();
+        int taggingEncodingLen = Asn1Util.lengthOfTagLength(taggingTagNo)
+                + Asn1Util.lengthOfBodyLength(taggingBodyLen) + taggingBodyLen;
+        return taggingEncodingLen;
+    }
+
+    @Override
+    public byte[] taggedEncode(TaggingOption taggingOption) {
+        int len = taggedEncodingLength(taggingOption);
+        ByteBuffer byteBuffer = ByteBuffer.allocate(len);
+        taggedEncode(byteBuffer, taggingOption);
+        byteBuffer.flip();
+        return byteBuffer.array();
+    }
+
+    @Override
+    public void taggedEncode(ByteBuffer buffer, TaggingOption taggingOption) {
+        Tag taggingTag = taggingOption.getTag(!isPrimitive());
+        Asn1Util.encodeTag(buffer, taggingTag);
+        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength()
+                : encodingLength();
+        Asn1Util.encodeLength(buffer, taggingBodyLen);
+        if (taggingOption.isImplicit()) {
+            encodeBody(buffer);
+        } else {
+            encode(buffer);
+        }
+    }
+
+    @Override
+    public void taggedDecode(byte[] content,
+                             TaggingOption taggingOption) throws IOException {
+        taggedDecode(ByteBuffer.wrap(content), taggingOption);
+    }
+
+    @Override
+    public void taggedDecode(ByteBuffer content,
+                             TaggingOption taggingOption) throws IOException {
+        Asn1ParseResult parseResult = Asn1Parser.parse(content);
+        taggedDecode(parseResult, taggingOption);
+    }
+
+    public void taggedDecode(Asn1ParseResult parseResult,
+                                TaggingOption taggingOption) throws IOException {
+        Tag expectedTaggingTagFlags = taggingOption.getTag(!isPrimitive());
+        if (!expectedTaggingTagFlags.equals(parseResult.tag())) {
+            throw new IOException("Unexpected tag " + parseResult.tag()
+                    + ", expecting " + expectedTaggingTagFlags);
+        }
+
+        if (taggingOption.isImplicit()) {
+            decodeBody(parseResult);
+        } else {
+            Asn1Container container = (Asn1Container) parseResult;
+            Asn1ParseResult body = container.getChildren().get(0);
+            decode(body);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
index d4c5ba5..9e40eac 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
@@ -20,29 +20,14 @@
 package org.apache.kerby.asn1.type;
 
 import org.apache.kerby.asn1.Tag;
-import org.apache.kerby.asn1.TaggingOption;
 import org.apache.kerby.asn1.UniversalTag;
-import org.apache.kerby.asn1.parse.Asn1Container;
-import org.apache.kerby.asn1.parse.Asn1Parser;
-import org.apache.kerby.asn1.parse.Asn1ParseResult;
-import org.apache.kerby.asn1.util.Asn1Util;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
 
 /**
- * The abstract ASN1 object for all the ASN1 types. It provides basic
- * encoding and decoding utilities.
+ * An ASN1 object has a tag.
  */
-public abstract class Asn1Object implements Asn1Type {
-    private final Tag tag;
+public abstract class Asn1Object {
 
-    private int bodyLength = -1;
-
-    // encoding options
-    private EncodingType encodingType = EncodingType.BER;
-    private boolean isImplicit = true;
-    private boolean isDefinitiveLength = true; // by default!!
+    private final Tag tag;
 
     /**
      * Constructor with a tag
@@ -68,120 +53,26 @@ public abstract class Asn1Object implements Asn1Type {
         this.tag = new Tag(tag);
     }
 
-    @Override
     public Tag tag() {
         return tag;
     }
 
-    protected int tagFlags() {
+    public int tagFlags() {
         return tag().tagFlags();
     }
 
-    protected int tagNo() {
+    public int tagNo() {
         return tag().tagNo();
     }
 
-    @Override
     public void usePrimitive(boolean isPrimitive) {
         tag.usePrimitive(isPrimitive);
     }
 
-    @Override
     public boolean isPrimitive() {
         return tag.isPrimitive();
     }
 
-    @Override
-    public void useDefinitiveLength(boolean isDefinitiveLength) {
-        this.isDefinitiveLength = isDefinitiveLength;
-    }
-
-    @Override
-    public boolean isDefinitiveLength() {
-        return isDefinitiveLength;
-    }
-
-    @Override
-    public void useImplicit(boolean isImplicit) {
-        this.isImplicit = isImplicit;
-    }
-
-    @Override
-    public boolean isImplicit() {
-        return isImplicit;
-    }
-
-    @Override
-    public void useDER() {
-        this.encodingType = EncodingType.DER;
-    }
-
-    @Override
-    public boolean isDER() {
-        return encodingType == EncodingType.DER;
-    }
-
-    @Override
-    public void useBER() {
-        this.encodingType = EncodingType.BER;
-    }
-
-    @Override
-    public boolean isBER() {
-        return encodingType == EncodingType.BER;
-    }
-
-    @Override
-    public void useCER() {
-        this.encodingType = EncodingType.CER;
-    }
-
-    @Override
-    public boolean isCER() {
-        return encodingType == EncodingType.CER;
-    }
-
-    @Override
-    public byte[] encode() {
-        ByteBuffer byteBuffer = ByteBuffer.allocate(encodingLength());
-        encode(byteBuffer);
-        byteBuffer.flip();
-        return byteBuffer.array();
-    }
-
-    @Override
-    public void encode(ByteBuffer buffer) {
-        Asn1Util.encodeTag(buffer, tag());
-        Asn1Util.encodeLength(buffer, encodingBodyLength());
-        encodeBody(buffer);
-    }
-
-    protected void encodeBody(ByteBuffer buffer) { }
-
-    @Override
-    public void decode(byte[] content) throws IOException {
-        decode(ByteBuffer.wrap(content));
-    }
-
-    @Override
-    public int encodingLength() {
-        return encodingHeaderLength() + getBodyLength();
-    }
-
-    private int getBodyLength() {
-        if (bodyLength == -1) {
-            bodyLength = encodingBodyLength();
-        }
-        return bodyLength;
-    }
-
-    protected int encodingHeaderLength() {
-        int bodyLen = getBodyLength();
-        int headerLen = Asn1Util.lengthOfTagLength(tagNo());
-        headerLen += (isDefinitiveLength()
-            ? Asn1Util.lengthOfBodyLength(bodyLen) : 1);
-        return headerLen;
-    }
 
     protected boolean isUniversal() {
         return tag.isUniversal();
@@ -210,85 +101,4 @@ public abstract class Asn1Object implements Asn1Type {
     public boolean isCollection() {
         return Asn1Collection.isCollection(tag());
     }
-
-    protected abstract int encodingBodyLength();
-
-    @Override
-    public void decode(ByteBuffer content) throws IOException {
-        Asn1ParseResult parseResult = Asn1Parser.parse(content);
-        decode(parseResult);
-    }
-
-    public void decode(Asn1ParseResult parseResult) throws IOException {
-        if (!tag().equals(parseResult.tag())) {
-            throw new IOException("Unexpected tag " + parseResult.tag()
-                + ", expecting " + tag());
-        }
-
-        decodeBody(parseResult);
-    }
-
-    protected abstract void decodeBody(Asn1ParseResult parseResult) throws IOException;
-
-    protected int taggedEncodingLength(TaggingOption taggingOption) {
-        int taggingTagNo = taggingOption.getTagNo();
-        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength()
-                : encodingLength();
-        int taggingEncodingLen = Asn1Util.lengthOfTagLength(taggingTagNo)
-                + Asn1Util.lengthOfBodyLength(taggingBodyLen) + taggingBodyLen;
-        return taggingEncodingLen;
-    }
-
-    @Override
-    public byte[] taggedEncode(TaggingOption taggingOption) {
-        int len = taggedEncodingLength(taggingOption);
-        ByteBuffer byteBuffer = ByteBuffer.allocate(len);
-        taggedEncode(byteBuffer, taggingOption);
-        byteBuffer.flip();
-        return byteBuffer.array();
-    }
-
-    @Override
-    public void taggedEncode(ByteBuffer buffer, TaggingOption taggingOption) {
-        Tag taggingTag = taggingOption.getTag(!isPrimitive());
-        Asn1Util.encodeTag(buffer, taggingTag);
-        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength()
-                : encodingLength();
-        Asn1Util.encodeLength(buffer, taggingBodyLen);
-        if (taggingOption.isImplicit()) {
-            encodeBody(buffer);
-        } else {
-            encode(buffer);
-        }
-    }
-
-    @Override
-    public void taggedDecode(byte[] content,
-                             TaggingOption taggingOption) throws IOException {
-        taggedDecode(ByteBuffer.wrap(content), taggingOption);
-    }
-
-    @Override
-    public void taggedDecode(ByteBuffer content,
-                             TaggingOption taggingOption) throws IOException {
-        Asn1ParseResult parseResult = Asn1Parser.parse(content);
-        taggedDecode(parseResult, taggingOption);
-    }
-
-    public void taggedDecode(Asn1ParseResult parseResult,
-                                TaggingOption taggingOption) throws IOException {
-        Tag expectedTaggingTagFlags = taggingOption.getTag(!isPrimitive());
-        if (!expectedTaggingTagFlags.equals(parseResult.tag())) {
-            throw new IOException("Unexpected tag " + parseResult.tag()
-                    + ", expecting " + expectedTaggingTagFlags);
-        }
-
-        if (taggingOption.isImplicit()) {
-            decodeBody(parseResult);
-        } else {
-            Asn1Container container = (Asn1Container) parseResult;
-            Asn1ParseResult body = container.getChildren().get(0);
-            decode(body);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
index 0cda770..d75f0a3 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
@@ -144,7 +144,7 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
      * @param tagNo The tag number
      * @return A simple ASN1 object
      */
-    public static Asn1Type createSimple(int tagNo) {
+    public static Asn1Simple<?> createSimple(int tagNo) {
         if (!isSimple(tagNo)) {
             throw new IllegalArgumentException("Not simple type, tag: " + tagNo);
         }
@@ -156,7 +156,7 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
      * @param tagNo The tag number
      * @return The simple ASN1 object
      */
-    public static Asn1Type createSimple(UniversalTag tagNo) {
+    public static Asn1Simple<?> createSimple(UniversalTag tagNo) {
         if (!isSimple(tagNo)) {
             throw new IllegalArgumentException("Not simple type, tag: " + tagNo);
         }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java
index f9b9eb3..c4ad00d 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java
@@ -63,7 +63,7 @@ public class Asn1Tagging<T extends Asn1Type>
 
     @Override
     protected int encodingBodyLength() {
-        Asn1Object value = (Asn1Object) getValue();
+        Asn1Encodeable value = (Asn1Encodeable) getValue();
         if (isImplicit()) {
             return value.encodingBodyLength();
         } else {
@@ -73,7 +73,7 @@ public class Asn1Tagging<T extends Asn1Type>
 
     @Override
     protected void encodeBody(ByteBuffer buffer) {
-        Asn1Object value = (Asn1Object) getValue();
+        Asn1Encodeable value = (Asn1Encodeable) getValue();
         if (isImplicit()) {
             value.encodeBody(buffer);
         } else {
@@ -83,7 +83,7 @@ public class Asn1Tagging<T extends Asn1Type>
 
     @Override
     protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
-        Asn1Object value = (Asn1Object) getValue();
+        Asn1Encodeable value = (Asn1Encodeable) getValue();
         if (isImplicit()) {
             value.decodeBody(parseResult);
         } else {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/CheckSumUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/CheckSumUtil.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/CheckSumUtil.java
index 2a5a1d5..139354a 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/CheckSumUtil.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/CheckSumUtil.java
@@ -19,7 +19,7 @@
  */
 package org.apache.kerby.kerberos.kerb.common;
 
-import org.apache.kerby.asn1.type.Asn1Object;
+import org.apache.kerby.asn1.type.Asn1Encodeable;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.crypto.CheckSumHandler;
 import org.apache.kerby.kerberos.kerb.crypto.EncTypeHandler;
@@ -50,14 +50,14 @@ public class CheckSumUtil {
         return CheckSumHandler.checksumWithKey(checkSumType, input, key.getKeyData(), usage);
     }
 
-    public static CheckSum seal(Asn1Object asn1Object,
+    public static CheckSum seal(Asn1Encodeable asn1Object,
                                 CheckSumType checkSumType) throws KrbException {
         byte[] encoded = asn1Object.encode();
         CheckSum checksum = makeCheckSum(checkSumType, encoded);
         return checksum;
     }
 
-    public static CheckSum seal(Asn1Object asn1Object, CheckSumType checkSumType,
+    public static CheckSum seal(Asn1Encodeable asn1Object, CheckSumType checkSumType,
                                      EncryptionKey key, KeyUsage usage) throws KrbException
{
         byte[] encoded = asn1Object.encode();
         CheckSum checksum = makeCheckSumWithKey(checkSumType, encoded, key, usage);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6487cf5b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
index 26f1d4f..d45789d 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
@@ -19,7 +19,7 @@
  */
 package org.apache.kerby.kerberos.kerb.common;
 
-import org.apache.kerby.asn1.type.Asn1Object;
+import org.apache.kerby.asn1.type.Asn1Encodeable;
 import org.apache.kerby.asn1.type.Asn1Type;
 import org.apache.kerby.kerberos.kerb.KrbCodec;
 import org.apache.kerby.kerberos.kerb.KrbException;
@@ -124,7 +124,7 @@ public class EncryptionUtil {
         return null;
     }
 
-    public static EncryptedData seal(Asn1Object asn1Type,
+    public static EncryptedData seal(Asn1Encodeable asn1Type,
                                      EncryptionKey key, KeyUsage usage) throws KrbException
{
         byte[] encoded = asn1Type.encode();
         EncryptedData encrypted = EncryptionHandler.encrypt(encoded, key, usage);


Mime
View raw message