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: Synced with master
Date Sat, 12 Dec 2015 02:38:44 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/pkinit-support 17513611d -> 7d89c4eeb


Synced with master


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

Branch: refs/heads/pkinit-support
Commit: 7d89c4eeb048a3bd623dc6ce88c391b9e3a2e022
Parents: 1751361
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Sat Dec 12 10:38:18 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Sat Dec 12 10:38:18 2015 +0800

----------------------------------------------------------------------
 .../java/org/apache/kerby/asn1/Asn1Dumper.java  |  3 +
 .../org/apache/kerby/asn1/TaggingOption.java    |  6 +-
 .../org/apache/kerby/asn1/type/Asn1Choice.java  |  2 +-
 .../kerby/asn1/type/Asn1CollectionOf.java       |  3 +-
 .../kerby/asn1/type/Asn1CollectionType.java     | 47 ++++++----
 .../org/apache/kerby/cms/type/Attribute.java    |  2 +-
 .../apache/kerby/cms/type/CertificateList.java  | 91 --------------------
 .../kerby/cms/type/RevocationInfoChoice.java    |  2 +
 .../kerby/x500/type/AttributeTypeAndValue.java  |  4 +-
 .../org/apache/kerby/x509/type/Attribute.java   |  3 +
 .../apache/kerby/x509/type/AttributeValues.java | 15 +++-
 .../org/apache/kerby/x509/type/GeneralName.java | 25 +++---
 .../org/apache/kerby/cms/TestCertificate.java   | 59 +++++++++++++
 .../org/apache/kerby/cms/TestGeneralName.java   | 50 +++++++++++
 .../org/apache/kerby/cms/TestSignedData.java    | 14 ++-
 kerby-pkix/src/test/resources/certificate1.txt  |  1 +
 kerby-pkix/src/test/resources/name.txt          |  1 +
 17 files changed, 190 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
index 38addf4..c701eb6 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Dumper.java
@@ -24,6 +24,7 @@ import org.apache.kerby.asn1.parse.Asn1ParseResult;
 import org.apache.kerby.asn1.parse.Asn1Parser;
 import org.apache.kerby.asn1.type.Asn1Any;
 import org.apache.kerby.asn1.type.Asn1Application;
+import org.apache.kerby.asn1.type.Asn1Choice;
 import org.apache.kerby.asn1.type.Asn1Simple;
 import org.apache.kerby.asn1.type.Asn1Type;
 import org.apache.kerby.asn1.util.HexUtil;
@@ -91,6 +92,8 @@ public final class Asn1Dumper {
             indent(indents).append(value.toString());
         } else if (value instanceof Asn1Any) {
             indent(indents).append("<Any>");
+        } else if (value instanceof Asn1Choice) {
+            indent(indents).append("<Choice>");
         } else {
             indent(indents).append("<Unknown>");
         }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/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 898c25e..5ba221a 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
