directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [27/30] directory-kerberos git commit: DIRKRB-158. Decouple the mixed aspects in EncodingOption in kerby-asn1
Date Mon, 09 Feb 2015 06:28:08 GMT
DIRKRB-158. Decouple the mixed aspects in EncodingOption in kerby-asn1


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

Branch: refs/heads/installation
Commit: 57e75f088d489b37f8480924cbb83d58ccdc24a4
Parents: 44a42d1
Author: Drankye <drankye@gmail.com>
Authored: Mon Feb 9 11:13:08 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Mon Feb 9 11:13:08 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/asn1/EncodingOption.java   | 185 ++++++++++++-------
 .../kerby/asn1/type/AbstractAsn1Type.java       |  42 +++--
 .../org/apache/kerby/asn1/type/Asn1Choice.java  |   2 +-
 .../apache/kerby/asn1/type/Asn1Collection.java  |   2 +-
 .../kerby/asn1/type/Asn1CollectionType.java     |   2 +-
 .../org/apache/kerby/asn1/type/Asn1Simple.java  |   3 +-
 .../org/apache/kerby/asn1/type/Asn1Tagging.java |  11 +-
 .../kerby/asn1/type/TaggingCollection.java      |   8 +-
 .../org/apache/kerby/asn1/PersonnelRecord.java  |  10 +-
 .../org/apache/kerby/asn1/TestAsn1Boolean.java  |  14 +-
 .../org/apache/kerby/asn1/TestAsn1Integer.java  |   4 +-
 .../kerby/asn1/TestAsn1ObjectIdentifier.java    |   4 +-
 .../org/apache/kerby/asn1/TestAsn1UtcTime.java  |   4 +-
 .../apache/kerby/asn1/TestTaggingEncoding.java  |  25 ++-
 .../kerby/kerberos/kerb/codec/KrbCodec.java     |   4 +-
 15 files changed, 204 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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
index bac3d19..0308065 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/EncodingOption.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/EncodingOption.java
@@ -21,20 +21,32 @@ package org.apache.kerby.asn1;
 
 /**
  * An enum used to represent the various Encoding options.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public enum EncodingOption {
-    UNKNOWN(-1),
-    PRIMITIVE(1),
-    CONSTRUCTED(2),
-    CONSTRUCTED_DEFLEN(3),
-    CONSTRUCTED_INDEFLEN(4),
-    IMPLICIT(5),
-    EXPLICIT(6),
-    BER(7),
-    DER(8),
-    CER(9);
+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
@@ -42,24 +54,15 @@ public enum EncodingOption {
      */
     public static int CONSTRUCTED_FLAG = 0x20;
 
