directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [12/19] directory-kerby git commit: ASN1. Introduced Asn1Converter to convert a parsing result into an ASN1 object
Date Wed, 09 Dec 2015 02:13:24 GMT
ASN1. Introduced Asn1Converter to convert a parsing result into an ASN1 object


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

Branch: refs/heads/pkinit-support
Commit: b561ff53b6344dd2edeb8f6f98cde79755dd2337
Parents: 030234b
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Wed Dec 9 05:52:31 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Wed Dec 9 05:52:31 2015 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/kerby/asn1/Asn1.java   |  2 +-
 .../org/apache/kerby/asn1/Asn1Converter.java    | 91 ++++++++++++++++++++
 .../org/apache/kerby/asn1/DecodingUtil.java     | 88 -------------------
 .../org/apache/kerby/asn1/type/Asn1Any.java     |  6 +-
 .../kerby/asn1/type/Asn1CollectionOf.java       |  4 +-
 .../kerby/asn1/type/Asn1CollectionType.java     |  6 +-
 .../apache/kerby/asn1/type/Asn1Constructed.java |  4 +-
 7 files changed, 102 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b561ff53/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
index 8ca411d..654c781 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1.java
@@ -51,7 +51,7 @@ public final class Asn1 {
 
     public static Asn1Type decode(ByteBuffer content) throws IOException {
         Asn1ParsingResult parsingResult = Asn1Parser.parse(content);
-        return DecodingUtil.decodeValue(parsingResult);
+        return Asn1Converter.convert(parsingResult);
     }
 
     public static Asn1ParsingResult parse(byte[] content) throws IOException {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b561ff53/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
new file mode 100644
index 0000000..89606a3
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Converter.java
@@ -0,0 +1,91 @@
+/**
+ *  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;
+
+import org.apache.kerby.asn1.parse.Asn1ParsingResult;
+import org.apache.kerby.asn1.type.Asn1Collection;
+import org.apache.kerby.asn1.type.Asn1Constructed;
+import org.apache.kerby.asn1.type.Asn1Object;
+import org.apache.kerby.asn1.type.Asn1Simple;
+import org.apache.kerby.asn1.type.Asn1Type;
+
+import java.io.IOException;
+
+/**
+ * Converting a ASN1 parsing result into an ASN1 object.
+ */
+public class Asn1Converter {
+
+    public static Asn1Type convert(Asn1ParsingResult parsingResult) throws IOException {
+        if (Asn1Simple.isSimple(parsingResult.tag())) {
+            return Asn1Converter.convertAsSimple(parsingResult);
+        } else if (Asn1Collection.isCollection(parsingResult.tag())) {
+            return Asn1Converter.convertAsCollection(parsingResult);
+        } else if (!parsingResult.tag().isPrimitive()) {
+            Asn1Object tmpValue = new Asn1Constructed(parsingResult.tag());
+            tmpValue.decode(parsingResult);
+            return tmpValue;
+        } else {
+            throw new IOException("Unknow type of tag=" + parsingResult.tag());
+        }
+    }
+
+    public static Asn1Type convertAsSimple(Asn1ParsingResult parsingResult) throws IOException
{
+        Asn1Object value = (Asn1Object) Asn1Simple.createSimple(parsingResult.tagNo());
+        value.useDefinitiveLength(parsingResult.isDefinitiveLength());
+        decodeValueWith(parsingResult, value);
+        return value;
+    }
+
+    public static Asn1Type convertAsCollection(Asn1ParsingResult parsingResult) throws IOException
{
+        Asn1Collection value = Asn1Collection.createCollection(parsingResult.tag());
+        value.useDefinitiveLength(parsingResult.isDefinitiveLength());
+        value.setLazy(true);
+        decodeValueWith(parsingResult, value);
+        return value;
+    }
+
+    public static Asn1Type convertAs(Asn1ParsingResult parsingResult,
+                                     Class<? extends Asn1Type> type) throws IOException
{
+        Asn1Type value;
+        try {
+            value = type.newInstance();
+        } catch (Exception e) {
+            throw new RuntimeException("Invalid type: "
+                + type.getCanonicalName(), e);
+        }
+        decodeValueWith(parsingResult, value);
+        return value;
+    }
+
+    public static void decodeValueWith(Asn1ParsingResult parsingResult, Asn1Type value) throws
IOException {
+        value.useDefinitiveLength(parsingResult.isDefinitiveLength());
+        ((Asn1Object) value).decode(parsingResult);
+    }
+
+    public static void decodeValueWith(Asn1ParsingResult parsingResult,
+                                       Asn1Type value, TaggingOption taggingOption) throws
IOException {
+        if (!parsingResult.isTagSpecific()) {
+            throw new IllegalArgumentException(
+                "Attempting to decode non-tagged value using tagging way");
+        }
+        ((Asn1Object) value).taggedDecode(parsingResult, taggingOption);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b561ff53/kerby-asn1/src/main/java/org/apache/kerby/asn1/DecodingUtil.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/DecodingUtil.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/DecodingUtil.java
deleted file mode 100644
index ef39540..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/DecodingUtil.java
+++ /dev/null
@@ -1,88 +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;
-
-import org.apache.kerby.asn1.parse.Asn1ParsingResult;
-import org.apache.kerby.asn1.type.Asn1Collection;
-import org.apache.kerby.asn1.type.Asn1Constructed;
-import org.apache.kerby.asn1.type.Asn1Object;
-import org.apache.kerby.asn1.type.Asn1Simple;
-import org.apache.kerby.asn1.type.Asn1Type;
-
-import java.io.IOException;
-
-public class DecodingUtil {
-
-    public static Asn1Type decodeValue(Asn1ParsingResult parsingResult) throws IOException
{
-        if (Asn1Simple.isSimple(parsingResult.tag())) {
-            return DecodingUtil.decodeValueAsSimple(parsingResult);
-        } else if (Asn1Collection.isCollection(parsingResult.tag())) {
-            return DecodingUtil.decodeValueAsCollection(parsingResult);
-        } else if (!parsingResult.tag().isPrimitive()) {
-            Asn1Object tmpValue = new Asn1Constructed(parsingResult.tag());
-            tmpValue.decode(parsingResult);
-            return tmpValue;
-        } else {
-            throw new IOException("Unknow type of tag=" + parsingResult.tag());
-        }
-    }
-
-    public static Asn1Type decodeValueAsSimple(Asn1ParsingResult parsingResult) throws IOException
{
-        Asn1Object value = (Asn1Object) Asn1Simple.createSimple(parsingResult.tagNo());
-        value.useDefinitiveLength(parsingResult.isDefinitiveLength());
-        decodeValueWith(parsingResult, value);
-        return value;
-    }
-
-    public static Asn1Type decodeValueAsCollection(Asn1ParsingResult parsingResult) throws
IOException {
-        Asn1Collection value = Asn1Collection.createCollection(parsingResult.tag());
-        value.useDefinitiveLength(parsingResult.isDefinitiveLength());
-        value.setLazy(true);
-        decodeValueWith(parsingResult, value);
-        return value;
-    }
-
-    public static Asn1Type decodeValueAs(Asn1ParsingResult parsingResult,
-                                         Class<? extends Asn1Type> type) throws IOException
{
-        Asn1Type value;
-        try {
-            value = type.newInstance();
-        } catch (Exception e) {
-            throw new RuntimeException("Invalid type: "
-                + type.getCanonicalName(), e);
-        }
-        decodeValueWith(parsingResult, value);
-        return value;
-    }
-
-    public static void decodeValueWith(Asn1ParsingResult parsingResult, Asn1Type value) throws
IOException {
-        value.useDefinitiveLength(parsingResult.isDefinitiveLength());
-        ((Asn1Object) value).decode(parsingResult);
-    }
-
-    public static void decodeValueWith(Asn1ParsingResult parsingResult,
-                                       Asn1Type value, TaggingOption taggingOption) throws
IOException {
-        if (!parsingResult.isTagSpecific()) {
-            throw new IllegalArgumentException(
-                "Attempting to decode non-tagged value using tagging way");
-        }
-        ((Asn1Object) value).taggedDecode(parsingResult, taggingOption);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b561ff53/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
index f63481f..4b42970 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Any.java
@@ -20,7 +20,7 @@
 package org.apache.kerby.asn1.type;
 
 import org.apache.kerby.asn1.Asn1FieldInfo;
-import org.apache.kerby.asn1.DecodingUtil;
+import org.apache.kerby.asn1.Asn1Converter;
 import org.apache.kerby.asn1.UniversalTag;
 import org.apache.kerby.asn1.parse.Asn1ParsingResult;
 
@@ -85,10 +85,10 @@ public class Asn1Any extends AbstractAsn1Type<Asn1Type> {
 
         try {
             if (field.isContextSpecific()) {
-                DecodingUtil.decodeValueWith(field, result,
+                Asn1Converter.decodeValueWith(field, result,
                     fieldInfo.getTaggingOption());
             } else {
-                DecodingUtil.decodeValueWith(field, result);
+                Asn1Converter.decodeValueWith(field, result);
             }
         } catch (IOException e) {
             throw new RuntimeException("Fully decoding failed", e);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b561ff53/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionOf.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionOf.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionOf.java
index 08eb317..d7849fe 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionOf.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionOf.java
@@ -20,7 +20,7 @@
 package org.apache.kerby.asn1.type;
 
 import org.apache.kerby.asn1.Asn1Dumper;
-import org.apache.kerby.asn1.DecodingUtil;
+import org.apache.kerby.asn1.Asn1Converter;
 import org.apache.kerby.asn1.UniversalTag;
 import org.apache.kerby.asn1.parse.Asn1ParsingResult;
 
@@ -43,7 +43,7 @@ public abstract class Asn1CollectionOf<T extends Asn1Type>
             }
 
             Asn1Type tmpValue = createElement();
-            DecodingUtil.decodeValueWith(parsingItem, tmpValue);
+            Asn1Converter.decodeValueWith(parsingItem, tmpValue);
             addItem(tmpValue);
         }
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b561ff53/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 2039b08..1b98847 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
@@ -22,7 +22,7 @@ package org.apache.kerby.asn1.type;
 import org.apache.kerby.asn1.Asn1Dumpable;
 import org.apache.kerby.asn1.Asn1Dumper;
 import org.apache.kerby.asn1.Asn1FieldInfo;
-import org.apache.kerby.asn1.DecodingUtil;
+import org.apache.kerby.asn1.Asn1Converter;
 import org.apache.kerby.asn1.EnumType;
 import org.apache.kerby.asn1.TaggingOption;
 import org.apache.kerby.asn1.UniversalTag;
@@ -121,10 +121,10 @@ public abstract class Asn1CollectionType
                 any.setFieldInfo(fieldInfos[foundPos]);
             } else {
                 if (parsingItem.isContextSpecific()) {
-                    DecodingUtil.decodeValueWith(parsingItem, fieldValue,
+                    Asn1Converter.decodeValueWith(parsingItem, fieldValue,
                         fieldInfos[foundPos].getTaggingOption());
                 } else {
-                    DecodingUtil.decodeValueWith(parsingItem, fieldValue);
+                    Asn1Converter.decodeValueWith(parsingItem, fieldValue);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/b561ff53/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Constructed.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Constructed.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Constructed.java
index 605b445..723bbca 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Constructed.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Constructed.java
@@ -21,7 +21,7 @@ package org.apache.kerby.asn1.type;
 
 import org.apache.kerby.asn1.Asn1Dumpable;
 import org.apache.kerby.asn1.Asn1Dumper;
-import org.apache.kerby.asn1.DecodingUtil;
+import org.apache.kerby.asn1.Asn1Converter;
 import org.apache.kerby.asn1.Tag;
 import org.apache.kerby.asn1.parse.Asn1Container;
 import org.apache.kerby.asn1.parse.Asn1ParsingResult;
@@ -106,7 +106,7 @@ public class Asn1Constructed
                 continue;
             }
 
-            Asn1Type tmpValue = DecodingUtil.decodeValue(parsingItem);
+            Asn1Type tmpValue = Asn1Converter.convert(parsingItem);
             addItem(tmpValue);
         }
     }


Mime
View raw message