@@ -76,9 +76,9 @@ public final class TaggingOption {
     }
 
     /**
-     * Make tag flags giving it's tagged constructed.
-     * @param isTaggedConstructed Tagged Constructed or not
-     * @return tag flag
+     * Make tag giving it's tagged constructed.
+     * @param isTaggedConstructed Tagged constructed or not
+     * @return tag
      */
     public Tag getTag(boolean isTaggedConstructed) {
         boolean isConstructed = isImplicit ? isTaggedConstructed : true;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/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 a7ff5ca..eca455a 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
@@ -148,7 +148,7 @@ public class Asn1Choice extends AbstractAsn1Type<Asn1Type> {
             return null;
         }
 
-        if (chosenField != null && index != chosenField) {
+        if (chosenField != null && index != chosenField.getIndex()) {
             throw new IllegalArgumentException("Incorrect chosen value requested");
         }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/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 4e0d7a0..5c9d3a2 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
@@ -81,7 +81,8 @@ public abstract class Asn1CollectionOf<T extends Asn1Type>
             T result = (T) eleType.newInstance();
             return result;
         } catch (Exception e) {
-            throw new IOException("Failed to create element type", e);
+            throw new IOException("Failed to create element type, "
+                + "no default constructor? " + eleType.getName(), e);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/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 44d6e59..3aa5225 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
@@ -56,7 +56,7 @@ public abstract class Asn1CollectionType
     protected int encodingBodyLength() {
         int allLen = 0;
         for (int i = 0; i < fields.length; ++i) {
-            AbstractAsn1Type<?> field = (AbstractAsn1Type<?>) fields[i];
+            Asn1Encodeable field = (Asn1Encodeable) fields[i];
             if (field != null) {
                 if (fieldInfos[i].isTagged()) {
                     TaggingOption taggingOption =
@@ -106,18 +106,25 @@ public abstract class Asn1CollectionType
             }
             lastPos = foundPos;
 
-            Asn1Type fieldValue = fields[foundPos];
-            if (fieldValue instanceof Asn1Any) {
-                Asn1Any any = (Asn1Any) fieldValue;
-                any.setFieldInfo(fieldInfos[foundPos]);
-                Asn1Binder.bind(parseItem, any);
+            attemptBinding(parseItem, foundPos);
+        }
+    }
+
+    private void attemptBinding(Asn1ParseResult parseItem,
+                                int foundPos) throws IOException {
+        Asn1Type fieldValue = fields[foundPos];
+        Asn1FieldInfo fieldInfo = fieldInfos[foundPos];
+
+        if (fieldValue instanceof Asn1Any) {
+            Asn1Any any = (Asn1Any) fieldValue;
+            any.setFieldInfo(fieldInfo);
+            Asn1Binder.bind(parseItem, any);
+        } else {
+            if (parseItem.isContextSpecific()) {
+                Asn1Binder.bindWithTagging(parseItem, fieldValue,
+                    fieldInfo.getTaggingOption());
             } else {
-                if (parseItem.isContextSpecific()) {
-                    Asn1Binder.bindWithTagging(parseItem, fieldValue,
-                            fieldInfos[foundPos].getTaggingOption());
-                } else {
-                    Asn1Binder.bind(parseItem, fieldValue);
-                }
+                Asn1Binder.bind(parseItem, fieldValue);
             }
         }
     }
@@ -125,21 +132,27 @@ public abstract class Asn1CollectionType
     private int match(int lastPos, Asn1ParseResult parseItem) {
         int foundPos = -1;
         for (int i = lastPos + 1; i < fieldInfos.length; ++i) {
-            if (parseItem.isContextSpecific()) {
-                if (fieldInfos[i].getTagNo() == parseItem.tagNo()) {
+            Asn1Type fieldValue = fields[i];
+            Asn1FieldInfo fieldInfo = fieldInfos[i];
+
+            if (fieldInfo.isTagged()) {
+                if (!parseItem.isContextSpecific()) {
+                    continue;
+                }
+                if (fieldInfo.getTagNo() == parseItem.tagNo()) {
                     foundPos = i;
                     break;
                 }
-            } else if (fields[i].tag().equals(parseItem.tag())) {
+            } else if (fieldValue.tag().equals(parseItem.tag())) {
                 foundPos = i;
                 break;
-            } else if (fields[i] instanceof Asn1Choice) {
+            } else if (fieldValue instanceof Asn1Choice) {
                 Asn1Choice aChoice = (Asn1Choice) fields[i];
                 if (aChoice.matchAndSetValue(parseItem.tag())) {
                     foundPos = i;
                     break;
                 }
-            } else if (fields[i] instanceof Asn1Any) {
+            } else if (fieldValue instanceof Asn1Any) {
                 foundPos = i;
                 break;
             }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/main/java/org/apache/kerby/cms/type/Attribute.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/cms/type/Attribute.java b/kerby-pkix/src/main/java/org/apache/kerby/cms/type/Attribute.java
index e91cf9e..f9a4615 100644
--- a/kerby-pkix/src/main/java/org/apache/kerby/cms/type/Attribute.java
+++ b/kerby-pkix/src/main/java/org/apache/kerby/cms/type/Attribute.java
@@ -33,7 +33,7 @@ import static org.apache.kerby.cms.type.Attribute.MyEnum.*;
  *     attrType OBJECT IDENTIFIER,
  *     attrValues SET OF AttributeValue
  * }
- * 
+ *
  * AttributeValue ::= ANY
  * </pre>
  */

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/main/java/org/apache/kerby/cms/type/CertificateList.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/cms/type/CertificateList.java b/kerby-pkix/src/main/java/org/apache/kerby/cms/type/CertificateList.java
deleted file mode 100644
index e528451..0000000
--- a/kerby-pkix/src/main/java/org/apache/kerby/cms/type/CertificateList.java
+++ /dev/null
@@ -1,91 +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.cms.type;
-
-import org.apache.kerby.asn1.EnumType;
-import org.apache.kerby.asn1.type.Asn1BitString;
-import org.apache.kerby.asn1.Asn1FieldInfo;
-import org.apache.kerby.asn1.type.Asn1SequenceType;
-import org.apache.kerby.x509.type.AlgorithmIdentifier;
-import org.apache.kerby.x509.type.TBSCertList;
-import static org.apache.kerby.cms.type.CertificateList.MyEnum.*;
-
-/**
- * Ref. RFC-2459
- *
- * <pre>
- * CertificateList  ::=  SEQUENCE  {
- *      tbsCertList          TBSCertList,
- *      signatureAlgorithm   AlgorithmIdentifier,
- *      signatureValue       BIT STRING
- * }
- * </pre>
- */
-public class CertificateList extends Asn1SequenceType {
-    protected enum MyEnum implements EnumType {
-        TBS_CERT_LIST,
-        SIGNATURE_ALGORITHMS,
-        SIGNATURE_VALUE;
-
-        @Override
-        public int getValue() {
-            return ordinal();
-        }
-
-        @Override
-        public String getName() {
-            return name();
-        }
-    }
-
-    static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
-            new Asn1FieldInfo(TBS_CERT_LIST, TBSCertList.class),
-            new Asn1FieldInfo(SIGNATURE_ALGORITHMS, AlgorithmIdentifier.class),
-            new Asn1FieldInfo(SIGNATURE_VALUE, Asn1BitString.class)
-    };
-
-    public CertificateList() {
-        super(fieldInfos);
-    }
-
-    public TBSCertList getTBSCertList() {
-        return getFieldAs(TBS_CERT_LIST, TBSCertList.class);
-    }
-
-    public void setTBSCertList(TBSCertList tbsCertList) {
-        setFieldAs(TBS_CERT_LIST, tbsCertList);
-    }
-
-    public AlgorithmIdentifier getSignatureAlgorithm() {
-        return getFieldAs(SIGNATURE_ALGORITHMS, AlgorithmIdentifier.class);
-    }
-
-    public void setSignatureAlgorithms(AlgorithmIdentifier signatureAlgorithms) {
-        setFieldAs(SIGNATURE_ALGORITHMS, signatureAlgorithms);
-    }
-
-    public Asn1BitString getSignature() {
-        return getFieldAs(SIGNATURE_VALUE, Asn1BitString.class);
-    }
-
-    public void setSignatureValue(Asn1BitString signatureValue) {
-        setFieldAs(SIGNATURE_VALUE, signatureValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/main/java/org/apache/kerby/cms/type/RevocationInfoChoice.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/cms/type/RevocationInfoChoice.java
b/kerby-pkix/src/main/java/org/apache/kerby/cms/type/RevocationInfoChoice.java
index 9e64470..57be933 100644
--- a/kerby-pkix/src/main/java/org/apache/kerby/cms/type/RevocationInfoChoice.java
+++ b/kerby-pkix/src/main/java/org/apache/kerby/cms/type/RevocationInfoChoice.java
@@ -23,6 +23,8 @@ import org.apache.kerby.asn1.EnumType;
 import org.apache.kerby.asn1.type.Asn1Choice;
 import org.apache.kerby.asn1.Asn1FieldInfo;
 import org.apache.kerby.asn1.ImplicitField;
+import org.apache.kerby.x509.type.CertificateList;
+
 import static org.apache.kerby.cms.type.RevocationInfoChoice.MyEnum.*;
 
 /**

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/main/java/org/apache/kerby/x500/type/AttributeTypeAndValue.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/x500/type/AttributeTypeAndValue.java
b/kerby-pkix/src/main/java/org/apache/kerby/x500/type/AttributeTypeAndValue.java
index bb2ab11..2da8077 100644
--- a/kerby-pkix/src/main/java/org/apache/kerby/x500/type/AttributeTypeAndValue.java
+++ b/kerby-pkix/src/main/java/org/apache/kerby/x500/type/AttributeTypeAndValue.java
@@ -50,8 +50,8 @@ public class AttributeTypeAndValue extends Asn1SequenceType {
     }
 
     static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[]{
-            new Asn1FieldInfo(TYPE, Asn1ObjectIdentifier.class, true),
-            new Asn1FieldInfo(VALUE, Asn1Any.class, true)
+            new Asn1FieldInfo(TYPE, -1, Asn1ObjectIdentifier.class, true),
+            new Asn1FieldInfo(VALUE, -1, Asn1Any.class, true)
     };
 
     public AttributeTypeAndValue() {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Attribute.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Attribute.java b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Attribute.java
index f9878cd..772468b 100644
--- a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Attribute.java
+++ b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Attribute.java
@@ -31,6 +31,9 @@ import static org.apache.kerby.x509.type.Attribute.MyEnum.*;
  *     attrType OBJECT IDENTIFIER,
  *     attrValues SET OF AttributeValue
  * }
+ *
+ * AttributeValue ::= ANY
+ *
  * </pre>
  */
 public class Attribute extends Asn1SequenceType {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/main/java/org/apache/kerby/x509/type/AttributeValues.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/AttributeValues.java b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/AttributeValues.java
index f407856..027ade3 100644
--- a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/AttributeValues.java
+++ b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/AttributeValues.java
@@ -19,9 +19,20 @@
  */
 package org.apache.kerby.x509.type;
 
+import org.apache.kerby.asn1.type.Asn1Any;
 import org.apache.kerby.asn1.type.Asn1SetOf;
-import org.apache.kerby.asn1.type.Asn1Type;
 
-public class AttributeValues extends Asn1SetOf<Asn1Type> {
+/**
+ * Ref. RFC 5652
+ * <pre>
+ * Attribute ::= SEQUENCE {
+ *     attrType OBJECT IDENTIFIER,
+ *     attrValues SET OF AttributeValue
+ * }
+ *
+ * AttributeValue ::= ANY
+ * </pre>
+ */
+public class AttributeValues extends Asn1SetOf<Asn1Any> {
 
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/main/java/org/apache/kerby/x509/type/GeneralName.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/GeneralName.java b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/GeneralName.java
index 3d68900..7f9217a 100644
--- a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/GeneralName.java
+++ b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/GeneralName.java
@@ -22,6 +22,7 @@ package org.apache.kerby.x509.type;
 import org.apache.kerby.asn1.Asn1FieldInfo;
 import org.apache.kerby.asn1.EnumType;
 import org.apache.kerby.asn1.ExplicitField;
+import org.apache.kerby.asn1.ImplicitField;
 import org.apache.kerby.asn1.type.Asn1Any;
 import org.apache.kerby.asn1.type.Asn1Choice;
 import org.apache.kerby.asn1.type.Asn1IA5String;
@@ -71,16 +72,16 @@ public class GeneralName extends Asn1Choice {
     }
 
     static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
-        new ExplicitField(OTHER_NAME, OtherName.class),
-        new ExplicitField(RFC822_NAME, Asn1IA5String.class),
-        new ExplicitField(DNS_NAME, Asn1IA5String.class),
+        new ImplicitField(OTHER_NAME, OtherName.class),
+        new ImplicitField(RFC822_NAME, Asn1IA5String.class),
+        new ImplicitField(DNS_NAME, Asn1IA5String.class),
         // ORAddress is to be defined.
-        new ExplicitField(X400_ADDRESS, Asn1Any.class),
+        new ImplicitField(X400_ADDRESS, Asn1Any.class),
         new ExplicitField(DIRECTORY_NAME, Name.class),
-        new ExplicitField(EDI_PARTY_NAME, EDIPartyName.class),
-        new ExplicitField(UNIFORM_RESOURCE_IDENTIFIER, Asn1IA5String.class),
-        new ExplicitField(IP_ADDRESS, Asn1OctetString.class),
-        new ExplicitField(REGISTERED_ID, Asn1ObjectIdentifier.class)
+        new ImplicitField(EDI_PARTY_NAME, EDIPartyName.class),
+        new ImplicitField(UNIFORM_RESOURCE_IDENTIFIER, Asn1IA5String.class),
+        new ImplicitField(IP_ADDRESS, Asn1OctetString.class),
+        new ImplicitField(REGISTERED_ID, Asn1ObjectIdentifier.class)
     };
 
     public GeneralName() {
@@ -143,12 +144,12 @@ public class GeneralName extends Asn1Choice {
         setChoiceValue(UNIFORM_RESOURCE_IDENTIFIER, uniformResourceIdentifier);
     }
 
-    public Asn1OctetString getIPAddress() {
-        return getChoiceValueAs(IP_ADDRESS, Asn1OctetString.class);
+    public byte[] getIPAddress() {
+        return getChoiceValueAsOctets(IP_ADDRESS);
     }
 
-    public void setIpAddress(Asn1OctetString ipAddress) {
-        setChoiceValue(IP_ADDRESS, ipAddress);
+    public void setIpAddress(byte[] ipAddress) {
+        setChoiceValueAsOctets(IP_ADDRESS, ipAddress);
     }
 
     public Asn1ObjectIdentifier getRegisteredID() {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java
new file mode 100644
index 0000000..ae98fa0
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestCertificate.java
@@ -0,0 +1,59 @@
+/**
+ *  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.cms;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.cms.type.Certificate;
+import org.apache.kerby.x500.type.Name;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class TestCertificate extends CmsTestBase {
+    @Test
+    public void testDecodingCertificate() throws IOException {
+        byte[] data = readDataFile("/certificate1.txt");
+        try {
+            Asn1.dump(data, true);
+            Certificate certificate = new Certificate();
+            certificate.decode(data);
+            Asn1.dump(certificate);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testDecodingName() throws IOException {
+        byte[] data = readDataFile("/name.txt");
+        try {
+            Asn1.dump(data, true);
+            Name name = new Name();
+            name.decode(data);
+            Asn1.dump(name.getName());
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
new file mode 100644
index 0000000..daa1542
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestGeneralName.java
@@ -0,0 +1,50 @@
+/**
+ *  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.cms;
+
+import org.apache.kerby.asn1.Asn1;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.apache.kerby.x509.type.GeneralName;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TestGeneralName {
+    private static final byte[] IPV4 = HexUtil.hex2bytes("87040a090800");
+
+    @Test
+    public void testIpAddress() throws IOException {
+        try {
+            Asn1.dump(IPV4, true);
+            GeneralName generalName = new GeneralName();
+            generalName.decode(IPV4);
+            assertThat(generalName.getIPAddress()).isNotNull();
+            byte[] addressBytes = generalName.getIPAddress();
+            // "10.9.8.0"
+            assertThat(addressBytes).isEqualTo(new byte[] {0x0a, 0x09, 0x08, 0x00});
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
index 900dab8..a169421 100644
--- a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestSignedData.java
@@ -41,14 +41,13 @@ public class TestSignedData extends CmsTestBase {
             contentInfo.decode(data);
             Asn1.dump(contentInfo);
 
-            /** TO BE FIXED AFTER choice supported
             SignedData signedData =
                 contentInfo.getContentAs(SignedData.class);
             Asn1.dump(signedData);
 
-            byte[] encodedData = contentInfo.encode();
-            Asn1.dump(encodedData, true);
-             */
+            //TO BE FIXED
+            //byte[] encodedData = contentInfo.encode();
+            //Asn1.dump(encodedData, true);
         } catch (Exception e) {
             e.printStackTrace();
             Assert.fail();
@@ -87,10 +86,9 @@ public class TestSignedData extends CmsTestBase {
             ContentInfo contentInfo = new ContentInfo();
             contentInfo.decode(data);
             Asn1.dump(contentInfo);
-/** Failed in DigestAlgorithmIdentifiers*/
-//            SignedData signedData =
-//                    contentInfo.getContentAs(SignedData.class);
-//            Asn1.dump(signedData);
+            SignedData signedData =
+                    contentInfo.getContentAs(SignedData.class);
+            Asn1.dump(signedData);
         } catch (Exception e) {
             e.printStackTrace();
             Assert.fail();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/test/resources/certificate1.txt
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/resources/certificate1.txt b/kerby-pkix/src/test/resources/certificate1.txt
new file mode 100644
index 0000000..5609025
--- /dev/null
+++ b/kerby-pkix/src/test/resources/certificate1.txt
@@ -0,0 +1 @@
+3082035E308202C7A003020102020107300D06092A864886F70D01010405003081B7310B30090603550406130241553111300F06035504081308566963746F726961311830160603550407130F536F757468204D656C626F75726E65311A3018060355040A1311436F6E6E656374203420507479204C7464311E301C060355040B1315436572746966696361746520417574686F72697479311530130603550403130C436F6E6E65637420342043413128302606092A864886F70D01090116197765626D617374657240636F6E6E656374342E636F6D2E6175301E170D3030303630323037353632315A170D3031303630323037353632315A3081B8310B30090603550406130241553111300F06035504081308566963746F726961311830160603550407130F536F757468204D656C626F75726E65311A3018060355040A1311436F6E6E656374203420507479204C746431173015060355040B130E576562736572766572205465616D311D301B06035504031314777777322E636F6E6E656374342E636F6D2E61753128302606092A864886F70D01090116197765626D617374657240636F6E6E656374342E636F6D2E617530819F300D06092A864886F70D010101050003818D0030818902818100AEF0F1725280872BFB43F5A6AF6ADE1B0E172FD0A787D7BEE95816CB6016372FCC5
 5E5DD971CDDED002E73578E59090640488B3F2E5742D4D8FAC05427700E46F7767C454921C8DFDBD7B2EDB62E6BD27FBF3E4C1B6298A3DFD6087230A83F66986F60D312DC7F0ABFB3C64906CC04EEC6FCE5553E87DE0F4EFB163AC5AE29A10203010001A377307530240603551D11041D301B81197765626D617374657240636F6E6E656374342E636F6D2E6175303A06096086480186F842010D042D162B6D6F645F73736C2067656E65726174656420637573746F6D20736572766572206365727469666963617465301106096086480186F8420101040403020640300D06092A864886F70D010104050003818100A2D71C7CAA704AC2313351DA7BC0D1ECCFD1C3C760FD1A8E5B1E391CD54B8814B8FF737F4CED7DE7279029B7E6CDB000DA36CF56F22F1A04F13E03B530FE1982F81185AB1A6B4A82242916BE9338C907F7DEF3A26106E9BF8AD3C3353C026465046E3959D8F23488A0195FA845CEB568A0939CBABBCC1F0DDF3D5317F6C5E7FF
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d89c4ee/kerby-pkix/src/test/resources/name.txt
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/resources/name.txt b/kerby-pkix/src/test/resources/name.txt
new file mode 100644
index 0000000..930ac37
--- /dev/null
+++ b/kerby-pkix/src/test/resources/name.txt
@@ -0,0 +1 @@
+3081B7310B30090603550406130241553111300F06035504081308566963746F726961311830160603550407130F536F757468204D656C626F75726E65311A3018060355040A1311436F6E6E656374203420507479204C7464311E301C060355040B1315436572746966696361746520417574686F72697479311530130603550403130C436F6E6E65637420342043413128302606092A864886F70D01090116197765626D617374657240636F6E6E656374342E636F6D2E6175301E170D3030303630323037353632315A170D3031303630323037353632315A3081B8310B30090603550406130241553111300F06035504081308566963746F726961311830160603550407130F536F757468204D656C626F75726E65311A3018060355040A1311436F6E6E656374203420507479204C746431173015060355040B130E576562736572766572205465616D311D301B06035504031314777777322E636F6E6E656374342E636F6D2E6175


Mime
View raw message