Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update command stuff to work a bit nicer

  • Loading branch information...
commit a94cdb1f7f7242e65ccb6d3c4647f1431bf1b457 1 parent ecd0669
Dave Johnson authored
2  README.md
Source Rendered
@@ -36,7 +36,7 @@ Building PhoneGap BlackBerry Projects from Eclipse
36 36 If you want to run things from Eclipse you can do that too. Of course it helps a lot with debugging.
37 37
38 38 1. Launch Eclipse, go to File->New->BlackBerry project.
39   -2. Choose "Use Existing Source" and navigate to the folder that you specified as the output.dir in step 5 above.
  39 +2. Choose "Create project from existing source" point it to the folder that you specified as the output.dir in step 5 above.
40 40 3. Modify the contents of the "www" directory to add your own HTML, CSS and Javascript.
41 41 4. Create a linked folder in the src folder to the www folder, this is important otherwise Eclipse will not deploy your www folder to the device / simulator.
42 42 5. Run or debug from Eclipse as desired. NOTE: Whatever simulator or device you are running / debugging on must have the PhoneGapBlackBerryLib.cod on that device - this is most easily achieved by running 'ant load-simulator' or load-device as in step 6 above.
2  build.xml
@@ -99,7 +99,7 @@ var alert=function(){},device={},Element={};
99 99 <propertyregex property="app.jde.home"
100 100 input="${jde.home}"
101 101 regexp="\\"
102   - replace="\\\\"
  102 + replace="\\\\\\\\"
103 103 global="true" />
104 104
105 105 <mkdir dir="${output.dir}" />
2  framework/common.properties
... ... @@ -1,5 +1,5 @@
1 1 jde.java.home = ${java.home}
2   -jde.home = C:\\Program Files\\eclipse\\plugins\\net.rim.ejde.componentpack4.7.0_4.7.0.57\\components
  2 +jde.home = C:\\Program Files\\eclipse-3.5\\plugins\\net.rim.ejde.componentpack4.7.0_4.7.0.57\\components
3 3 simulator.home = ${jde.home}\\simulator
4 4 mds.home = ${jde.home}\\MDS
5 5 sigtool.jde = ${jde.home}
3  framework/src/com/phonegap/PhoneGap.java
@@ -241,8 +241,7 @@ public void run() {
241 241 response = null;
242 242 } catch (JSONException e) {
243 243 pendingResponses.addElement(
244   - new CommandResult(CommandResult.Status.JSONEXCEPTION, "{message: 'foo'}")
245   - .toErrorString());
  244 + new CommandResult(CommandResult.Status.JSON_EXCEPTION, "").toErrorString());
246 245 }
247 246 }
248 247 cookie = null;
11 framework/src/com/phonegap/api/CommandManager.java
@@ -121,20 +121,17 @@ public void run() {
121 121 cr = plugin.execute(action, args);
122 122 }
123 123 } catch (ClassNotFoundException e) {
124   - cr = new CommandResult(CommandResult.Status.CLASSNOTFOUNDEXCEPTION,
125   - "{ message: 'ClassNotFoundException', status: "+CommandResult.Status.CLASSNOTFOUNDEXCEPTION.ordinal()+" }");
  124 + cr = new CommandResult(CommandResult.Status.CLASS_NOT_FOUND_EXCEPTION);
126 125 } catch (IllegalAccessException e) {
127   - cr = new CommandResult(CommandResult.Status.ILLEGALACCESSEXCEPTION,
128   - "{ message: 'IllegalAccessException', status: "+CommandResult.Status.ILLEGALACCESSEXCEPTION.ordinal()+" }");
  126 + cr = new CommandResult(CommandResult.Status.ILLEGAL_ACCESS_EXCEPTION);
129 127 } catch (InstantiationException e) {
130   - cr = new CommandResult(CommandResult.Status.INSTANTIATIONEXCEPTION,
131   - "{ message: 'InstantiationException', status: "+CommandResult.Status.INSTANTIATIONEXCEPTION.ordinal()+" }");
  128 + cr = new CommandResult(CommandResult.Status.INSTANTIATION_EXCEPTION);
132 129 }
133 130 // if async we have already returned at this point unless there was an error...
134 131 if (async) {
135 132 app.loadUrl(cr.toErrorCallbackString(callbackId));
136 133 }
137   - return ( cr != null ? cr.getResult() : "{ status: 0, message: 'all good' }" );
  134 + return ( cr != null ? cr.getMessage() : "{ status: 0, message: 'all good' }" );
