harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r411980 - /incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerInputStream.java
Date Tue, 06 Jun 2006 03:31:13 GMT
Author: smishura
Date: Mon Jun  5 20:31:13 2006
New Revision: 411980

URL: http://svn.apache.org/viewvc?rev=411980&view=rev
Log:
Adding mask for verifying unused bits + minor updates

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerInputStream.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerInputStream.java?rev=411980&r1=411979&r2=411980&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerInputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/asn1/DerInputStream.java
Mon Jun  5 20:31:13 2006
@@ -62,19 +62,10 @@
         return tag;
     }
 
-    /**
-     * @see org.apache.harmony.security.asn1.BerInputStream#readBoolean()
-     */
-    public void readBoolean() throws IOException {
-
-        super.readBoolean();
+    // mask for verifying unused bits for ASN.1 bitstring
+    private static final byte[] UNUSED_BITS_MASK = new byte[] { 0x01, 0x03,
+            0x07, 0x0F, 0x1F, 0x3F, 0x7F };
 
-        // check encoded content
-        if (buffer[contentOffset] != 0 && buffer[contentOffset] != (byte) 0xFF) {
-            throw new ASN1Exception("ASN.1 boolean: wrong content at ["
-					+ contentOffset + "]. DER allows only 0x00 or 0xFF values");
-        }
-    }
 
     /**
      * @see org.apache.harmony.security.asn1.BerInputStream#readBitString()
@@ -83,24 +74,33 @@
 
         if (tag == ASN1Constants.TAG_C_BITSTRING) {
             throw new ASN1Exception(
-                    "DER: ASN.1 Bitstring type MUST have primitive encoding");
+                    "ASN.1 bitstring: constructed identifier at [" + tagOffset
+                            + "]. Not valid for DER.");
         }
 
         super.readBitString();
 
-        //check: unused bits values: MUST be 0
-        if (length > 1 && buffer[contentOffset] != 0) {
+        //check: unused bits values - MUST be 0
+        if (length > 1
+                && buffer[contentOffset] != 0
+                && (buffer[offset - 1] & UNUSED_BITS_MASK[buffer[contentOffset]
- 1]) != 0) {
+            throw new ASN1Exception("ASN.1 bitstring: wrong content at ["
+                    + contentOffset
+                    + "]. DER requires zero unused bits in final octet.");
+        }
+    }
+
+    /**
+     * @see org.apache.harmony.security.asn1.BerInputStream#readBoolean()
+     */
+    public void readBoolean() throws IOException {
 
-            byte finalOctet = buffer[offset - 1];
-            for (int i = 0; i < buffer[contentOffset]; i++) {
-                if ((finalOctet & 0x01) != 0) {
-                    throw new ASN1Exception(
-                            "DER: ASN.1 Bitstring wrong content at ["
-                                    + contentOffset
-                                    + "]. Unused bits in final octet MUST be zero");
-                }
-                finalOctet = (byte) (finalOctet >> 1);
-            }
+        super.readBoolean();
+
+        // check encoded content
+        if (buffer[contentOffset] != 0 && buffer[contentOffset] != (byte) 0xFF) {
+            throw new ASN1Exception("ASN.1 boolean: wrong content at ["
+                    + contentOffset + "]. DER allows only 0x00 or 0xFF values");
         }
     }
 



Mime
View raw message