harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r393374 - in /incubator/harmony/enhanced/classlib/trunk/modules: archive/src/main/java/java/util/jar/ luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ luni/src/main/java/org/apache/harmony/luni/util/ prefs/src/main...
Date Wed, 12 Apr 2006 03:48:16 GMT
Author: mloenko
Date: Tue Apr 11 20:48:13 2006
New Revision: 393374

URL: http://svn.apache.org/viewcvs?rev=393374&view=rev
Log:
Change as discussed in the
'select one (was: RE: svn commit: r391955 [5/5] - in /incubator/harmony/enhanced/...)'
mail thread: switching to a single Base64 implementation. Removing unused ASN.1 and DefaultPolicy

Removed:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ASN1Decoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ASN1Encoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ASN1Exception.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/BASE64Decoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/BASE64Encoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/DefaultPolicy.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
    incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/misc/Base64.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java?rev=393374&r1=393373&r2=393374&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarVerifier.java
Tue Apr 11 20:48:13 2006
@@ -32,7 +32,7 @@
 import java.util.Vector;
 import java.util.zip.ZipEntry;
 
-import org.apache.harmony.luni.util.BASE64Decoder;
+import org.apache.harmony.misc.Base64;
 
 import org.apache.harmony.security.utils.JarUtils;
 
@@ -366,7 +366,7 @@
 	 */
 	void verifySignatures(VerifierEntry entry, ZipEntry zipEntry) {
 		byte[] digest = entry.digest.digest();
-		if (!MessageDigest.isEqual(digest, BASE64Decoder.decode(entry.hash)))
+		if (!MessageDigest.isEqual(digest, Base64.decode(entry.hash)))
 			/* [MSG "K00ec", "{0} has invalid digest for {1} in {2}"] */
 			throw new SecurityException(Msg.getString("K00ec", new Object[] {
 					JarFile.MANIFEST_NAME, zipEntry.getName(), jarName }));
@@ -422,7 +422,7 @@
 			} catch (UnsupportedEncodingException e) {
 				throw new RuntimeException(e.toString());
 			}
-			return MessageDigest.isEqual(b, BASE64Decoder.decode(hashBytes));
+			return MessageDigest.isEqual(b, Base64.decode(hashBytes));
 		}
 		if (ignorable) {
 			return true;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java?rev=393374&r1=393373&r2=393374&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
Tue Apr 11 20:48:13 2006
@@ -941,7 +941,7 @@
 			connected = false;
 			// base64 encode the username and password
 			byte[] bytes = (pa.getUserName() + ":" + new String(pa.getPassword())).getBytes("ISO8859_1");
-			String encoded = new String(org.apache.harmony.luni.util.BASE64Encoder.encode(bytes),
"ISO8859_1");
+			String encoded = org.apache.harmony.misc.Base64.encode(bytes, "ISO8859_1");
 			setRequestProperty("Authorization", scheme + " " + encoded);
 			continue;
 		}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java?rev=393374&r1=393373&r2=393374&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
Tue Apr 11 20:48:13 2006
@@ -25,8 +25,7 @@
 import java.util.StringTokenizer;
 import java.util.TreeSet;
 