138 135 }
139 136
140 137 public void stopXHR() {
81 framework/src/com/phonegap/api/CommandResult.java
... ... @@ -1,53 +1,78 @@
1 1 package com.phonegap.api;
2 2
  3 +import org.json.me.JSONObject;
  4 +
3 5 public class CommandResult {
4 6 private final int status;
5   - private final String result;
  7 + private final String message;
  8 +
  9 + public CommandResult(Status status) {
  10 + this.status = status.ordinal();
  11 + this.message = CommandResult.StatusMessages[this.status];
  12 + }
6 13
7   - public CommandResult(Status status, String result) {
  14 + public CommandResult(Status status, String message) {
8 15 this.status = status.ordinal();
9   - this.result = result;
  16 + this.message = "'" + message + "'";
10 17 }
11 18
  19 + public CommandResult(Status status, JSONObject message) {
  20 + this.status = status.ordinal();
  21 + this.message = message.toString();
  22 + }
  23 +
12 24 public int getStatus() {
13 25 return status;
14 26 }
15 27
16   - public String getResult() {
17   - return result;
  28 + public String getMessage() {
  29 + return message;
  30 + }
  31 +
  32 + public String getJSONString() {
  33 + return "{ status: " + this.getStatus() + ", message: " + this.getMessage() + " }";
18 34 }
19 35
20 36 public String toSuccessCallbackString(String callbackId) {
21   - return "try { PhoneGap.callbackSuccess('"+callbackId+"', " + this.getResult()+ "); } catch(e) { alert('error in callbackSuccess. probably badly formed callback JSON'); }";
  37 + return "javascript:PhoneGap.callbackSuccess('"+callbackId+"', " + this.getJSONString() + " );";
22 38 }
23 39
24 40 public String toErrorCallbackString(String callbackId) {
25   - return "try { PhoneGap.callbackError('"+callbackId+"', " + this.getResult()+ "); } catch(e) { alert('error in callbackError. probably badly formed callback JSON'); }";
  41 + return "javascript:PhoneGap.callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
26 42 }
27 43
28 44 public String toErrorString() {
29 45 return "alert('general error');";
30   - //return "PhoneGap.error(" + this.getResult()+ ");";
31   - }
32   -
33   - public static class Status
34   - {
35   - private int val;
36   - private Status(int val) {
37   - this.val = val;
38   - }
39   -
40   - public int ordinal() {
41   - return this.val;
42   - }
  46 + }
  47 +
  48 + public static class Status {
  49 + private int val;
  50 + private Status(int val) {
  51 + this.val = val;
  52 + }
  53 +
  54 + public int ordinal() {
  55 + return this.val;
  56 + }
43 57
44   - public static final Status OK = new Status(0);
45   - public static final Status CLASSNOTFOUNDEXCEPTION = new Status(1);
46   - public static final Status ILLEGALACCESSEXCEPTION = new Status(2);
47   - public static final Status INSTANTIATIONEXCEPTION = new Status(3);
48   - public static final Status MALFORMEDURLEXCEPTION = new Status(4);
49   - public static final Status IOEXCEPTION = new Status(5);
50   - public static final Status INVALIDACTION = new Status(6);
51   - public static final Status JSONEXCEPTION = new Status(7);
  58 + public static final Status OK = new Status(0);
  59 + public static final Status CLASS_NOT_FOUND_EXCEPTION = new Status(1);
  60 + public static final Status ILLEGAL_ACCESS_EXCEPTION = new Status(2);
  61 + public static final Status INSTANTIATION_EXCEPTION = new Status(3);
  62 + public static final Status MALFORMED_URL_EXCEPTION = new Status(4);
  63 + public static final Status IO_EXCEPTION = new Status(5);
  64 + public static final Status INVALID_ACTION = new Status(6);
  65 + public static final Status JSON_EXCEPTION = new Status(7);
52 66 }
  67 +
  68 + public static String[] StatusMessages = new String[] {
  69 + "OK",
  70 + "Class not found",
  71 + "Illegal access",
  72 + "Instantiation error",
  73 + "Malformed url",
  74 + "IO error",
  75 + "Invalid action",
  76 + "JSON error"
  77 + };
53 78 }
522 framework/src/com/twmacinta/util/MD5.java
... ... @@ -1,522 +0,0 @@
1   -package com.twmacinta.util;
2   -
3   -/**
4   - * Fast implementation of RSA's MD5 hash generator in Java JDK Beta-2 or higher.
5   - * <p>
6   - * Originally written by Santeri Paavolainen, Helsinki Finland 1996.<br>
7   - * (c) Santeri Paavolainen, Helsinki Finland 1996<br>
8   - * Many changes Copyright (c) 2002 - 2005 Timothy W Macinta<br>
9   - * <p>
10   - * This library is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU Library General Public License as published by the Free
12   - * Software Foundation; either version 2.1 of the License, or (at your option)
13   - * any later version.
14   - * <p>
15   - * This library is distributed in the hope that it will be useful, but WITHOUT
16   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17   - * FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
18   - * details.
19   - * <p>
20   - * You should have received a copy of the GNU Library General Public License
21   - * along with this library; if not, write to the Free Software Foundation, Inc.,
22   - * 675 Mass Ave, Cambridge, MA 02139, USA.
23   - * <p>
24   - * See http://www.twmacinta.com/myjava/fast_md5.php for more information on this
25   - * file and the related files.
26   - * <p>
27   - * This was originally a rather straight re-implementation of the reference
28   - * implementation given in RFC1321 by RSA. It passes the MD5 test suite as
29   - * defined in RFC1321.
30   - * <p>
31   - * Many optimizations made by Timothy W Macinta. Reduced time to checksum a test
32   - * file in Java alone to roughly half the time taken compared with
33   - * java.security.MessageDigest (within an intepretter). Also added an optional
34   - * native method to reduce the time even further. See
35   - * http://www.twmacinta.com/myjava/fast_md5.php for further information on the
36   - * time improvements achieved.
37   - * <p>
38   - * Some bug fixes also made by Timothy W Macinta.
39   - * <p>
40   - * Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util
41   - * package only because it came without a package. I was not the the original
42   - * author of the code, although I did optimize it (substantially) and fix some
43   - * bugs.
44   - * <p>
45   - * This Java class has been derived from the RSA Data Security, Inc. MD5
46   - * Message-Digest Algorithm and its reference implementation.
47   - * <p>
48   - * This class will attempt to use a native method to quickly compute checksums
49   - * when the appropriate native library is available. On Linux, this library
50   - * should be named "MD5.so" and on Windows it should be named "MD5.dll". The
51   - * code will attempt to locate the library in the following locations in the
52   - * order given:
53   - *
54   - * <ol>
55   - * <li>The path specified by the system property
56   - * "com.twmacinta.util.MD5.NATIVE_LIB_FILE" (be sure to include "MD5.so" or
57   - * "MD5.dll" as appropriate at the end of the path).
58   - * <li>A platform specific directory beneath the "lib/arch/" directory. On
59   - * Linux for x86, this is "lib/arch/linux_x86/". On Windows for x86, this is
60   - * "lib/arch/win32_x86/".
61   - * <li>Within the "lib/" directory.
62   - * <li>Within the current directory.
63   - * </ol>
64   - *
65   - * <p>
66   - * If the library is not found, the code will fall back to the default (slower)
67   - * Java code.
68   - * <p>
69   - * As a side effect of having the code search for the native library,
70   - * SecurityExceptions might be thrown on JVMs that have a restrictive
71   - * SecurityManager. The initialization code attempts to silently discard these
72   - * exceptions and continue, but many SecurityManagers will attempt to notify the
73   - * user directly of all SecurityExceptions thrown. Consequently, the code has
74   - * provisions for skipping the search for the native library. Any of these
75   - * provisions may be used to skip the search as long as they are performed
76   - * <i>before</i> the first instance of a com.twmacinta.util.MD5 object is
77   - * constructed (note that the convenience stream objects will implicitly create
78   - * an MD5 object).
79   - * <p>
80   - * The first option is to set the system property
81   - * "com.twmacinta.util.MD5.NO_NATIVE_LIB" to "true" or "1". Unfortunately,
82   - * SecurityManagers may also choose to disallow system property setting, so this
83   - * won't be of use in all cases.
84   - * <p>
85   - * The second option is to call com.twmacinta.util.MD5.initNativeLibrary(true)
86   - * before any MD5 objects are constructed.
87   - *
88   - * @author Santeri Paavolainen <sjpaavol@cc.helsinki.fi>
89   - * @author Timothy W Macinta (twm@alum.mit.edu) (optimizations and bug fixes)
90   - */
91   -
92   -public class MD5 {
93   - private static final char[] HEX_CHARS = {
94   - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
95   - };
96   -
97   - private MD5State state;
98   - private MD5State finals;
99   -
100   - private static final byte padding[] = { (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103   - 0, 0, 0, 0, 0, 0, 0, 0 };
104   -
105   - /*
106   - * len += shift; for (int i = 0; shift < len; i++, shift += 4) { out[i] =
107   - * ((int) (buffer[shift] & 0xff)) | (((int) (buffer[shift + 1] & 0xff)) <<
108   - * 8) | (((int) (buffer[shift + 2] & 0xff)) << 16) | (((int)
109   - * buffer[shift + 3]) << 24); }
110   - */
111   - private final void decode( final byte buffer[], final int shift, final int[] out) {
112   - out[0] = (buffer[shift] & 0xff) | ((buffer[shift + 1] & 0xff) << 8)
113   - | ((buffer[shift + 2] & 0xff) << 16)
114   - | (buffer[shift + 3] << 24);
115   - out[1] = (buffer[shift + 4] & 0xff) | ((buffer[shift + 5] & 0xff) << 8)
116   - | ((buffer[shift + 6] & 0xff) << 16)
117   - | (buffer[shift + 7] << 24);
118   - out[2] = (buffer[shift + 8] & 0xff) | ((buffer[shift + 9] & 0xff) << 8)
119   - | ((buffer[shift + 10] & 0xff) << 16)
120   - | (buffer[shift + 11] << 24);
121   - out[3] = (buffer[shift + 12] & 0xff)
122   - | ((buffer[shift + 13] & 0xff) << 8)
123   - | ((buffer[shift + 14] & 0xff) << 16)
124   - | (buffer[shift + 15] << 24);
125   - out[4] = (buffer[shift + 16] & 0xff)
126   - | ((buffer[shift + 17] & 0xff) << 8)
127   - | ((buffer[shift + 18] & 0xff) << 16)
128   - | (buffer[shift + 19] << 24);
129   - out[5] = (buffer[shift + 20] & 0xff)
130   - | ((buffer[shift + 21] & 0xff) << 8)
131   - | ((buffer[shift + 22] & 0xff) << 16)
132   - | (buffer[shift + 23] << 24);
133   - out[6] = (buffer[shift + 24] & 0xff)
134   - | ((buffer[shift + 25] & 0xff) << 8)
135   - | ((buffer[shift + 26] & 0xff) << 16)
136   - | (buffer[shift + 27] << 24);
137   - out[7] = (buffer[shift + 28] & 0xff)
138   - | ((buffer[shift + 29] & 0xff) << 8)
139   - | ((buffer[shift + 30] & 0xff) << 16)
140   - | (buffer[shift + 31] << 24);
141   - out[8] = (buffer[shift + 32] & 0xff)
142   - | ((buffer[shift + 33] & 0xff) << 8)
143   - | ((buffer[shift + 34] & 0xff) << 16)
144   - | (buffer[shift + 35] << 24);
145   - out[9] = (buffer[shift + 36] & 0xff)
146   - | ((buffer[shift + 37] & 0xff) << 8)
147   - | ((buffer[shift + 38] & 0xff) << 16)
148   - | (buffer[shift + 39] << 24);
149   - out[10] = (buffer[shift + 40] & 0xff)
150   - | ((buffer[shift + 41] & 0xff) << 8)
151   - | ((buffer[shift + 42] & 0xff) << 16)
152   - | (buffer[shift + 43] << 24);
153   - out[11] = (buffer[shift + 44] & 0xff)
154   - | ((buffer[shift + 45] & 0xff) << 8)
155   - | ((buffer[shift + 46] & 0xff) << 16)
156   - | (buffer[shift + 47] << 24);
157   - out[12] = (buffer[shift + 48] & 0xff)
158   - | ((buffer[shift + 49] & 0xff) << 8)
159   - | ((buffer[shift + 50] & 0xff) << 16)
160   - | (buffer[shift + 51] << 24);
161   - out[13] = (buffer[shift + 52] & 0xff)
162   - | ((buffer[shift + 53] & 0xff) << 8)
163   - | ((buffer[shift + 54] & 0xff) << 16)
164   - | (buffer[shift + 55] << 24);
165   - out[14] = (buffer[shift + 56] & 0xff)
166   - | ((buffer[shift + 57] & 0xff) << 8)
167   - | ((buffer[shift + 58] & 0xff) << 16)
168   - | (buffer[shift + 59] << 24);
169   - out[15] = (buffer[shift + 60] & 0xff)
170   - | ((buffer[shift + 61] & 0xff) << 8)
171   - | ((buffer[shift + 62] & 0xff) << 16)
172   - | (buffer[shift + 63] << 24);
173   - }
174   -
175   - private final void transform(MD5State state, byte buffer[], int shift, int[] decode_buf) {
176   - int a = state.state[0], b = state.state[1], c = state.state[2], d = state.state[3], x[] = decode_buf;
177   -
178   - decode(buffer, shift, decode_buf);
179   -
180   - /* Round 1 */
181   - a += ((b & c) | (~b & d)) + x[0] + 0xd76aa478; /* 1 */
182   - a = ((a << 7) | (a >>> 25)) + b;
183   - d += ((a & b) | (~a & c)) + x[1] + 0xe8c7b756; /* 2 */
184   - d = ((d << 12) | (d >>> 20)) + a;
185   - c += ((d & a) | (~d & b)) + x[2] + 0x242070db; /* 3 */
186   - c = ((c << 17) | (c >>> 15)) + d;
187   - b += ((c & d) | (~c & a)) + x[3] + 0xc1bdceee; /* 4 */
188   - b = ((b << 22) | (b >>> 10)) + c;
189   -
190   - a += ((b & c) | (~b & d)) + x[4] + 0xf57c0faf; /* 5 */
191   - a = ((a << 7) | (a >>> 25)) + b;
192   - d += ((a & b) | (~a & c)) + x[5] + 0x4787c62a; /* 6 */
193   - d = ((d << 12) | (d >>> 20)) + a;
194   - c += ((d & a) | (~d & b)) + x[6] + 0xa8304613; /* 7 */
195   - c = ((c << 17) | (c >>> 15)) + d;
196   - b += ((c & d) | (~c & a)) + x[7] + 0xfd469501; /* 8 */
197   - b = ((b << 22) | (b >>> 10)) + c;
198   -
199   - a += ((b & c) | (~b & d)) + x[8] + 0x698098d8; /* 9 */
200   - a = ((a << 7) | (a >>> 25)) + b;
201   - d += ((a & b) | (~a & c)) + x[9] + 0x8b44f7af; /* 10 */
202   - d = ((d << 12) | (d >>> 20)) + a;
203   - c += ((d & a) | (~d & b)) + x[10] + 0xffff5bb1; /* 11 */
204   - c = ((c << 17) | (c >>> 15)) + d;
205   - b += ((c & d) | (~c & a)) + x[11] + 0x895cd7be; /* 12 */
206   - b = ((b << 22) | (b >>> 10)) + c;
207   -
208   - a += ((b & c) | (~b & d)) + x[12] + 0x6b901122; /* 13 */
209   - a = ((a << 7) | (a >>> 25)) + b;
210   - d += ((a & b) | (~a & c)) + x[13] + 0xfd987193; /* 14 */
211   - d = ((d << 12) | (d >>> 20)) + a;
212   - c += ((d & a) | (~d & b)) + x[14] + 0xa679438e; /* 15 */
213   - c = ((c << 17) | (c >>> 15)) + d;
214   - b += ((c & d) | (~c & a)) + x[15] + 0x49b40821; /* 16 */
215   - b = ((b << 22) | (b >>> 10)) + c;
216   -
217   - /* Round 2 */
218   - a += ((b & d) | (c & ~d)) + x[1] + 0xf61e2562; /* 17 */
219   - a = ((a << 5) | (a >>> 27)) + b;
220   - d += ((a & c) | (b & ~c)) + x[6] + 0xc040b340; /* 18 */
221   - d = ((d << 9) | (d >>> 23)) + a;
222   - c += ((d & b) | (a & ~b)) + x[11] + 0x265e5a51; /* 19 */
223   - c = ((c << 14) | (c >>> 18)) + d;
224   - b += ((c & a) | (d & ~a)) + x[0] + 0xe9b6c7aa; /* 20 */
225   - b = ((b << 20) | (b >>> 12)) + c;
226   -
227   - a += ((b & d) | (c & ~d)) + x[5] + 0xd62f105d; /* 21 */
228   - a = ((a << 5) | (a >>> 27)) + b;
229   - d += ((a & c) | (b & ~c)) + x[10] + 0x02441453; /* 22 */
230   - d = ((d << 9) | (d >>> 23)) + a;
231   - c += ((d & b) | (a & ~b)) + x[15] + 0xd8a1e681; /* 23 */
232   - c = ((c << 14) | (c >>> 18)) + d;
233   - b += ((c & a) | (d & ~a)) + x[4] + 0xe7d3fbc8; /* 24 */
234   - b = ((b << 20) | (b >>> 12)) + c;
235   -
236   - a += ((b & d) | (c & ~d)) + x[9] + 0x21e1cde6; /* 25 */
237   - a = ((a << 5) | (a >>> 27)) + b;
238   - d += ((a & c) | (b & ~c)) + x[14] + 0xc33707d6; /* 26 */
239   - d = ((d << 9) | (d >>> 23)) + a;
240   - c += ((d & b) | (a & ~b)) + x[3] + 0xf4d50d87; /* 27 */
241   - c = ((c << 14) | (c >>> 18)) + d;
242   - b += ((c & a) | (d & ~a)) + x[8] + 0x455a14ed; /* 28 */
243   - b = ((b << 20) | (b >>> 12)) + c;
244   -
245   - a += ((b & d) | (c & ~d)) + x[13] + 0xa9e3e905; /* 29 */
246   - a = ((a << 5) | (a >>> 27)) + b;
247   - d += ((a & c) | (b & ~c)) + x[2] + 0xfcefa3f8; /* 30 */
248   - d = ((d << 9) | (d >>> 23)) + a;
249   - c += ((d & b) | (a & ~b)) + x[7] + 0x676f02d9; /* 31 */
250   - c = ((c << 14) | (c >>> 18)) + d;
251   - b += ((c & a) | (d & ~a)) + x[12] + 0x8d2a4c8a; /* 32 */
252   - b = ((b << 20) | (b >>> 12)) + c;
253   -
254   - /* Round 3 */
255   - a += (b ^ c ^ d) + x[5] + 0xfffa3942; /* 33 */
256   - a = ((a << 4) | (a >>> 28)) + b;
257   - d += (a ^ b ^ c) + x[8] + 0x8771f681; /* 34 */
258   - d = ((d << 11) | (d >>> 21)) + a;
259   - c += (d ^ a ^ b) + x[11] + 0x6d9d6122; /* 35 */
260   - c = ((c << 16) | (c >>> 16)) + d;
261   - b += (c ^ d ^ a) + x[14] + 0xfde5380c; /* 36 */
262   - b = ((b << 23) | (b >>> 9)) + c;
263   -
264   - a += (b ^ c ^ d) + x[1] + 0xa4beea44; /* 37 */
265   - a = ((a << 4) | (a >>> 28)) + b;
266   - d += (a ^ b ^ c) + x[4] + 0x4bdecfa9; /* 38 */
267   - d = ((d << 11) | (d >>> 21)) + a;
268   - c += (d ^ a ^ b) + x[7] + 0xf6bb4b60; /* 39 */
269   - c = ((c << 16) | (c >>> 16)) + d;
270   - b += (c ^ d ^ a) + x[10] + 0xbebfbc70; /* 40 */
271   - b = ((b << 23) | (b >>> 9)) + c;
272   -
273   - a += (b ^ c ^ d) + x[13] + 0x289b7ec6; /* 41 */
274   - a = ((a << 4) | (a >>> 28)) + b;
275   - d += (a ^ b ^ c) + x[0] + 0xeaa127fa; /* 42 */
276   - d = ((d << 11) | (d >>> 21)) + a;
277   - c += (d ^ a ^ b) + x[3] + 0xd4ef3085; /* 43 */
278   - c = ((c << 16) | (c >>> 16)) + d;
279   - b += (c ^ d ^ a) + x[6] + 0x04881d05; /* 44 */
280   - b = ((b << 23) | (b >>> 9)) + c;
281   -
282   - a += (b ^ c ^ d) + x[9] + 0xd9d4d039; /* 33 */
283   - a = ((a << 4) | (a >>> 28)) + b;
284   - d += (a ^ b ^ c) + x[12] + 0xe6db99e5; /* 34 */
285   - d = ((d << 11) | (d >>> 21)) + a;
286   - c += (d ^ a ^ b) + x[15] + 0x1fa27cf8; /* 35 */
287   - c = ((c << 16) | (c >>> 16)) + d;
288   - b += (c ^ d ^ a) + x[2] + 0xc4ac5665; /* 36 */
289   - b = ((b << 23) | (b >>> 9)) + c;
290   -
291   - /* Round 4 */
292   - a += (c ^ (b | ~d)) + x[0] + 0xf4292244; /* 49 */
293   - a = ((a << 6) | (a >>> 26)) + b;
294   - d += (b ^ (a | ~c)) + x[7] + 0x432aff97; /* 50 */
295   - d = ((d << 10) | (d >>> 22)) + a;
296   - c += (a ^ (d | ~b)) + x[14] + 0xab9423a7; /* 51 */
297   - c = ((c << 15) | (c >>> 17)) + d;
298   - b += (d ^ (c | ~a)) + x[5] + 0xfc93a039; /* 52 */
299   - b = ((b << 21) | (b >>> 11)) + c;
300   -
301   - a += (c ^ (b | ~d)) + x[12] + 0x655b59c3; /* 53 */
302   - a = ((a << 6) | (a >>> 26)) + b;
303   - d += (b ^ (a | ~c)) + x[3] + 0x8f0ccc92; /* 54 */
304   - d = ((d << 10) | (d >>> 22)) + a;
305   - c += (a ^ (d | ~b)) + x[10] + 0xffeff47d; /* 55 */
306   - c = ((c << 15) | (c >>> 17)) + d;
307   - b += (d ^ (c | ~a)) + x[1] + 0x85845dd1; /* 56 */
308   - b = ((b << 21) | (b >>> 11)) + c;
309   -
310   - a += (c ^ (b | ~d)) + x[8] + 0x6fa87e4f; /* 57 */
311   - a = ((a << 6) | (a >>> 26)) + b;
312   - d += (b ^ (a | ~c)) + x[15] + 0xfe2ce6e0; /* 58 */
313   - d = ((d << 10) | (d >>> 22)) + a;
314   - c += (a ^ (d | ~b)) + x[6] + 0xa3014314; /* 59 */
315   - c = ((c << 15) | (c >>> 17)) + d;
316   - b += (d ^ (c | ~a)) + x[13] + 0x4e0811a1; /* 60 */
317   - b = ((b << 21) | (b >>> 11)) + c;
318   -
319   - a += (c ^ (b | ~d)) + x[4] + 0xf7537e82; /* 61 */
320   - a = ((a << 6) | (a >>> 26)) + b;
321   - d += (b ^ (a | ~c)) + x[11] + 0xbd3af235; /* 62 */
322   - d = ((d << 10) | (d >>> 22)) + a;
323   - c += (a ^ (d | ~b)) + x[2] + 0x2ad7d2bb; /* 63 */
324   - c = ((c << 15) | (c >>> 17)) + d;
325   - b += (d ^ (c | ~a)) + x[9] + 0xeb86d391; /* 64 */
326   - b = ((b << 21) | (b >>> 11)) + c;
327   -
328   - state.state[0] += a;
329   - state.state[1] += b;
330   - state.state[2] += c;
331   - state.state[3] += d;
332   - System.gc();
333   - }
334   -
335   - /**
336   - * Updates hash with the bytebuffer given (using at maximum length bytes
337   - * from that buffer)
338   - *
339   - * @param stat
340   - * Which state is updated
341   - * @param buffer
342   - * Array of bytes to be hashed
343   - * @param offset
344   - * Offset to buffer array
345   - * @param length
346   - * Use at maximum `length' bytes (absolute maximum is
347   - * buffer.length)
348   - */
349   - private final void update(MD5State stat, byte buffer[], int offset, int length) {
350   - int index, partlen, i, start;
351   - finals = null;
352   - /* Length can be told to be shorter, but not inter */
353   - if ((length - offset) > buffer.length)
354   - length = buffer.length - offset;
355   -
356   - /* compute number of bytes mod 64 */
357   -
358   - index = (int) (stat.count & 0x3f);
359   - stat.count += length;
360   -
361   - partlen = 64 - index;
362   -
363   - if (length >= partlen) {
364   - // update state (using only Java) to reflect input
365   - int[] decode_buf = new int[16];
366   - if (partlen == 64) {
367   - partlen = 0;
368   - } else {
369   - for (i = 0; i < partlen; i++)
370   - stat.buffer[i + index] = buffer[i + offset];
371   - transform(stat, stat.buffer, 0, decode_buf);
372   - }
373   - for (i = partlen; (i + 63) < length; i += 64) {
374   - transform(stat, buffer, i + offset, decode_buf);
375   - }
376   - index = 0;
377   - } else
378   - i = 0;
379   - /* buffer remaining input */
380   - if (i < length) {
381   - start = i;
382   - for (; i < length; i++) {
383   - stat.buffer[index + i - start] = buffer[i + offset];
384   - }
385   - }
386   - }
387   -
388   - private static final byte[] encode( final int input[], final int len) {
389   - int i, j;
390   - byte out[];
391   - out = new byte[len];
392   - for (i = j = 0; j < len; i++, j += 4) {
393   - out[j] = (byte) (input[i] & 0xff);
394   - out[j + 1] = (byte) ((input[i] >>> 8) & 0xff);
395   - out[j + 2] = (byte) ((input[i] >>> 16) & 0xff);
396   - out[j + 3] = (byte) ((input[i] >>> 24) & 0xff);
397   - }
398   - return out;
399   - }
400   -
401   - public MD5( byte[] data ) {
402   - state = new MD5State();
403   - finals = null;
404   - update( data );
405   - }
406   -
407   - /**
408   - * Updates hash with given array of bytes
409   - *
410   - * @param buffer
411   - * Array of bytes to use for updating the hash
412   - */
413   - public final void update( final byte buffer[]) {
414   - if( buffer == null )
415   - return;
416   - this.state = new MD5State();
417   - update( state, buffer,0, buffer.length );
418   - }
419   -
420   - /**
421   - * Returns array of bytes (16 bytes) representing hash as of the current
422   - * state of this object. Note: getting a hash does not invalidate the hash
423   - * object, it only creates a copy of the real state which is finalized.
424   - *
425   - * @return Array of 16 bytes, the hash of all updated bytes
426   - */
427   - public synchronized final byte[] doFinal() {
428   - byte bits[];
429   - int index, padlen;
430   - MD5State fin;
431   - if (finals == null) {
432   - fin = new MD5State(state);
433   - int[] count_ints = { (int) (fin.count << 3),(int) (fin.count >> 29) };
434   - bits = encode(count_ints, 8);
435   - index = (int) (fin.count & 0x3f);
436   - padlen = (index < 56) ? (56 - index) : (120 - index);
437   - update(fin, padding, 0, padlen);
438   - update(fin, bits, 0, 8);
439   - /* Update() sets finals to null */
440   - finals = fin;
441   - }
442   -
443   - return encode(finals.state, 16);
444   - }
445   -
446   - /**
447   - * Returns 32-character hex representation of this objects hash
448   - *
449   - * @return String of this object's hash
450   - */
451   - public static final String toHex( final byte[] hash ) {
452   - char buf[] = new char[hash.length * 2];
453   - for (int i = 0, x = 0; i < hash.length; i++) {
454   - buf[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf];
455   - buf[x++] = HEX_CHARS[hash[i] & 0xf];
456   - }
457   - return new String(buf);
458   - }
459   -
460   - public static final String toBase64( final byte[] data ) {
461   - char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray();
462   - char[] out = new char[((data.length + 2) / 3) * 4];
463   - for (int i=0, index=0; i<data.length; i+=3, index+=4) {
464   - boolean quad = false;
465   - boolean trip = false;
466   -
467   - int val = (0xFF & data[i]);
468   - val <<= 8;
469   - if ((i+1) < data.length) {
470   - val |= (0xFF & data[i+1]);
471   - trip = true;
472   - }
473   - val <<= 8;
474   - if ((i+2) < data.length) {
475   - val |= (0xFF & data[i+2]);
476   - quad = true;
477   - }
478   - out[index+3] = alphabet[(quad? (val & 0x3F): 64)];
479   - val >>= 6;
480   - out[index+2] = alphabet[(trip? (val & 0x3F): 64)];
481   - val >>= 6;
482   - out[index+1] = alphabet[val & 0x3F];
483   - val >>= 6;
484   - out[index+0] = alphabet[val & 0x3F];
485   - }
486   - return new String( out );
487   - }
488   -
489   - /**
490   - * Calculates and returns the hash of the contents of the given file.
491   - */
492   - public final byte[] fingerprint(final byte[] data) {
493   - update( data );
494   - return doFinal();
495   - }
496   -
497   - /**
498   - * @return true iff the first 16 bytes of both hash1 and hash2 are equal;
499   - * both hash1 and hash2 are null; or either hash array is less than
500   - * 16 bytes in length and their lengths and all of their bytes are
501   - * equal.
502   - */
503   - public static final boolean equals(byte[] hash1, byte[] hash2) {
504   - if (hash1 == null)
505   - return hash2 == null;
506   - if (hash2 == null)
507   - return false;
508   - int targ = 16;
509   - if (hash1.length < 16) {
510   - if (hash2.length != hash1.length)
511   - return false;
512   - targ = hash1.length;
513   - } else if (hash2.length < 16) {
514   - return false;
515   - }
516   - for (int i = 0; i < targ; i++) {
517   - if (hash1[i] != hash2[i])
518   - return false;
519   - }
520   - return true;
521   - }
522   -}
79 framework/src/com/twmacinta/util/MD5State.java
... ... @@ -1,79 +0,0 @@
1   -package com.twmacinta.util;
2   -
3   -/**
4   - * Fast implementation of RSA's MD5 hash generator in Java JDK Beta-2 or higher<br>
5   - * Originally written by Santeri Paavolainen, Helsinki Finland 1996 <br>
6   - * (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
7   - * Some changes Copyright (c) 2002 Timothy W Macinta <br>
8   - * <p>
9   - * This library is free software; you can redistribute it and/or
10   - * modify it under the terms of the GNU Library General Public
11   - * License as published by the Free Software Foundation; either
12   - * version 2.1 of the License, or (at your option) any later version.
13   - * <p>
14   - * This library is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   - * Library General Public License for more details.
18   - * <p>
19   - * You should have received a copy of the GNU Library General Public
20   - * License along with this library; if not, write to the Free
21   - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22   - * <p>
23   - * See http://www.twmacinta.com/myjava/fast_md5.php for more information
24   - * on this file.
25   - * <p>
26   - * Contains internal state of the MD5 class
27   - * <p>
28   - * Please note: I (Timothy Macinta) have put this code in the
29   - * com.twmacinta.util package only because it came without a package. I
30   - * was not the the original author of the code, although I did
31   - * optimize it (substantially) and fix some bugs.
32   - *
33   - * @author Santeri Paavolainen <sjpaavol@cc.helsinki.fi>
34   - * @author Timothy W Macinta (twm@alum.mit.edu) (optimizations and bug fixes)
35   - **/
36   -
37   -class MD5State {
38   - /**
39   - * 128-bit state
40   - */
41   - int state[];
42   -
43   - /**
44   - * 64-bit character count
45   - */
46   - long count;
47   -
48   - /**
49   - * 64-byte buffer (512 bits) for storing to-be-hashed characters
50   - */
51   - byte buffer[];
52   -
53   - public MD5State() {
54   - buffer = new byte[64];
55   - count = 0;
56   - state = new int[4];
57   -
58   - state[0] = 0x67452301;
59   - state[1] = 0xefcdab89;
60   - state[2] = 0x98badcfe;
61   - state[3] = 0x10325476;
62   -
63   - }
64   -
65   - /** Create this State as a copy of another state */
66   - public MD5State (MD5State from) {
67   - this();
68   -
69   - int i;
70   -
71   - for (i = 0; i < buffer.length; i++)
72   - this.buffer[i] = from.buffer[i];
73   -
74   - for (i = 0; i < state.length; i++)
75   - this.state[i] = from.state[i];
76   -
77   - this.count = from.count;
78   - }
79   -};

0 comments on commit a94cdb1

Please sign in to comment.
Something went wrong with that request. Please try again.