Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 32971 invoked from network); 12 Apr 2006 03:48:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Apr 2006 03:48:42 -0000 Received: (qmail 20710 invoked by uid 500); 12 Apr 2006 03:48:41 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 20670 invoked by uid 500); 12 Apr 2006 03:48:40 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 20659 invoked by uid 99); 12 Apr 2006 03:48:40 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Apr 2006 20:48:40 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 11 Apr 2006 20:48:39 -0700 Received: (qmail 32880 invoked by uid 65534); 12 Apr 2006 03:48:19 -0000 Message-ID: <20060412034819.32879.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: harmony-commits@incubator.apache.org From: mloenko@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 Preferences, 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= '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); } }