directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [05/17] directory-kerby git commit: DIRKRB-474 Refined asn1 APIs, getting rid of the questionable encoding option; Made it more general, not too friendly to Kerberos, considering CMS & X509 types
Date Fri, 27 Nov 2015 08:18:15 GMT
DIRKRB-474 Refined asn1 APIs, getting rid of the questionable encoding option; Made it more
general, not too friendly to Kerberos, considering CMS & X509 types


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

Branch: refs/heads/pkinit-support
Commit: 1f4b21c8601602d511baffe8ba8c588abd560dcb
Parents: b7a062e
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Thu Nov 26 19:29:16 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Thu Nov 26 19:29:16 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/asn1/Asn1OutputBuffer.java |   5 -
 .../org/apache/kerby/asn1/EncodingOption.java   | 202 -------------------
 .../org/apache/kerby/asn1/TaggingOption.java    |   4 +-
 .../kerby/asn1/type/AbstractAsn1Type.java       | 148 +++++++++-----
 .../apache/kerby/asn1/type/Asn1BmpString.java   |   3 +-
 .../org/apache/kerby/asn1/type/Asn1Boolean.java |   2 +-
 .../org/apache/kerby/asn1/type/Asn1Choice.java  |   6 -
 .../apache/kerby/asn1/type/Asn1Collection.java  |   7 +-
 .../kerby/asn1/type/Asn1CollectionType.java     |   7 +-
 .../apache/kerby/asn1/type/Asn1EnumType.java    |  11 +-
 .../org/apache/kerby/asn1/type/Asn1Simple.java  |   7 +-
 .../org/apache/kerby/asn1/type/Asn1Tagging.java |  55 +++--
 .../org/apache/kerby/asn1/type/Asn1Type.java    |  96 ++++++++-
 .../kerby/asn1/type/TaggingCollection.java      |  82 ++++++--
 .../apache/kerby/asn1/type/TaggingSequence.java |   5 +-
 .../org/apache/kerby/asn1/type/TaggingSet.java  |   5 +-
 .../org/apache/kerby/asn1/PersonnelRecord.java  |  15 +-
 .../org/apache/kerby/asn1/TestAsn1Boolean.java  |   8 +-
 .../org/apache/kerby/asn1/TestAsn1Integer.java  |   4 +-
 .../kerby/asn1/TestAsn1ObjectIdentifier.java    |   4 +-
 .../org/apache/kerby/asn1/TestAsn1UtcTime.java  |   4 +-
 .../apache/kerby/asn1/TestTaggingEncoding.java  |  12 +-
 .../kerberos/kerb/spec/KrbAppSequenceType.java  |   2 +-
 23 files changed, 321 insertions(+), 373 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1OutputBuffer.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1OutputBuffer.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1OutputBuffer.java
index 76e4d2b..f50d092 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1OutputBuffer.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1OutputBuffer.java
@@ -40,11 +40,6 @@ public class Asn1OutputBuffer {
         objects.add(value);
     }
 
