directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject directory-kerby git commit: ASN1. Introduced Asn1Constructed for support of some primitive types using constructed encoding
Date Tue, 01 Dec 2015 13:33:15 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 949104fd2 -> 1d9385611


ASN1. Introduced Asn1Constructed for support of some primitive types using constructed encoding


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

Branch: refs/heads/master
Commit: 1d9385611873e4fd9e6da9296c0fddfdb2a4115a
Parents: 949104f
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Tue Dec 1 21:32:54 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Tue Dec 1 21:32:54 2015 +0800

----------------------------------------------------------------------
 .../apache/kerby/asn1/type/Asn1Collection.java  | 66 +-------------
 .../apache/kerby/asn1/type/Asn1Constructed.java | 93 ++++++++++++++++++++
 2 files changed, 95 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1d938561/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 3bbb770..a4d6560 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
@@ -22,74 +22,13 @@ package org.apache.kerby.asn1.type;
 import org.apache.kerby.asn1.Tag;
 import org.apache.kerby.asn1.UniversalTag;
 
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * ASN1 complex type, may be better named.
  */
-public class Asn1Collection extends AbstractAsn1Type<List<Asn1Type>> {
-    private boolean lazy = false;
+public class Asn1Collection extends Asn1Constructed {
 
     public Asn1Collection(UniversalTag universalTag) {
-        super(universalTag);
-        setValue(new ArrayList<Asn1Type>());
-        usePrimitive(false);
-    }
-
-    public void setLazy(boolean lazy) {
-        this.lazy = lazy;
-    }
-
-    public boolean isLazy() {
-        return lazy;
-    }
-
-    public void addItem(Asn1Type value) {
-        getValue().add(value);
-    }
-
-    public void clear() {
-        getValue().clear();
-    }
-
-    @Override
-    protected int encodingBodyLength() {
-        List<Asn1Type> valueItems = getValue();
-        int allLen = 0;
-        for (Asn1Type item : valueItems) {
-            if (item != null) {
-                allLen += item.encodingLength();
-            }
-        }
-        return allLen;
-    }
-
-    @Override
-    protected void encodeBody(ByteBuffer buffer) {
-        List<Asn1Type> valueItems = getValue();
-        for (Asn1Type item : valueItems) {
-            if (item != null) {
-                item.encode(buffer);
-            }
-        }
-    }
-
-    @Override
-    protected void decodeBody(ByteBuffer content) throws IOException {
-        while (content.remaining() > 0) {
-            Asn1Item item = decodeOne(content);
-            if (item != null) {
-                if (item.isSimple() && !isLazy()) {
-                    item.decodeValueAsSimple();
-                    addItem(item.getValue());
-                } else {
-                    addItem(item);
-                }
-            }
-        }
+        super(new Tag(universalTag));
     }
 
     public static boolean isCollection(Tag tag) {
@@ -137,5 +76,4 @@ public class Asn1Collection extends AbstractAsn1Type<List<Asn1Type>>
{
                 throw new IllegalArgumentException("Unexpected tag " + tagNo.getValue());
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/1d938561/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
new file mode 100644
index 0000000..46cb6c6
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Constructed.java
@@ -0,0 +1,93 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.kerby.asn1.type;
+
+import org.apache.kerby.asn1.Tag;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ASN1 constructed types, mainly structured ones, but also some primitive ones.
+ */
+public class Asn1Constructed extends AbstractAsn1Type<List<Asn1Type>> {
+    private boolean lazy = false;
+
+    public Asn1Constructed(Tag tag) {
+        super(tag);
+        setValue(new ArrayList<Asn1Type>());
+        usePrimitive(false);
+    }
+
+    public void setLazy(boolean lazy) {
+        this.lazy = lazy;
+    }
+
+    public boolean isLazy() {
+        return lazy;
+    }
+
+    public void addItem(Asn1Type value) {
+        getValue().add(value);
+    }
+
+    public void clear() {
+        getValue().clear();
+    }
+
+    @Override
+    protected int encodingBodyLength() {
+        List<Asn1Type> valueItems = getValue();
+        int allLen = 0;
+        for (Asn1Type item : valueItems) {
+            if (item != null) {
+                allLen += item.encodingLength();
+            }
+        }
+        return allLen;
+    }
+
+    @Override
+    protected void encodeBody(ByteBuffer buffer) {
+        List<Asn1Type> valueItems = getValue();
+        for (Asn1Type item : valueItems) {
+            if (item != null) {
+                item.encode(buffer);
+            }
+        }
+    }
+
+    @Override
+    protected void decodeBody(ByteBuffer content) throws IOException {
+        while (content.remaining() > 0) {
+            Asn1Item item = decodeOne(content);
+            if (item != null) {
+                if (item.isSimple() && !isLazy()) {
+                    item.decodeValueAsSimple();
+                    addItem(item.getValue());
+                } else {
+                    addItem(item);
+                }
+            }
+        }
+    }
+}


Mime
View raw message