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: DIRKRB-493. Fixed a CMS signed data encoding issue
Date Thu, 10 Dec 2015 00:54:15 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 8fc0a9c98 -> c4b11ccba


DIRKRB-493. Fixed a CMS signed data encoding issue


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

Branch: refs/heads/master
Commit: c4b11ccbab7120ad2f3f43c9d94e373167c59aac
Parents: 8fc0a9c
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Thu Dec 10 08:53:56 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Thu Dec 10 08:53:56 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/asn1/type/Asn1Any.java     | 26 ++++++++++++++++++--
 .../org/apache/kerby/cms/TestSignedData.java    | 23 +++++++++--------
 2 files changed, 37 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c4b11ccb/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 0debce1..daff598 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
@@ -21,6 +21,7 @@ package org.apache.kerby.asn1.type;
 
 import org.apache.kerby.asn1.Asn1Binder;
 import org.apache.kerby.asn1.Asn1FieldInfo;
+import org.apache.kerby.asn1.Tag;
 import org.apache.kerby.asn1.UniversalTag;
 import org.apache.kerby.asn1.parse.Asn1ParseResult;
 
@@ -56,8 +57,24 @@ public class Asn1Any extends AbstractAsn1Type<Asn1Type> {
     }
 
     @Override
+    public Tag tag() {
+        if (getValue() != null) {
+            return getValue().tag();
+        } else if (field != null) {
+            return field.tag();
+        }
+        return super.tag();
+    }
+
+    @Override
     protected int encodingBodyLength() {
-        return ((Asn1Encodeable) getValue()).encodingBodyLength();
+        if (getValue() != null) {
+            return ((Asn1Encodeable) getValue()).encodingBodyLength();
+        } else if (field != null) {
+            return field.getBodyLength();
+        }
+
+        return -1;
     }
 
     @Override
@@ -67,7 +84,12 @@ public class Asn1Any extends AbstractAsn1Type<Asn1Type> {
 
     @Override
     protected void encodeBody(ByteBuffer buffer) {
-        ((Asn1Encodeable) getValue()).encodeBody(buffer);
+        if (getValue() != null) {
+            ((Asn1Encodeable) getValue()).encodeBody(buffer);
+        } else if (field != null) {
+            buffer.put(field.getBodyBuffer());
+        }
+
     }
 
     protected <T extends Asn1Type> T getValueAs(Class<T> t) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c4b11ccb/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 55c1646..bd2cef1 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
@@ -32,7 +32,7 @@ import java.io.IOException;
 public class TestSignedData extends CmsTestBase {
 
     @Test
-    public void testDump1WithSignedData() throws IOException {
+    public void testDecoding() throws IOException {
         byte[] data = readDataFile("/signed-data.txt");
         try {
             Asn1.dump(data, true);
@@ -44,6 +44,9 @@ public class TestSignedData extends CmsTestBase {
             SignedData signedData =
                 contentInfo.getContentAs(SignedData.class);
             Asn1.dump(signedData);
+
+            byte[] encodedData = contentInfo.encode();
+            Asn1.dump(encodedData, true);
         } catch (Exception e) {
             e.printStackTrace();
             Assert.fail();
@@ -51,7 +54,7 @@ public class TestSignedData extends CmsTestBase {
     }
 
     @Test
-    public void testDecodeSignedData() throws IOException {
+    public void testEncoding() throws IOException {
         ContentInfo contentInfo = new ContentInfo();
         contentInfo.setContentType(new Asn1ObjectIdentifier("1.2.840.113549.1.7.2"));
         SignedData signedData = new SignedData();
@@ -61,15 +64,15 @@ public class TestSignedData extends CmsTestBase {
         signedData.setEncapContentInfo(eContentInfo);
         contentInfo.setContent(signedData);
         Asn1.dump(contentInfo);
-        Asn1.dump(contentInfo.encode(), true);
+        byte[] encodedData = contentInfo.encode();
+        Asn1.dump(encodedData, true);
 
-        ContentInfo actualContentInfo = new ContentInfo();
-        actualContentInfo.decode(contentInfo.encode());
-        Asn1.dump(actualContentInfo);
+        ContentInfo decodedContentInfo = new ContentInfo();
+        decodedContentInfo.decode(encodedData);
+        Asn1.dump(decodedContentInfo);
 
-        /* Fail
-        SignedData actualSignedData =
-                actualContentInfo.getContentAs(SignedData.class);
-                */
+        SignedData decodedSignedData =
+                decodedContentInfo.getContentAs(SignedData.class);
+        Asn1.dump(decodedSignedData);
     }
 }


Mime
View raw message