-import org.apache.harmony.luni.util.BASE64Decoder;
-import org.apache.harmony.luni.util.BASE64Encoder;
+import org.apache.harmony.misc.Base64;
 
 /**
  * This class is partly implementation of <code>Preferences</code>, which can
be 
@@ -445,7 +444,7 @@
             if (bavalue.length % 4 != 0) {
                 return deflt;
             }
-            dres = BASE64Decoder.decode(bavalue);
+            dres = Base64.decode(bavalue);
         } catch (Exception e) {
             dres = deflt;
         }
@@ -700,9 +699,8 @@
      * @see java.util.prefs.Preferences#putByteArray(java.lang.String, byte[])
      */
     public void putByteArray(String key, byte[] value) {
-        byte[] result = BASE64Encoder.encode(value);
         try {
-            put(key, new String(result, "ascii")); //$NON-NLS-1$
+            put(key, Base64.encode(value, "ascii")); //$NON-NLS-1$
         } catch (UnsupportedEncodingException e) {
             //should not happen
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/misc/Base64.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/misc/Base64.java?rev=393374&r1=393373&r2=393374&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/misc/Base64.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/misc/Base64.java
Tue Apr 11 20:48:13 2006
@@ -21,6 +21,8 @@
 
 package org.apache.harmony.misc;
 
+import java.io.UnsupportedEncodingException;
+
 /**
  * This class implements Base64 encoding/decoding functionality
  * as specified in RFC 2045 (http://www.ietf.org/rfc/rfc2045.txt).
@@ -32,59 +34,87 @@
     }
     
     public static byte[] decode(byte[] in, int len) {
+        // approximate output length
         int length = len / 4 * 3;
+        // temporary array
         byte[] out = new byte[length];
-        int pad = 0, index = 0, j = 0, bits = 0;
-        byte[] bytes = new byte[4];
+        // number of padding characters ('=')
+        int pad = 0;
         byte chr;
-        for (int i=0; i<len; i++) {
-            if (in[i] == '\n' || in[i] =='\r') {
+        // compute the number of the padding characters
+        // and adjust the length of the input
+        for (;;len--) {
+            chr = in[len-1];
+            // skip the neutral characters
+            if ((chr == '\n') || (chr == '\r') || 
+                    (chr == ' ') || (chr == '\t')) {
                 continue;
             }
+            if (chr == '=') {
+                pad++;
+            } else {
+                break;
+            }
+        }
+        // index in the output array
+        int out_index = 0;
+        // index in the input array
+        int in_index = 0;
+        // holds the value of the input character
+        int bits = 0;
+        // holds the value of the input quantum
+        int quantum = 0;
+        for (int i=0; i<len; i++) {
             chr = in[i];
-            // char ASCII value
-            //  +    43    62
-            //  /    47    63
-            //  0    48    52
-            //     .  .  .
-            //  9    57    61 (ASCII + 4)
-            //  =    61   pad
-            //  A    65    0
-            //     .  .  .
-            //  Z    90    25 (ASCII - 65)
-            //  a    97    26
-            //     .  .  .
-            //  z    122   51 (ASCII - 71)
-            if (chr == '+') {
-                bits = 62;
-            } else if (chr == '/') {
-                bits = 63;
-            } else if ((chr >= '0') && (chr <= '9')) {
-                bits = chr + 4;
-            } else if (chr == '=') {
-                bits = 0;
-                pad ++;
-            } else if ((chr >= 'A') && (chr <= 'Z')) {
+            // skip the neutral characters
+            if ((chr == '\n') || (chr == '\r') || 
+                    (chr == ' ') || (chr == '\t')) {
+                continue;
+            }
+            if ((chr >= 'A') && (chr <= 'Z')) {
+                // char ASCII value
+                //  A    65    0
+                //  Z    90    25 (ASCII - 65)
                 bits = chr - 65;
             } else if ((chr >= 'a') && (chr <= 'z')) {
+                // char ASCII value
+                //  a    97    26
+                //  z    122   51 (ASCII - 71)
                 bits = chr - 71;
+            } else if ((chr >= '0') && (chr <= '9')) {
+                // char ASCII value
+                //  0    48    52
+                //  9    57    61 (ASCII + 4)
+                bits = chr + 4;
+            } else if (chr == '+') {
+                bits = 62;
+            } else if (chr == '/') {
+                bits = 63;
             } else {
                 return null;
             }
-            bytes[j%4] = (byte) bits;
-            if (j%4 == 3) {
-                out[index++] = (byte) (bytes[0] << 2 | bytes[1] >> 4);
-                if (pad != 2) {
-                    out[index++] = (byte) (bytes[1] << 4 | bytes[2] >> 2);
-                    if (pad != 1) {
-                        out[index++] = (byte) (bytes[2] << 6 | bytes[3]);
-                    }
-                }
+            // append the value to the quantum
+            quantum = (quantum << 6) | (byte) bits;
+            if (in_index%4 == 3) {
+                // 4 characters were read, so make the output:
+                out[out_index++] = (byte) ((quantum & 0x00FF0000) >> 16);
+                out[out_index++] = (byte) ((quantum & 0x0000FF00) >> 8);
+                out[out_index++] = (byte) (quantum & 0x000000FF);
+            }
+            in_index++;
+        }
+        if (pad > 0) {
+            // adjust the quantum value according to the padding
+            quantum = quantum << (6*pad);
+            // make output
+            out[out_index++] = (byte) ((quantum & 0x00FF0000) >> 16);
+            if (pad == 1) {
+                out[out_index++] = (byte) ((quantum & 0x0000FF00) >> 8);
             }
-            j++;
         }
-        byte[] result = new byte[index];
-        System.arraycopy(out, 0, result, 0, index);
+        // create the resulting array
+        byte[] result = new byte[out_index];
+        System.arraycopy(out, 0, result, 0, out_index);
         return result;
     }
 
@@ -95,7 +125,7 @@
          'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', 
          '4', '5', '6', '7', '8', '9', '+', '/'};
 
-    public static String encode(byte[] in) {
+    public static String encode(byte[] in, String charsetName) throws UnsupportedEncodingException
{
         int length = in.length * 4 / 3;
         length += length / 76 + 3; // for crlr
         byte[] out = new byte[length];
@@ -129,7 +159,7 @@
                 out[index++] = '=';
                 break;
         }
-        return new String(out, 0, index);
+        return new String(out, 0, index, charsetName);
     }
 }
 



Mime
View raw message