-    /** The associated value */
-    private int value;
-
-    /** Create a instance of EncodingOption */
-    private EncodingOption(int value) {
-        this.value = value;
+    public static boolean isConstructed(int tag) {
+        return (tag & CONSTRUCTED_FLAG) != 0;
     }
 
-
     /**
-     * @return The integer value associated with the EncodingOption instance
+     * Use primitive.
      */
-    public int getValue() {
-        return value;
-    }
-
-    public static boolean isConstructed(int tag) {
-        return (tag & CONSTRUCTED_FLAG) != 0;
+    public void usePrimitive() {
+        this.isPrimitive = true;
     }
 
     /**
@@ -68,82 +71,132 @@ public enum EncodingOption {
      * @return true if using PRIMITIVE, false otherwise
      */
     public boolean isPrimitive() {
-        return this == PRIMITIVE;
+        return this.isPrimitive;
     }
 
     /**
-     * Tells if the EncodingOption is for an encoded type (CONSTRUCTED, CONSTRUCTED_DEFLEN
-     * or CONSTRUCTED_INDEFLEN)
+     * Use constructed.
+     */
+    public void useConstructed() {
+        this.isPrimitive = false;
+        useNonDefLen();
+    }
+
+    /**
+     * Tells if it's constructed (not primitive).
      * 
-     * @return true if the EncodingOption is CONSTRUCTED, false otherwise
+     * @return true if it's constructed, false otherwise
      */
     public boolean isConstructed() {
-        return this == CONSTRUCTED || this == CONSTRUCTED_DEFLEN || this == CONSTRUCTED_INDEFLEN;
+        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 the EncodingOption is IMPLICIT
+     * Tells if it's definitive length or not.
+     * @return
+     */
+    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 this == IMPLICIT;
+        return isImplicit;
+    }
+
+    /**
+     * Use explicit, which will discard the value set by useImplicit.
+     */
+    public void useExplicit() {
+        this.isImplicit = false;
     }
 
     /**
-     * Tells if the EncodingOption is EXPLICIT
+     * Tells if it's is EXPLICIT
      * 
      * @return true if using EXPLICIT, false otherwise
      */
     public boolean isExplicit() {
-        return this == EXPLICIT;
+        return ! isImplicit;
+    }
+
+    /**
+     * Set encoding type as DER.
+     */
+    public void useDer() {
+        this.encodingType = EncodingType.DER;
     }
 
     /**
-     * Tells if the EncodingOption is DER
+     * Tells if it's is DER
      * 
      * @return true if using DER, false otherwise
      */
     public boolean isDer() {
-        return this == DER;
+        return encodingType == EncodingType.DER;
     }
 
     /**
-     * Tells if the EncodingOption is CER
-     * 
-     * @return true if using CER, false otherwise
+     * Set encoding type as BER.
      */
-    public boolean isCer() {
-        return this == CER;
+    public void useBer() {
+        this.encodingType = EncodingType.BER;
     }
 
     /**
-     * Tells if the EncodingOption is BER
-     * 
+     * Tells if it's is BER
+     *
      * @return true if using BER, false otherwise
      */
     public boolean isBer() {
-        return this == BER;
-    }
-
-    
-    /**
-     * Get the EncodingOption given an integer value
-     * @param value The value to translate
-     * @return The associated EncodingOption
-     */
-    public static EncodingOption fromValue(int value) {
-        switch (value) {
-            case 1 : return PRIMITIVE;
-            case 2 : return CONSTRUCTED;
-            case 3 : return CONSTRUCTED_DEFLEN;
-            case 4 : return CONSTRUCTED_INDEFLEN;
-            case 5 : return IMPLICIT;
-            case 6 : return EXPLICIT;
-            case 7 : return BER;
-            case 8 : return DER;
-            case 9 : return CER;
-            default : return UNKNOWN;
-        }
+        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-kerberos/blob/57e75f08/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 a00591d..bf0ec9b 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
@@ -38,7 +38,7 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
     private TagClass tagClass = TagClass.UNKNOWN;
     private int tagNo = -1;
     private int tagFlags = -1;
-    private EncodingOption encodingOption = EncodingOption.BER;
+    private EncodingOption encodingOption = new EncodingOption();
     private int encodingLen = -1;
     // The wrapped real value.
     private T value;
@@ -214,12 +214,16 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type
{
         decode(tag, tagNo, new LimitedByteBuffer(content, length));
     }
 
-    public void decode(int tagFlags, int tagNo, LimitedByteBuffer content) throws IOException
{
-        if (this.tagClass != TagClass.UNKNOWN && this.tagClass != TagClass.fromTagFlags(tagFlags))
{
-            throw new IOException("Unexpected tagFlags " + tagFlags + ", expecting " + this.tagClass);
+    public void decode(int tagFlags, int tagNo,
+                       LimitedByteBuffer content) throws IOException {
+        if (this.tagClass != TagClass.UNKNOWN && this.tagClass !=
+                TagClass.fromTagFlags(tagFlags)) {
+            throw new IOException("Unexpected tagFlags " + tagFlags +
+                    ", expecting " + this.tagClass);
         }
         if (this.tagNo != -1 && this.tagNo != tagNo) {
-            throw new IOException("Unexpected tagNo " + tagNo + ", expecting " + this.tagNo);
+            throw new IOException("Unexpected tagNo " + tagNo + ", " +
+                    "expecting " + this.tagNo);
         }
 
         this.tagClass = TagClass.fromTagFlags(tagFlags);
@@ -233,8 +237,10 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
 
     protected int taggedEncodingLength(TaggingOption taggingOption) {
         int taggingTagNo = taggingOption.getTagNo();
-        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength() : encodingLength();
-        int taggingEncodingLen = lengthOfTagLength(taggingTagNo) + lengthOfBodyLength(taggingBodyLen)
+ taggingBodyLen;
+        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength() :
+                encodingLength();
+        int taggingEncodingLen = lengthOfTagLength(taggingTagNo) +
+                lengthOfBodyLength(taggingBodyLen) + taggingBodyLen;
         return taggingEncodingLen;
     }
 
@@ -249,7 +255,8 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type {
     public void taggedEncode(ByteBuffer buffer, TaggingOption taggingOption) {
         int taggingTagFlags = taggingOption.tagFlags(isConstructed());
         encodeTag(buffer, taggingTagFlags, taggingOption.getTagNo());
-        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength() : encodingLength();
+        int taggingBodyLen = taggingOption.isImplicit() ? encodingBodyLength() :
+                encodingLength();
         encodeLength(buffer, taggingBodyLen);
         if (taggingOption.isImplicit()) {
             encodeBody(buffer);
@@ -258,17 +265,20 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type
{
         }
     }
 
-    public void taggedDecode(byte[] content, TaggingOption taggingOption) throws IOException
{
+    public void taggedDecode(byte[] content,
+                             TaggingOption taggingOption) throws IOException {
         taggedDecode(ByteBuffer.wrap(content), taggingOption);
     }
 
     @Override
-    public void taggedDecode(ByteBuffer content, TaggingOption taggingOption) throws IOException
{
+    public void taggedDecode(ByteBuffer content,
+                             TaggingOption taggingOption) throws IOException {
         LimitedByteBuffer limitedBuffer = new LimitedByteBuffer(content);
         taggedDecode(limitedBuffer, taggingOption);
     }
 
-    protected void taggedDecode(LimitedByteBuffer content, TaggingOption taggingOption) throws
IOException {
+    protected void taggedDecode(LimitedByteBuffer content,
+                                TaggingOption taggingOption) throws IOException {
         int taggingTag = readTag(content);
         int taggingTagNo = readTagNo(content, taggingTag);
         int taggingLength = readLength(content);
@@ -278,13 +288,17 @@ public abstract class AbstractAsn1Type<T> implements Asn1Type
{
         taggedDecode(tagFlags, taggingTagNo, newContent, taggingOption);
     }
 
-    protected void taggedDecode(int taggingTagFlags, int taggingTagNo, LimitedByteBuffer
content, TaggingOption taggingOption) throws IOException {
+    protected void taggedDecode(int taggingTagFlags, int taggingTagNo,
+                                LimitedByteBuffer content,
+                                TaggingOption taggingOption) throws IOException {
         int expectedTaggingTagFlags = taggingOption.tagFlags(isConstructed());
         if (expectedTaggingTagFlags != taggingTagFlags) {
-            throw new IOException("Unexpected tag flags" + taggingTagFlags + ", expecting
" + expectedTaggingTagFlags);
+            throw new IOException("Unexpected tag flags " + taggingTagFlags +
+                    ", expecting " + expectedTaggingTagFlags);
         }
         if (taggingOption.getTagNo() != taggingTagNo) {
-            throw new IOException("Unexpected tagNo " + taggingTagNo + ", expecting " + taggingOption.getTagNo());
+            throw new IOException("Unexpected tagNo " + taggingTagNo + ", " +
+                    "expecting " + taggingOption.getTagNo());
         }
 
         if (taggingOption.isImplicit()) {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 69b1fd6..7c65e7c 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
@@ -34,7 +34,7 @@ public class Asn1Choice extends AbstractAsn1Type<Asn1Type> {
         setValue(this);
         this.fieldInfos = fieldInfos;
         this.fields = new Asn1Type[fieldInfos.length];
-        setEncodingOption(EncodingOption.CONSTRUCTED);
+        getEncodingOption().useConstructed();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 5ea02f1..796092e 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
@@ -36,7 +36,7 @@ public class Asn1Collection extends AbstractAsn1Type<List<Asn1Item>>
{
     public Asn1Collection(TagClass tagClass, int tagNo) {
         super(tagClass, tagNo);
         setValue(new ArrayList<Asn1Item>());
-        setEncodingOption(EncodingOption.CONSTRUCTED);
+        getEncodingOption().useConstructed();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 4187209..bb42988 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
@@ -39,7 +39,7 @@ public abstract class Asn1CollectionType extends AbstractAsn1Type<Asn1Collection
         setValue(this);
         this.fieldInfos = fieldInfos;
         this.fields = new Asn1Type[fieldInfos.length];
-        setEncodingOption(EncodingOption.CONSTRUCTED);
+        getEncodingOption().useConstructed();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 6c4352c..66c542b 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
@@ -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.UniversalTag;
@@ -49,7 +48,7 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
      */
     public Asn1Simple(UniversalTag tagNo, T value) {
         super(TagClass.UNIVERSAL, tagNo.getValue(), value);
-        setEncodingOption(EncodingOption.PRIMITIVE);
+        getEncodingOption().usePrimitive();
     }
 
     protected byte[] getBytes() {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 b1e919c..89fccaa 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
@@ -38,7 +38,7 @@ public class Asn1Tagging<T extends Asn1Type> extends AbstractAsn1Type<T>
{
 
     public Asn1Tagging(int tagNo, T value, boolean isAppSpecific) {
         super(isAppSpecific ? TagClass.APPLICATION : TagClass.CONTEXT_SPECIFIC, tagNo, value);
-        setEncodingOption(EncodingOption.EXPLICIT);
+        getEncodingOption().useExplicit();
         if (value == null) {
             initValue();
         }
@@ -52,7 +52,8 @@ public class Asn1Tagging<T extends Asn1Type> extends AbstractAsn1Type<T>
{
         } else if (getEncodingOption().isImplicit()) {
             return value.encodingBodyLength();
         } else {
-            throw new RuntimeException("Invalid util option, only allowing explicit/implicit");
+            throw new RuntimeException("Invalid decoding option, " +
+                    "only allowing explicit/implicit");
         }
     }
 
@@ -75,7 +76,8 @@ public class Asn1Tagging<T extends Asn1Type> extends AbstractAsn1Type<T>
{
         } else if (getEncodingOption().isImplicit()) {
             value.encodeBody(buffer);
         } else {
-            throw new RuntimeException("Invalid util option, only allowing explicit/implicit");
+            throw new RuntimeException("Invalid decoding option, " +
+                    "only allowing explicit/implicit");
         }
     }
 
@@ -87,7 +89,8 @@ public class Asn1Tagging<T extends Asn1Type> extends AbstractAsn1Type<T>
{
         } else if (getEncodingOption().isImplicit()) {
             value.decodeBody(content);
         } else {
-            throw new RuntimeException("Invalid util option, only allowing explicit/implicit");
+            throw new RuntimeException("Invalid decoding option, " +
+                    "only allowing explicit/implicit");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 48a815c..d316b7b 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
@@ -38,16 +38,22 @@ public abstract class TaggingCollection extends AbstractAsn1Type<Asn1CollectionT
         this.tagged = createTaggedCollection(tags);
         setValue(tagged);
         this.tagging = new Asn1Tagging<Asn1CollectionType>(taggingTagNo, tagged, isAppSpecific);
-        setEncodingOption(EncodingOption.EXPLICIT);
+        getEncodingOption().useExplicit();
     }
 
     protected abstract Asn1CollectionType createTaggedCollection(Asn1FieldInfo[] tags);
 
+    @Override
     public void setEncodingOption(EncodingOption encodingOption) {
         tagging.setEncodingOption(encodingOption);
     }
 
     @Override
+    public EncodingOption getEncodingOption() {
+        return tagging.getEncodingOption();
+    }
+
+    @Override
     public boolean isConstructed() {
         return tagging.isConstructed();
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 20e4f5c..6c6fc04 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
@@ -44,7 +44,7 @@ public class PersonnelRecord extends TaggingSet {
 
     public PersonnelRecord() {
         super(0, fieldInfos, true);
-        setEncodingOption(EncodingOption.IMPLICIT);
+        getEncodingOption().useImplicit();
     }
 
     public void setName(Name name) {
@@ -151,7 +151,7 @@ public class PersonnelRecord extends TaggingSet {
 
         public Name() {
             super(1, tags, true);
-            setEncodingOption(EncodingOption.IMPLICIT);
+            getEncodingOption().useImplicit();
         }
 
         public Name(String givenName, String initial, String familyName) {
@@ -189,19 +189,19 @@ public class PersonnelRecord extends TaggingSet {
     public static class EmployeeNumber extends Asn1Tagging<Asn1Integer> {
         public EmployeeNumber(Integer value) {
             super(2, new Asn1Integer(value), true);
-            setEncodingOption(EncodingOption.IMPLICIT);
+            getEncodingOption().useImplicit();
         }
 
         public EmployeeNumber() {
             super(2, new Asn1Integer(), true);
-            setEncodingOption(EncodingOption.IMPLICIT);
+            getEncodingOption().useImplicit();
         }
     }
 
     public static class Date extends Asn1Tagging<Asn1VisibleString> {
         public Date(String value) {
             super(3, new Asn1VisibleString(value), true);
-            setEncodingOption(EncodingOption.IMPLICIT);
+            getEncodingOption().useImplicit();
         }
         public Date() {
             this(null);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 691c8fe..947f30f 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
@@ -38,8 +38,11 @@ public class TestAsn1Boolean {
                                   boolean isDer) {
         byte[] expected = Util.hex2bytes(expectedEncoding);
         Asn1Boolean aValue = new Asn1Boolean(value);
-        aValue.setEncodingOption(isDer ? EncodingOption.DER :
-                EncodingOption.BER);
+        if (isDer) {
+            aValue.getEncodingOption().useDer();
+        } else {
+            aValue.getEncodingOption().useBer();
+        }
         byte[] encodingBytes = aValue.encode();
         assertThat(encodingBytes).isEqualTo(expected);
     }
@@ -55,8 +58,11 @@ public class TestAsn1Boolean {
     private void testDecodingWith(Boolean expectedValue, String content,
                                   boolean isDer) throws IOException {
         Asn1Boolean decoded = new Asn1Boolean();
-        decoded.setEncodingOption(isDer ? EncodingOption.DER :
-                EncodingOption.BER);
+        if (isDer) {
+            decoded.getEncodingOption().useDer();
+        } else {
+            decoded.getEncodingOption().useBer();
+        }
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue()).isEqualTo(expectedValue);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 29df679..f9a774e 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.setEncodingOption(EncodingOption.DER);
+        aValue.getEncodingOption().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.setEncodingOption(EncodingOption.DER);
+        decoded.getEncodingOption().useDer();
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue().intValue()).isEqualTo(expectedValue);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 4299eab..cb97922 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.setEncodingOption(EncodingOption.DER);
+        aValue.getEncodingOption().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.setEncodingOption(EncodingOption.DER);
+        decoded.getEncodingOption().useDer();
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue()).isEqualTo(expectedValue);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 20e5c30..6d4d2a2 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.setEncodingOption(EncodingOption.DER);
+        aValue.getEncodingOption().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.setEncodingOption(EncodingOption.DER);
+        decoded.getEncodingOption().useDer();
         decoded.decode(Util.hex2bytes(content));
         assertThat(decoded.getValue()).isEqualTo(expectedValue);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/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 a6ada58..c836217 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
@@ -62,11 +62,18 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class TestTaggingEncoding {
     static final String TEST_STRING = "Jones";
-    static byte[] TYPE1_EXPECTED_BYTES = new byte[] {(byte) 0x1A, (byte) 0x05, (byte) 0x4A,
(byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
-    static byte[] TYPE2_EXPECTED_BYTES = new byte[] {(byte) 0x43, (byte) 0x05, (byte) 0x4A,
(byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
-    static byte[] TYPE3_EXPECTED_BYTES = new byte[] {(byte) 0xA2, (byte) 0x07, (byte) 0x43,
(byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
-    static byte[] TYPE4_EXPECTED_BYTES = new byte[] {(byte) 0x67, (byte) 0x07, (byte) 0x43,
(byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
-    static byte[] TYPE5_EXPECTED_BYTES = new byte[] {(byte) 0x82, (byte) 0x05, (byte) 0x4A,
(byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+    static byte[] TYPE1_EXPECTED_BYTES = new byte[] {(byte) 0x1A, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+    static byte[] TYPE2_EXPECTED_BYTES = new byte[] {(byte) 0x43, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+    static byte[] TYPE3_EXPECTED_BYTES = new byte[] {(byte) 0xA2, (byte) 0x07,
+            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73};
+    static byte[] TYPE4_EXPECTED_BYTES = new byte[] {(byte) 0x67, (byte) 0x07,
+            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73};
+    static byte[] TYPE5_EXPECTED_BYTES = new byte[] {(byte) 0x82, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
 
 
     public static class Type1 extends Asn1VisibleString {
@@ -81,7 +88,7 @@ public class TestTaggingEncoding {
     public static class Type2 extends Asn1Tagging<Type1> {
         public Type2(Type1 value) {
             super(3, value, true);
-            setEncodingOption(EncodingOption.IMPLICIT);
+            getEncodingOption().useImplicit();
         }
         public Type2() {
             this(null);
@@ -91,7 +98,7 @@ public class TestTaggingEncoding {
     public static class Type3 extends Asn1Tagging<Type2> {
         public Type3(Type2 value) {
             super(2, value, false);
-            setEncodingOption(EncodingOption.EXPLICIT);
+            getEncodingOption().useExplicit();
         }
         public Type3() {
             this(null);
@@ -101,7 +108,7 @@ public class TestTaggingEncoding {
     public static class Type4 extends Asn1Tagging<Type3> {
         public Type4(Type3 value) {
             super(7, value, true);
-            setEncodingOption(EncodingOption.IMPLICIT);
+            getEncodingOption().useImplicit();
         }
         public Type4() {
             this(null);
@@ -111,7 +118,7 @@ public class TestTaggingEncoding {
     public static class Type5 extends Asn1Tagging<Type2> {
         public Type5(Type2 value) {
             super(2, value, false);
-            setEncodingOption(EncodingOption.IMPLICIT);
+            getEncodingOption().useImplicit();
         }
         public Type5() {
             this(null);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/57e75f08/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/codec/KrbCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/codec/KrbCodec.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/codec/KrbCodec.java
index 8204267..3e26c30 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/codec/KrbCodec.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/codec/KrbCodec.java
@@ -45,7 +45,7 @@ public class KrbCodec {
     }
 
     public static <T extends Asn1Type> T decode(ByteBuffer content, Class<T>
krbType) throws KrbException {
-        Asn1Type implObj = null;
+        Asn1Type implObj;
         try {
             implObj = krbType.newInstance();
         } catch (Exception e) {
@@ -68,7 +68,7 @@ public class KrbCodec {
         int length = AbstractAsn1Type.readLength(limitedBuffer);
         LimitedByteBuffer valueBuffer = new LimitedByteBuffer(limitedBuffer, length);
 
-        KrbMessage msg = null;
+        KrbMessage msg;
         KrbMessageType msgType = KrbMessageType.fromValue(tagNo);
         if (msgType == KrbMessageType.TGS_REQ) {
             msg = new TgsReq();


Mime
View raw message