-    public void write(Asn1Type value, EncodingOption option) {
-        value.setEncodingOption(option);
-        objects.add(value);
-    }
-
     public ByteBuffer getOutput() {
         int len = encodingLength();
         ByteBuffer byteBuffer = ByteBuffer.allocate(len);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/EncodingOption.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/EncodingOption.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/EncodingOption.java
deleted file mode 100644
index d9627e0..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/EncodingOption.java
+++ /dev/null
@@ -1,202 +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;
-
-/**
- * A class used to hold the various encoding options for a type.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class EncodingOption {
-    /**
-     * Encoding type
-     */
-    protected static enum EncodingType {
-        BER,
-        DER,
-        CER;
-    }
-
-    private EncodingType encodingType;
-    private boolean isPrimitive;
-    private boolean isDefLen;
-    private boolean isImplicit;
-
-    /**
-     * The default constructor with default values.
-     */
-    public EncodingOption() {
-        this.encodingType = EncodingType.BER;
-        this.isPrimitive = true;
-        this.isImplicit = true;
-    }
-
-    /** 
-     * A mask to determinate if a Tag is CONSTRUCTED. The fifth bit should be set to 1 if
-     * the type is constructed (0010-0000).
-     */
-    public static final int CONSTRUCTED_FLAG = 0x20;
-
-    public static boolean isConstructed(int tag) {
-        return (tag & CONSTRUCTED_FLAG) != 0;
-    }
-
-    /**
-     * Use primitive.
-     */
-    public void usePrimitive() {
-        this.isPrimitive = true;
-    }
-
-    /**
-     * Tells if the EncodingOption is PRIMITIVE
-     * 
-     * @return true if using PRIMITIVE, false otherwise
-     */
-    public boolean isPrimitive() {
-        return this.isPrimitive;
-    }
-
-    /**
-     * Use constructed.
-     */
-    public void useConstructed() {
-        this.isPrimitive = false;
-        useNonDefLen();
-    }
-
-    /**
-     * Tells if it's constructed (not primitive).
-     * 
-     * @return true if it's constructed, false otherwise
-     */
-    public boolean isConstructed() {
-        return !isPrimitive;
-    }
-
-    /**
-     * Use definitive length, only makes sense when it's constructed.
-     */
-    public void useDefLen() {
-        if (isPrimitive()) {
-            throw new IllegalArgumentException("It's only for constructed");
-        }
-        this.isDefLen = true;
-    }
-
-    /**
-     * Use non-definitive length, only makes sense when it's constructed.
-     */
-    public void useNonDefLen() {
-        if (isPrimitive()) {
-            throw new IllegalArgumentException("It's only for constructed");
-        }
-        this.isDefLen = false;
-    }
-
-    /**
-     * Tells if it's definitive length or not.
-     * @return The boolean value
-     */
-    public boolean isDefLen() {
-        return this.isDefLen;
-    }
-
-    /**
-     * Use implicit, which will discard the value set by useExplicit.
-     */
-    public void useImplicit() {
-        this.isImplicit = true;
-    }
-
-    /**
-     * Tells if it's is IMPLICIT
-     * 
-     * @return true if using IMPLICIT, false otherwise
-     */
-    public boolean isImplicit() {
-        return isImplicit;
-    }
-
-    /**
-     * Use explicit, which will discard the value set by useImplicit.
-     */
-    public void useExplicit() {
-        this.isImplicit = false;
-    }
-
-    /**
-     * Tells if it's is EXPLICIT
-     * 
-     * @return true if using EXPLICIT, false otherwise
-     */
-    public boolean isExplicit() {
-        return !isImplicit;
-    }
-
-    /**
-     * Set encoding type as DER.
-     */
-    public void useDer() {
-        this.encodingType = EncodingType.DER;
-    }
-
-    /**
-     * Tells if it's is DER
-     * 
-     * @return true if using DER, false otherwise
-     */
-    public boolean isDer() {
-        return encodingType == EncodingType.DER;
-    }
-
-    /**
-     * Set encoding type as BER.
-     */
-    public void useBer() {
-        this.encodingType = EncodingType.BER;
-    }
-
-    /**
-     * Tells if it's is BER
-     *
-     * @return true if using BER, false otherwise
-     */
-    public boolean isBer() {
-        return encodingType == EncodingType.BER;
-    }
-
-    /**
-     * Set encoding type as CER.
-     */
-    public void useCer() {
-        this.encodingType = EncodingType.CER;
-    }
-
-    /**
-     * Tells if it's is CER
-     * 
-     * @return true if using CER, false otherwise
-     */
-    public boolean isCer() {
-        return encodingType == EncodingType.CER;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/TaggingOption.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/TaggingOption.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/TaggingOption.java
index f72d3e9..8bb0419 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/TaggingOption.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/TaggingOption.java
@@ -19,6 +19,8 @@
  */
 package org.apache.kerby.asn1;
 
+import org.apache.kerby.asn1.type.Asn1Type;
+
 /**
  * Tagging option for tagging an ASN1 type.
  */
@@ -83,7 +85,7 @@ public final class TaggingOption {
     public int tagFlags(boolean isTaggedConstructed) {
         boolean isConstructed = isImplicit ? isTaggedConstructed : true;
         TagClass tagClass = isAppSpecific ? TagClass.APPLICATION : TagClass.CONTEXT_SPECIFIC;
-        int flags = tagClass.getValue() | (isConstructed ? EncodingOption.CONSTRUCTED_FLAG
: 0x00);
+        int flags = tagClass.getValue() | (isConstructed ? Asn1Type.CONSTRUCTED_FLAG : 0x00);
 
         return flags;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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 74bf6e3..7446c7c 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
@@ -19,7 +19,6 @@
  */
 package org.apache.kerby.asn1.type;
 
-import org.apache.kerby.asn1.EncodingOption;
 import org.apache.kerby.asn1.LimitedByteBuffer;
 import org.apache.kerby.asn1.TagClass;
 import org.apache.kerby.asn1.TaggingOption;
@@ -34,14 +33,19 @@ import java.nio.ByteBuffer;
  * @param <T> the type of the value encoded/decoded or wrapped by this
  */
 public abstract class AbstractAsn1Type<T> implements Asn1Type {
+
     private TagClass tagClass = TagClass.UNKNOWN;
     private int tagNo = -1;
-    private int tagFlags = -1;
-    private EncodingOption encodingOption = new EncodingOption();
+    private int tagFlags = 0;
     private int encodingLen = -1;
     // The wrapped real value.
     private T value;
 
+    // encoding options
+    private EncodingType encodingType = EncodingType.BER;
+    private boolean isImplicit = true;
+    private boolean isDefinitiveLength = false;
+
     /**
      * Default constructor, generally for decoding as a value container
      * @param tagClass The tag class
@@ -81,22 +85,8 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
         this.tagClass = tagClass;
         this.tagNo = tagNo;
         this.value = value;
-    }
 
-    /**
-     * Set encoding option
-     * @param encodingOption The encoding option
-     */
-    public void setEncodingOption(EncodingOption encodingOption) {
-        this.encodingOption = encodingOption;
-    }
-
-    /**
-     * Get encoding option
-     * @return encoding option
-     */
-    public EncodingOption getEncodingOption() {
-        return this.encodingOption;
+        this.tagFlags |= tagClass.getValue();
     }
 
     public T getValue() {
@@ -107,10 +97,20 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
         this.value = value;
     }
 
-    protected TagClass tagClass() {
+    @Override
+    public TagClass tagClass() {
         return tagClass;
     }
 
+    protected void setTagClass(TagClass tagClass) {
+        this.tagClass = tagClass;
+    }
+
+    @Override
+    public int tagFlags() {
+        return tagFlags;
+    }
+
     @Override
     public int tagNo() {
         return tagNo;
@@ -125,6 +125,70 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
     }
 
     @Override
+    public void usePrimitive(boolean isPrimitive) {
+        if (isPrimitive) {
+            tagFlags &= ~CONSTRUCTED_FLAG;
+        } else {
+            tagFlags |= CONSTRUCTED_FLAG;
+        }
+    }
+
+    @Override
+    public boolean isPrimitive() {
+        return (tagFlags & CONSTRUCTED_FLAG) == 0;
+    }
+
+    @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);
@@ -152,18 +216,6 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
     }
 
     @Override
-    public int tagFlags() {
-        if (tagFlags == -1) {
-            int flags = tagClass.getValue();
-            if (isConstructed()) {
-                flags |= EncodingOption.CONSTRUCTED_FLAG;
-            }
-            return flags;
-        }
-        return tagFlags;
-    }
-
-    @Override
     public int encodingLength() {
         if (encodingLen == -1) {
             int bodyLen = encodingBodyLength();
@@ -172,14 +224,6 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
         return encodingLen;
     }
 
-    public boolean isConstructed() {
-        if (tagFlags != -1) {
-            return (tagFlags & EncodingOption.CONSTRUCTED_FLAG) != 0;
-        } else {
-            return false;
-        }
-    }
-
     public boolean isUniversal() {
         return tagClass.isUniversal();
     }
@@ -209,27 +253,27 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type
{
     protected void decode(LimitedByteBuffer content) throws IOException {
         int tag = readTag(content);
         int tagNo = readTagNo(content, tag);
-        int tagFlags = tag & 0xe0;
+        int tmpTagFlags = tag & 0xe0;
         int length = readLength(content);
 
-        decode(tagFlags, tagNo, new LimitedByteBuffer(content, length));
+        decode(tmpTagFlags, tagNo, new LimitedByteBuffer(content, length));
     }
 
     public void decode(int tagFlags, int tagNo,
                        LimitedByteBuffer content) throws IOException {
-        if (this.tagClass != TagClass.UNKNOWN && this.tagClass
+        if (tagClass() != TagClass.UNKNOWN && tagClass()
                 != TagClass.fromTagFlags(tagFlags)) {
             throw new IOException("Unexpected tagFlags " + tagFlags
-                    + ", expecting " + this.tagClass);
+                    + ", expecting " + tagClass());
         }
-        if (this.tagNo != -1 && this.tagNo != tagNo) {
+        if (tagNo() != -1 && tagNo() != tagNo) {
             throw new IOException("Unexpected tagNo " + tagNo + ", "
-                    + "expecting " + this.tagNo);
+                    + "expecting " + tagNo());
         }
 
-        this.tagClass = TagClass.fromTagFlags(tagFlags);
-        this.tagFlags = tagFlags;
-        this.tagNo = tagNo;
+        setTagClass(TagClass.fromTagFlags(tagFlags));
+        setTagFlags(tagFlags);
+        setTagNo(tagNo);
 
         decodeBody(content);
     }
@@ -254,7 +298,7 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
 
     @Override
     public void taggedEncode(ByteBuffer buffer, TaggingOption taggingOption) {
-        int taggingTagFlags = taggingOption.tagFlags(isConstructed());
+        int taggingTagFlags = taggingOption.tagFlags(!isPrimitive());
         encodeTag(buffer, taggingTagFlags, taggingOption.getTagNo());
         int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength()
                 : encodingLength();
@@ -285,14 +329,14 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type
{
         int taggingLength = readLength(content);
         LimitedByteBuffer newContent = new LimitedByteBuffer(content, taggingLength);
 
-        int tagFlags = taggingTag & 0xe0;
-        taggedDecode(tagFlags, taggingTagNo, newContent, taggingOption);
+        int tmpTagFlags = taggingTag & 0xe0;
+        taggedDecode(tmpTagFlags, taggingTagNo, newContent, taggingOption);
     }
 
     protected void taggedDecode(int taggingTagFlags, int taggingTagNo,
                                 LimitedByteBuffer content,
                                 TaggingOption taggingOption) throws IOException {
-        int expectedTaggingTagFlags = taggingOption.tagFlags(isConstructed());
+        int expectedTaggingTagFlags = taggingOption.tagFlags(!isPrimitive());
         if (expectedTaggingTagFlags != taggingTagFlags) {
             throw new IOException("Unexpected tag flags " + taggingTagFlags
                     + ", expecting " + expectedTaggingTagFlags);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BmpString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BmpString.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BmpString.java
index 4949be0..5f1712d 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BmpString.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BmpString.java
@@ -19,7 +19,6 @@
  */
 package org.apache.kerby.asn1.type;
 
-import org.apache.kerby.asn1.EncodingOption;
 import org.apache.kerby.asn1.LimitedByteBuffer;
 import org.apache.kerby.asn1.UniversalTag;
 
@@ -39,7 +38,7 @@ public class Asn1BmpString extends Asn1Simple<String> {
         return getValue().length() * 2;
     }
 
-    protected void toBytes(EncodingOption encodingOption) {
+    protected void toBytes() {
         String strValue = getValue();
         int len = strValue.length();
         byte[] bytes = new byte[len * 2];

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Boolean.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Boolean.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Boolean.java
index 3b70e52..7b9be41 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Boolean.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Boolean.java
@@ -75,7 +75,7 @@ public class Asn1Boolean extends Asn1Simple<Boolean> {
         } else if ((bytes[0] & 0xff) == 0xff) {
             // DER only accepts 0xFF as true
             setValue(true);
-        } else if (getEncodingOption().isBer()) {
+        } else if (isBER()) {
             // BER accepts any non-zero as true
             setValue(true);
         } else {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
index 77116fc..e251e11 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
@@ -37,12 +37,6 @@ public class Asn1Choice extends AbstractAsn1Type<Asn1Type> {
         setValue(this);
         this.fieldInfos = fieldInfos.clone();
         this.fields = new Asn1Type[fieldInfos.length];
-        getEncodingOption().useConstructed();
-    }
-
-    @Override
-    public boolean isConstructed() {
-        return true;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Collection.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Collection.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Collection.java
index af7fbd2..54a2e9d 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Collection.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Collection.java
@@ -35,12 +35,7 @@ public class Asn1Collection extends AbstractAsn1Type<List<Asn1Item>>
{
     public Asn1Collection(TagClass tagClass, int tagNo) {
         super(tagClass, tagNo);
         setValue(new ArrayList<Asn1Item>());
-        getEncodingOption().useConstructed();
-    }
-
-    @Override
-    public boolean isConstructed() {
-        return true;
+        usePrimitive(false);
     }
 
     public void addItem(Asn1Type value) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
index 194ae8c..2fdb34b 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
@@ -38,12 +38,7 @@ public abstract class Asn1CollectionType extends AbstractAsn1Type<Asn1Collection
         setValue(this);
         this.fieldInfos = fieldInfos.clone();
         this.fields = new Asn1Type[fieldInfos.length];
-        getEncodingOption().useConstructed();
-    }
-
-    @Override
-    public boolean isConstructed() {
-        return true;
+        usePrimitive(false);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1EnumType.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1EnumType.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1EnumType.java
index 42eabc6..12e5e65 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1EnumType.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1EnumType.java
@@ -6,19 +6,22 @@
  *  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. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.kerby.asn1.type;
 
+/**
+ * A helper interface used by Asn1Enumerated.
+ */
 public interface Asn1EnumType {
     int getIntValue();
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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 877c2f3..deb2de8 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
@@ -47,7 +47,7 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
      */
     public Asn1Simple(UniversalTag tagNo, T value) {
         super(TagClass.UNIVERSAL, tagNo.getValue(), value);
-        getEncodingOption().usePrimitive();
+        usePrimitive(true);
     }
 
     protected byte[] getBytes() {
@@ -100,11 +100,6 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
         }
     }
 
-    @Override
-    public boolean isConstructed() {
-        return false;
-    }
-
     protected void toValue() throws IOException { }
 
     protected void toBytes() { }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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 d9c0d28..dd7d394 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
@@ -31,65 +31,56 @@ import java.nio.ByteBuffer;
  */
 public class Asn1Tagging<T extends Asn1Type> extends AbstractAsn1Type<T> {
 
-    public Asn1Tagging(boolean isAppSpecific) {
-        this(-1, null, isAppSpecific);
-    }
-
-    public Asn1Tagging(int tagNo, T value, boolean isAppSpecific) {
-        super(isAppSpecific ? TagClass.APPLICATION : TagClass.CONTEXT_SPECIFIC, tagNo, value);
-        getEncodingOption().useExplicit();
+    public Asn1Tagging(int tagNo, T value,
+                       boolean isAppSpecific, boolean isImplicit) {
+        super(isAppSpecific ? TagClass.APPLICATION : TagClass.CONTEXT_SPECIFIC,
+            tagNo, value);
         if (value == null) {
             initValue();
         }
+        useImplicit(isImplicit);
     }
 
     @Override
-    protected int encodingBodyLength() {
-        AbstractAsn1Type<?> value = (AbstractAsn1Type<?>) getValue();
-        if (getEncodingOption().isExplicit()) {
-            return value.encodingLength();
-        } else if (getEncodingOption().isImplicit()) {
-            return value.encodingBodyLength();
+    public void useImplicit(boolean isImplicit) {
+        super.useImplicit(isImplicit);
+
+        if (!isImplicit) {
+            //In effect, explicitly tagged types are structured types consisting
+            // of one component, the underlying type.
+            super.usePrimitive(false);
         } else {
-            throw new RuntimeException("Invalid decoding option, "
-                    + "only allowing explicit/implicit");
+            super.usePrimitive(getValue().isPrimitive());
         }
     }
 
     @Override
-    public boolean isConstructed() {
-        if (getEncodingOption().isExplicit()) {
-            return true;
-        } else if (getEncodingOption().isImplicit()) {
-            AbstractAsn1Type<?> value = (AbstractAsn1Type<?>) getValue();
-            return value.isConstructed();
+    protected int encodingBodyLength() {
+        AbstractAsn1Type<?> value = (AbstractAsn1Type<?>) getValue();
+        if (isImplicit()) {
+            return value.encodingBodyLength();
+        } else {
+            return value.encodingLength();
         }
-        return false;
     }
 
     @Override
     protected void encodeBody(ByteBuffer buffer) {
         AbstractAsn1Type<?> value = (AbstractAsn1Type<?>) getValue();
-        if (getEncodingOption().isExplicit()) {
-            value.encode(buffer);
-        } else if (getEncodingOption().isImplicit()) {
+        if (isImplicit()) {
             value.encodeBody(buffer);
         } else {
-            throw new RuntimeException("Invalid decoding option, "
-                    + "only allowing explicit/implicit");
+            value.encode(buffer);
         }
     }
 
     @Override
     protected void decodeBody(LimitedByteBuffer content) throws IOException {
         AbstractAsn1Type<?> value = (AbstractAsn1Type<?>) getValue();
-        if (getEncodingOption().isExplicit()) {
-            value.decode(content);
-        } else if (getEncodingOption().isImplicit()) {
+        if (isImplicit()) {
             value.decodeBody(content);
         } else {
-            throw new RuntimeException("Invalid decoding option, "
-                    + "only allowing explicit/implicit");
+            value.decode(content);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java
index c77418b..271e795 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java
@@ -19,7 +19,7 @@
  */
 package org.apache.kerby.asn1.type;
 
-import org.apache.kerby.asn1.EncodingOption;
+import org.apache.kerby.asn1.TagClass;
 import org.apache.kerby.asn1.TaggingOption;
 
 import java.io.IOException;
@@ -30,6 +30,27 @@ import java.nio.ByteBuffer;
  */
 public interface Asn1Type {
     /**
+     * A mask to determinate if a Tag is CONSTRUCTED. The fifth bit should be
+     * set to 1 if the type is constructed (0010-0000).
+     */
+    int CONSTRUCTED_FLAG = 0x20;
+
+    /**
+     * Encoding type
+     */
+    enum EncodingType {
+        BER,
+        DER,
+        CER;
+    }
+
+    /**
+     *
+     * @return The tag class
+     */
+    TagClass tagClass();
+
+    /**
      *
      * @return The tag flags
      */
@@ -42,11 +63,76 @@ public interface Asn1Type {
     int tagNo();
 
     /**
-     * Set encoding option.
-     * See {@link org.apache.kerby.asn1.EncodingOption}.
-     * @param encodingOption The encoding option
+     * Use primitive or constructed.
+     */
+    void usePrimitive(boolean isPrimitive);
+
+    /**
+     * Tells if it is PRIMITIVE or not.
+     *
+     * @return true if using PRIMITIVE, false otherwise
+     */
+    boolean isPrimitive();
+
+    /**
+     * Use definitive length or not.
+     * Note definitive length only makes sense when it's constructed.
+     */
+    void useDefinitiveLength(boolean isDefinitiveLength);
+
+    /**
+     * Tells if it's definitive length or not.
+     * @return The boolean value
+     */
+    boolean isDefinitiveLength();
+
+    /**
+     * Use implicit or not.
+     */
+    void useImplicit(boolean isImplicit);
+
+    /**
+     * Tells if it's is IMPLICIT or not.
+     *
+     * @return true if using IMPLICIT, false otherwise
+     */
+    boolean isImplicit();
+
+    /**
+     * Set encoding type as DER.
+     */
+    void useDER();
+
+    /**
+     * Tells if it's is DER
+     *
+     * @return true if using DER, false otherwise
+     */
+    boolean isDER();
+
+    /**
+     * Set encoding type as BER.
+     */
+    void useBER();
+
+    /**
+     * Tells if it's is BER
+     *
+     * @return true if using BER, false otherwise
+     */
+    boolean isBER();
+
+    /**
+     * Set encoding type as CER.
+     */
+    void useCER();
+
+    /**
+     * Tells if it's is CER
+     *
+     * @return true if using CER, false otherwise
      */
-    void setEncodingOption(EncodingOption encodingOption);
+    boolean isCER();
 
     /**
      * Get length of encoding bytes by just calculating without real encoding.

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingCollection.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingCollection.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingCollection.java
index d316b7b..1d810a3 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingCollection.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingCollection.java
@@ -19,7 +19,6 @@
  */
 package org.apache.kerby.asn1.type;
 
-import org.apache.kerby.asn1.EncodingOption;
 import org.apache.kerby.asn1.LimitedByteBuffer;
 import org.apache.kerby.asn1.TagClass;
 
@@ -27,38 +26,97 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 
 /**
- * For tagging a collection type with tagNo, either application specific or context specific
class
+ * For tagging a collection type with tagNo, either application specific or
+ * context specific class
  */
 public abstract class TaggingCollection extends AbstractAsn1Type<Asn1CollectionType>
{
     private Asn1Tagging<Asn1CollectionType> tagging;
     private Asn1CollectionType tagged;
 
-    public TaggingCollection(int taggingTagNo, Asn1FieldInfo[] tags, boolean isAppSpecific)
{
-        super(isAppSpecific ? TagClass.APPLICATION : TagClass.CONTEXT_SPECIFIC, taggingTagNo);
+    public TaggingCollection(int taggingTagNo, Asn1FieldInfo[] tags,
+                             boolean isAppSpecific, boolean isImplicit) {
+        super(isAppSpecific ? TagClass.APPLICATION : TagClass.CONTEXT_SPECIFIC,
+            taggingTagNo);
         this.tagged = createTaggedCollection(tags);
         setValue(tagged);
-        this.tagging = new Asn1Tagging<Asn1CollectionType>(taggingTagNo, tagged, isAppSpecific);
-        getEncodingOption().useExplicit();
+        this.tagging = new Asn1Tagging<Asn1CollectionType>(taggingTagNo,
+            tagged, isAppSpecific, isImplicit);
     }
 
     protected abstract Asn1CollectionType createTaggedCollection(Asn1FieldInfo[] tags);
 
     @Override
-    public void setEncodingOption(EncodingOption encodingOption) {
-        tagging.setEncodingOption(encodingOption);
+    public int tagFlags() {
+        return tagging.tagFlags();
     }
 
     @Override
-    public EncodingOption getEncodingOption() {
-        return tagging.getEncodingOption();
+    public int tagNo() {
+        return tagging.tagNo();
     }
 
     @Override
-    public boolean isConstructed() {
-        return tagging.isConstructed();
+    public void usePrimitive(boolean isPrimitive) {
+        tagging.usePrimitive(isPrimitive);
     }
 
     @Override
+    public boolean isPrimitive() {
+        return tagging.isPrimitive();
+    }
+
+    @Override
+    public void useDefinitiveLength(boolean isDefinitiveLength) {
+        tagging.useDefinitiveLength(isDefinitiveLength);
+    }
+
+    @Override
+    public boolean isDefinitiveLength() {
+        return tagging.isDefinitiveLength();
+    }
+
+    @Override
+    public void useImplicit(boolean isImplicit) {
+        tagging.useImplicit(isImplicit);
+    }
+
+    @Override
+    public boolean isImplicit() {
+        return tagging.isImplicit();
+    }
+
+    @Override
+    public void useDER() {
+        tagging.useDER();
+    }
+
+    @Override
+    public boolean isDER() {
+        return tagging.isDER();
+    }
+
+    @Override
+    public void useBER() {
+        tagging.useBER();
+    }
+
+    @Override
+    public boolean isBER() {
+        return tagging.isBER();
+    }
+
+    @Override
+    public void useCER() {
+        tagging.useCER();
+    }
+
+    @Override
+    public boolean isCER() {
+        return tagging.isCER();
+    }
+
+
+    @Override
     protected int encodingBodyLength() {
         return tagging.encodingBodyLength();
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSequence.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSequence.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSequence.java
index 90ecaed..eab2aaf 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSequence.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSequence.java
@@ -24,8 +24,9 @@ package org.apache.kerby.asn1.type;
  */
 public class TaggingSequence extends TaggingCollection {
 
-    public TaggingSequence(int taggingTagNo, Asn1FieldInfo[] tags, boolean isAppSpecific)
{
-        super(taggingTagNo, tags, isAppSpecific);
+    public TaggingSequence(int taggingTagNo, Asn1FieldInfo[] tags,
+                           boolean isAppSpecific, boolean isImplicit) {
+        super(taggingTagNo, tags, isAppSpecific, isImplicit);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSet.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSet.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSet.java
index c4807d0..444102b 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSet.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/TaggingSet.java
@@ -24,8 +24,9 @@ package org.apache.kerby.asn1.type;
  */
 public class TaggingSet extends TaggingCollection {
 
-    public TaggingSet(int taggingTagNo, Asn1FieldInfo[] tags, boolean isAppSpecific) {
-        super(taggingTagNo, tags, isAppSpecific);
+    public TaggingSet(int taggingTagNo, Asn1FieldInfo[] tags,
+                      boolean isAppSpecific, boolean isImplicit) {
+        super(taggingTagNo, tags, isAppSpecific, isImplicit);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
index a5c10f8..cee7d3b 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
@@ -51,8 +51,7 @@ public class PersonnelRecord extends TaggingSet {
     };
 
     public PersonnelRecord() {
-        super(0, fieldInfos, true);
-        getEncodingOption().useImplicit();
+        super(0, fieldInfos, true, true);
     }
 
     public void setName(Name name) {
@@ -158,8 +157,7 @@ public class PersonnelRecord extends TaggingSet {
         };
 
         public Name() {
-            super(1, tags, true);
-            getEncodingOption().useImplicit();
+            super(1, tags, true, true);
         }
 
         public Name(String givenName, String initial, String familyName) {
@@ -196,20 +194,17 @@ public class PersonnelRecord extends TaggingSet {
 
     public static class EmployeeNumber extends Asn1Tagging<Asn1Integer> {
         public EmployeeNumber(Integer value) {
-            super(2, new Asn1Integer(value), true);
-            getEncodingOption().useImplicit();
+            super(2, new Asn1Integer(value), true, true);
         }
 
         public EmployeeNumber() {
-            super(2, new Asn1Integer(), true);
-            getEncodingOption().useImplicit();
+            super(2, new Asn1Integer(), true, true);
         }
     }
 
     public static class Date extends Asn1Tagging<Asn1VisibleString> {
         public Date(String value) {
-            super(3, new Asn1VisibleString(value), true);
-            getEncodingOption().useImplicit();
+            super(3, new Asn1VisibleString(value), true, true);
         }
         public Date() {
             this(null);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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
index 947f30f..177ddef 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
@@ -39,9 +39,9 @@ public class TestAsn1Boolean {
         byte[] expected = Util.hex2bytes(expectedEncoding);
         Asn1Boolean aValue = new Asn1Boolean(value);
         if (isDer) {
-            aValue.getEncodingOption().useDer();
+            aValue.useDER();
         } else {
-            aValue.getEncodingOption().useBer();
+            aValue.useBER();
         }
         byte[] encodingBytes = aValue.encode();
         assertThat(encodingBytes).isEqualTo(expected);
@@ -59,9 +59,9 @@ public class TestAsn1Boolean {
                                   boolean isDer) throws IOException {
         Asn1Boolean decoded = new Asn1Boolean();
         if (isDer) {
-            decoded.getEncodingOption().useDer();
+            decoded.useDER();
         } else {
-            decoded.getEncodingOption().useBer();
+            decoded.useBER();
         }
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue()).isEqualTo(expectedValue);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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
index f9a774e..8eb4b4d 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
@@ -44,7 +44,7 @@ public class TestAsn1Integer {
     private void testEncodingWith(int value, String expectedEncoding) {
         byte[] expected = Util.hex2bytes(expectedEncoding);
         Asn1Integer aValue = new Asn1Integer(value);
-        aValue.getEncodingOption().useDer();
+        aValue.useDER();
         byte[] encodingBytes = aValue.encode();
         assertThat(encodingBytes).isEqualTo(expected);
     }
@@ -64,7 +64,7 @@ public class TestAsn1Integer {
 
     private void testDecodingWith(int expectedValue, String content) throws IOException {
         Asn1Integer decoded = new Asn1Integer();
-        decoded.getEncodingOption().useDer();
+        decoded.useDER();
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue().intValue()).isEqualTo(expectedValue);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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
index cb97922..726c23e 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
@@ -45,7 +45,7 @@ public class TestAsn1ObjectIdentifier {
     private void testEncodingWith(String oid, String expectedEncoding) {
         byte[] expected = Util.hex2bytes(expectedEncoding);
         Asn1ObjectIdentifier aValue = new Asn1ObjectIdentifier(oid);
-        aValue.getEncodingOption().useDer();
+        aValue.useDER();
         byte[] encodingBytes = aValue.encode();
         assertThat(encodingBytes).isEqualTo(expected);
     }
@@ -58,7 +58,7 @@ public class TestAsn1ObjectIdentifier {
 
     private void testDecodingWith(String expectedValue, String content) throws IOException
{
         Asn1ObjectIdentifier decoded = new Asn1ObjectIdentifier();
-        decoded.getEncodingOption().useDer();
+        decoded.useDER();
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue()).isEqualTo(expectedValue);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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
index 6d4d2a2..ebc1509 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
@@ -48,7 +48,7 @@ public class TestAsn1UtcTime {
     private void testEncodingWith(Date value, String expectedEncoding) {
         byte[] expected = Util.hex2bytes(expectedEncoding);
         Asn1UtcTime aValue = new Asn1UtcTime(value);
-        aValue.getEncodingOption().useDer();
+        aValue.useDER();
         byte[] encodingBytes = aValue.encode();
         assertThat(encodingBytes).isEqualTo(expected);
     }
@@ -64,7 +64,7 @@ public class TestAsn1UtcTime {
 
     private void testDecodingWith(Date expectedValue, String content) throws IOException
{
         Asn1UtcTime decoded = new Asn1UtcTime();
-        decoded.getEncodingOption().useDer();
+        decoded.useDER();
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue()).isEqualTo(expectedValue);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/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
index 26fb3a2..6956b46 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestTaggingEncoding.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestTaggingEncoding.java
@@ -87,8 +87,7 @@ public class TestTaggingEncoding {
 
     public static class Type2 extends Asn1Tagging<Type1> {
         public Type2(Type1 value) {
-            super(3, value, true);
-            getEncodingOption().useImplicit();
+            super(3, value, true, true);
         }
         public Type2() {
             this(null);
@@ -97,8 +96,7 @@ public class TestTaggingEncoding {
 
     public static class Type3 extends Asn1Tagging<Type2> {
         public Type3(Type2 value) {
-            super(2, value, false);
-            getEncodingOption().useExplicit();
+            super(2, value, false, false);
         }
         public Type3() {
             this(null);
@@ -107,8 +105,7 @@ public class TestTaggingEncoding {
 
     public static class Type4 extends Asn1Tagging<Type3> {
         public Type4(Type3 value) {
-            super(7, value, true);
-            getEncodingOption().useImplicit();
+            super(7, value, true, true);
         }
         public Type4() {
             this(null);
@@ -117,8 +114,7 @@ public class TestTaggingEncoding {
 
     public static class Type5 extends Asn1Tagging<Type2> {
         public Type5(Type2 value) {
-            super(2, value, false);
-            getEncodingOption().useImplicit();
+            super(2, value, false, true);
         }
         public Type5() {
             this(null);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1f4b21c8/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbAppSequenceType.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbAppSequenceType.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbAppSequenceType.java
index 05e87f1..6e4e1bd 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbAppSequenceType.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbAppSequenceType.java
@@ -28,7 +28,7 @@ import org.apache.kerby.asn1.type.TaggingSequence;
  */
 public abstract class KrbAppSequenceType extends TaggingSequence {
     public KrbAppSequenceType(int tagNo, Asn1FieldInfo[] fieldInfos) {
-        super(tagNo, fieldInfos, true);
+        super(tagNo, fieldInfos, true, false); // Kerberos favors explicit
     }
 
     protected int getFieldAsInt(int index) {


Mime
View raw message