directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [1/5] directory-kerby git commit: ASN1. Refined dumping output and refactored some codes
Date Thu, 10 Dec 2015 08:10:00 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/pkinit-support c31c056da -> dfb0555c6


ASN1. Refined dumping output and refactored some codes


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

Branch: refs/heads/pkinit-support
Commit: 5f32419ef577b67e8420874e5825414c5173d738
Parents: c4b11cc
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Thu Dec 10 09:51:49 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Thu Dec 10 09:51:49 2015 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/kerby/asn1/Asn1Converter.java  |  2 +-
 kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java | 10 ++++++++++
 .../java/org/apache/kerby/asn1/parse/Asn1Container.java | 12 +++---------
 .../main/java/org/apache/kerby/asn1/parse/Asn1Item.java |  9 +--------
 .../org/apache/kerby/asn1/parse/Asn1ParseResult.java    |  8 ++++++++
 .../org/apache/kerby/asn1/type/Asn1CollectionType.java  |  4 +---
 6 files changed, 24 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5f32419e/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 b1efd93..820d08b 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
@@ -47,7 +47,7 @@ public final class Asn1Converter {
             tmpValue.decode(parseResult);
             return tmpValue;
         } else {
-            throw new IOException("Unknow type of tag=" + parseResult.tag());
+            throw new IOException("Unexpected item: " + parseResult.typeStr());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5f32419e/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
index 3768ae7..d248802 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
@@ -140,6 +140,16 @@ public class Tag {
         return String.format("0x%02X", tagByte());
     }
 
+    public String typeStr() {
+        if (isUniversal()) {
+            return universalTag().toStr();
+        } else if (isAppSpecific()) {
+            return "application [" + tagNo() + "]";
+        } else {
+            return "context [" + tagNo() + "]";
+        }
+    }
+
     public static Tag newAppTag(int tagNo) {
         return new Tag(TagClass.APPLICATION, tagNo);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5f32419e/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Container.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Container.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Container.java
index 7cbd471..d423e76 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Container.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Container.java
@@ -66,19 +66,13 @@ public class Asn1Container
 
     @Override
     public String toString() {
-        String typeStr;
-        if (tag().isUniversal()) {
-            typeStr = tag().universalTag().toStr();
-        } else if (tag().isAppSpecific()) {
-            typeStr = "application " + tagNo();
-        } else {
-            typeStr = "[" + tagNo() + "]";
-        }
-        return typeStr + " ["
+        String typeStr = tag().typeStr();
+        typeStr += " ["
             + "tag=" + tag()
             + ", off=" + getOffset()
             + ", len=" + getHeaderLength() + "+" + getBodyLength()
             + (isDefinitiveLength() ? "" : "(undefined)")
             + "]";
+        return typeStr;
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5f32419e/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Item.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Item.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Item.java
index 1e4f6f6..d70af2f 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Item.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1Item.java
@@ -37,13 +37,6 @@ public class Asn1Item extends Asn1ParseResult {
     @Override
     public String toString() {
         String valueStr = "##undecoded##";
-        String typeStr = tag().isUniversal() ? tag().universalTag().toStr()
-            : tag().tagClass().name().toLowerCase();
-        return typeStr + " ["
-            + "tag=" + tag()
-            + ", off=" + getOffset()
-            + ", len=" + getHeaderLength() + "+" + getBodyLength()
-            + "] "
-            + valueStr;
+        return typeStr() + valueStr;
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5f32419e/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1ParseResult.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1ParseResult.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1ParseResult.java
index bf80ced..78b7865 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1ParseResult.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/parse/Asn1ParseResult.java
@@ -105,4 +105,12 @@ public abstract class Asn1ParseResult extends Asn1Object {
     public boolean checkBodyFinished(int pos) {
         return getBodyEnd() != -1 && pos >= getBodyEnd();
     }
+
+    public String typeStr() {
+        return tag().typeStr() + " ["
+            + "tag=" + tag()
+            + ", off=" + getOffset()
+            + ", len=" + getHeaderLength() + "+" + getBodyLength()
+            + "] ";
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5f32419e/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 97221ce..97b2883 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
@@ -110,9 +110,7 @@ public abstract class Asn1CollectionType
                 }
             }
             if (foundPos == -1) {
-                String error = String.format("Unexpected item tag=%s, off=%d",
-                    parseItem.tag(), parseItem.getOffset());
-                throw new IOException(error);
+                throw new IOException("Unexpected item: " + parseItem.typeStr());
             }
             lastPos = foundPos;
 


Mime
View raw message