harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r410244 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/asn1/DerOutputStream.java test/java/common/org/apache/harmony/security/asn1/der/SequenceTest.java
Date Tue, 30 May 2006 11:36:03 GMT
Author: smishura
Date: Tue May 30 04:36:02 2006
New Revision: 410244

URL: http://svn.apache.org/viewvc?rev=410244&view=rev
Log:
Bug fix for encoding sequence type: exception MUST be raised if non-optional data is missing.
Adding regression test

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerOutputStream.java
  (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/SequenceTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerOutputStream.java?rev=410244&r1=410243&r2=410244&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerOutputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerOutputStream.java
Tue May 30 04:36:02 2006
@@ -190,8 +190,13 @@
 
         int seqLen = 0;
         for (int i = 0; i < type.length; i++) {
+            // check optional types
             if (values[i] == null) {
-                continue; //FIXME raise exception if non-optional data is missing
+                if (sequence.OPTIONAL[i]) {
+                    continue;
+                } else {
+                    throw new RuntimeException();//FIXME type & message
+                }
             }
 
             if (sequence.DEFAULT[i] != null

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/SequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/SequenceTest.java?rev=410244&r1=410243&r2=410244&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/SequenceTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/SequenceTest.java
Tue May 30 04:36:02 2006
@@ -102,19 +102,19 @@
                 // format: object to encode / byte array 
 
                 // sequence : all values are default
-                new Object[] { new AppClass(Boolean.TRUE, defaultList),
+                { new AppClass(Boolean.TRUE, defaultList),
                         new byte[] { 0x30, 0x00 } },
 
                 // sequence : true, default
-                new Object[] { new AppClass(Boolean.FALSE, defaultList),
+                { new AppClass(Boolean.FALSE, defaultList),
                         new byte[] { 0x30, 0x03, 0x01, 0x01, 0x00 } },
 
                 // sequence = default, empty sequence
-                new Object[] { new AppClass(Boolean.TRUE, new ArrayList()),
+                { new AppClass(Boolean.TRUE, new ArrayList()),
                         new byte[] { 0x30, 0x02, 0x30, 0x00 } },
 
                 // sequence = false, empty sequence
-                new Object[] { new AppClass(Boolean.FALSE, new ArrayList()),
+                { new AppClass(Boolean.FALSE, new ArrayList()),
                         new byte[] { 0x30, 0x05, 0x01, 0x01, 0x00, 0x30, 0x00 } },
 
         //TODO add testcase for another ASN.1 type` 
@@ -193,6 +193,9 @@
         }
     }
 
+    /**
+     * Tests encoding default fields 
+     */
     public void testEncodeDefault() throws IOException {
 
         //
@@ -229,5 +232,46 @@
 
         encoded = s.encode(new Object[] { new byte[] { 0x01 } });
         assertTrue("Encoded integer:", Arrays.equals(expectedArray, encoded));
+    }
+    
+    /**
+     * Tests encoding optional fields 
+     */
+    public void testEncodeOptional() throws IOException {
+
+        //
+        // Test not optional
+        //
+        ASN1Sequence s = new ASN1Sequence(new ASN1Type[] { ASN1Boolean
+                .getInstance() }) {
+
+            protected void getValues(Object object, Object[] values) {
+                values[0] = ((Object[]) object)[0];
+            }
+        };
+
+        try {
+            s.encode(new Object[] { null });
+            fail("No expected RuntimeException"); 
+        } catch (RuntimeException e) {
+        }
+
+        //
+        // Test optional
+        //
+        s = new ASN1Sequence(new ASN1Type[] { ASN1Boolean.getInstance() }) {
+            {
+                setOptional(0);
+            }
+
+            protected void getValues(Object object, Object[] values) {
+                values[0] = ((Object[]) object)[0];
+            }
+        };
+
+        byte[] expectedArray = new byte[] { 0x30, 0x00 };
+
+        byte[] encoded = s.encode(new Object[] { null });
+        assertTrue("Encoded boolean:", Arrays.equals(expectedArray, encoded));
     }
 }



Mime
View raw message