dango_generator 0.0.38
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +16 -0
- data/README.txt +41 -0
- data/dango_generator.rb +99 -0
- data/templates/as3/as3corelib-license.txt +33 -0
- data/templates/as3/as3corelib-readme.txt +5 -0
- data/templates/as3/com/adobe/crypto/MD5.as +256 -0
- data/templates/as3/com/adobe/crypto/SHA1.as +268 -0
- data/templates/as3/com/adobe/crypto/SHA224.as +255 -0
- data/templates/as3/com/adobe/crypto/SHA256.as +260 -0
- data/templates/as3/com/adobe/crypto/WSSEUsernameToken.as +117 -0
- data/templates/as3/com/adobe/errors/IllegalStateError.as +66 -0
- data/templates/as3/com/adobe/images/BitString.as +42 -0
- data/templates/as3/com/adobe/images/JPGEncoder.as +651 -0
- data/templates/as3/com/adobe/images/PNGEncoder.as +144 -0
- data/templates/as3/com/adobe/net/DynamicURLLoader.as +58 -0
- data/templates/as3/com/adobe/net/IURIResolver.as +79 -0
- data/templates/as3/com/adobe/net/URI.as +2469 -0
- data/templates/as3/com/adobe/net/URIEncodingBitmap.as +142 -0
- data/templates/as3/com/adobe/net/proxies/RFC2817Socket.as +204 -0
- data/templates/as3/com/adobe/serialization/json/JSON.as +88 -0
- data/templates/as3/com/adobe/serialization/json/JSONDecoder.as +218 -0
- data/templates/as3/com/adobe/serialization/json/JSONEncoder.as +302 -0
- data/templates/as3/com/adobe/serialization/json/JSONParseError.as +90 -0
- data/templates/as3/com/adobe/serialization/json/JSONToken.as +107 -0
- data/templates/as3/com/adobe/serialization/json/JSONTokenType.as +70 -0
- data/templates/as3/com/adobe/serialization/json/JSONTokenizer.as +550 -0
- data/templates/as3/com/adobe/utils/ArrayUtil.as +190 -0
- data/templates/as3/com/adobe/utils/DateUtil.as +666 -0
- data/templates/as3/com/adobe/utils/DictionaryUtil.as +90 -0
- data/templates/as3/com/adobe/utils/IntUtil.as +69 -0
- data/templates/as3/com/adobe/utils/NumberFormatter.as +77 -0
- data/templates/as3/com/adobe/utils/StringUtil.as +257 -0
- data/templates/as3/com/adobe/utils/XMLUtil.as +171 -0
- data/templates/as3/com/adobe/webapis/ServiceBase.as +51 -0
- data/templates/as3/com/adobe/webapis/URLLoaderBase.as +111 -0
- data/templates/as3/com/adobe/webapis/events/ServiceEvent.as +78 -0
- data/templates/as3/org/rubyforge/dango/DangoClientFramework.as +426 -0
- data/templates/as3/org/rubyforge/dango/DangoError.as +11 -0
- data/templates/as3/org/rubyforge/dango/DangoErrorCode.as +7 -0
- data/templates/as3/org/rubyforge/dango/DangoErrorEvent.as +23 -0
- data/templates/as3/org/rubyforge/dango/DangoReceiveEvent.as +21 -0
- data/templates/as3/org/rubyforge/dango/DangoURLLoader.as +127 -0
- data/templates/as3/org/rubyforge/dango/DangoURLLoaderEvent.as +29 -0
- data/templates/as3/org/rubyforge/dango/DangoUtil.as +84 -0
- data/templates/dango/config/development.yml +28 -0
- data/templates/dango/config/production.yml +3 -0
- data/templates/dango/config/system_message.yml +5 -0
- data/templates/dango/config/test.yml +3 -0
- data/templates/dango/server/99_dango_server.rb +22 -0
- data/templates/lib/dango_monitor_client.rb +1 -0
- data/templates/lib/dango_tester_client.rb +1 -0
- data/templates/script/dango_server +36 -0
- data/templates/tasks/dango.rake +2 -0
- metadata +108 -0
@@ -0,0 +1,268 @@
|
|
1
|
+
/*
|
2
|
+
Adobe Systems Incorporated(r) Source Code License Agreement
|
3
|
+
Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
4
|
+
|
5
|
+
Please read this Source Code License Agreement carefully before using
|
6
|
+
the source code.
|
7
|
+
|
8
|
+
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
9
|
+
no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
10
|
+
prepare derivative works of, publicly display, publicly perform, and
|
11
|
+
distribute this source code and such derivative works in source or
|
12
|
+
object code form without any attribution requirements.
|
13
|
+
|
14
|
+
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
15
|
+
derived from the source code without prior written permission.
|
16
|
+
|
17
|
+
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
18
|
+
against any loss, damage, claims or lawsuits, including attorney's
|
19
|
+
fees that arise or result from your use or distribution of the source
|
20
|
+
code.
|
21
|
+
|
22
|
+
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
23
|
+
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
24
|
+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
25
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
26
|
+
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
27
|
+
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
28
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
29
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
30
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
33
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
package com.adobe.crypto
|
37
|
+
{
|
38
|
+
import com.adobe.utils.IntUtil;
|
39
|
+
import flash.utils.ByteArray;
|
40
|
+
import mx.utils.Base64Encoder;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* US Secure Hash Algorithm 1 (SHA1)
|
44
|
+
*
|
45
|
+
* Implementation based on algorithm description at
|
46
|
+
* http://www.faqs.org/rfcs/rfc3174.html
|
47
|
+
*/
|
48
|
+
public class SHA1
|
49
|
+
{
|
50
|
+
/**
|
51
|
+
* Performs the SHA1 hash algorithm on a string.
|
52
|
+
*
|
53
|
+
* @param s The string to hash
|
54
|
+
* @return A string containing the hash value of s
|
55
|
+
* @langversion ActionScript 3.0
|
56
|
+
* @playerversion 9.0
|
57
|
+
* @tiptext
|
58
|
+
*/
|
59
|
+
public static function hash( s:String ):String
|
60
|
+
{
|
61
|
+
var blocks:Array = createBlocksFromString( s );
|
62
|
+
var byteArray:ByteArray = hashBlocks( blocks );
|
63
|
+
|
64
|
+
return IntUtil.toHex( byteArray.readInt(), true )
|
65
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
66
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
67
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
68
|
+
+ IntUtil.toHex( byteArray.readInt(), true );
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Performs the SHA1 hash algorithm on a ByteArray.
|
73
|
+
*
|
74
|
+
* @param data The ByteArray data to hash
|
75
|
+
* @return A string containing the hash value of data
|
76
|
+
* @langversion ActionScript 3.0
|
77
|
+
* @playerversion 9.0
|
78
|
+
*/
|
79
|
+
public static function hashBytes( data:ByteArray ):String
|
80
|
+
{
|
81
|
+
var blocks:Array = SHA1.createBlocksFromByteArray( data );
|
82
|
+
var byteArray:ByteArray = hashBlocks(blocks);
|
83
|
+
|
84
|
+
return IntUtil.toHex( byteArray.readInt(), true )
|
85
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
86
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
87
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
88
|
+
+ IntUtil.toHex( byteArray.readInt(), true );
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Performs the SHA1 hash algorithm on a string, then does
|
93
|
+
* Base64 encoding on the result.
|
94
|
+
*
|
95
|
+
* @param s The string to hash
|
96
|
+
* @return The base64 encoded hash value of s
|
97
|
+
* @langversion ActionScript 3.0
|
98
|
+
* @playerversion 9.0
|
99
|
+
* @tiptext
|
100
|
+
*/
|
101
|
+
public static function hashToBase64( s:String ):String
|
102
|
+
{
|
103
|
+
var blocks:Array = SHA1.createBlocksFromString( s );
|
104
|
+
var byteArray:ByteArray = hashBlocks(blocks);
|
105
|
+
|
106
|
+
// ByteArray.toString() returns the contents as a UTF-8 string,
|
107
|
+
// which we can't use because certain byte sequences might trigger
|
108
|
+
// a UTF-8 conversion. Instead, we convert the bytes to characters
|
109
|
+
// one by one.
|
110
|
+
var charsInByteArray:String = "";
|
111
|
+
byteArray.position = 0;
|
112
|
+
for (var j:int = 0; j < byteArray.length; j++)
|
113
|
+
{
|
114
|
+
var byte:uint = byteArray.readUnsignedByte();
|
115
|
+
charsInByteArray += String.fromCharCode(byte);
|
116
|
+
}
|
117
|
+
|
118
|
+
var encoder:Base64Encoder = new Base64Encoder();
|
119
|
+
encoder.encode(charsInByteArray);
|
120
|
+
return encoder.flush();
|
121
|
+
}
|
122
|
+
|
123
|
+
private static function hashBlocks( blocks:Array ):ByteArray
|
124
|
+
{
|
125
|
+
// initialize the h's
|
126
|
+
var h0:int = 0x67452301;
|
127
|
+
var h1:int = 0xefcdab89;
|
128
|
+
var h2:int = 0x98badcfe;
|
129
|
+
var h3:int = 0x10325476;
|
130
|
+
var h4:int = 0xc3d2e1f0;
|
131
|
+
|
132
|
+
var len:int = blocks.length;
|
133
|
+
var w:Array = new Array( 80 );
|
134
|
+
|
135
|
+
// loop over all of the blocks
|
136
|
+
for ( var i:int = 0; i < len; i += 16 ) {
|
137
|
+
|
138
|
+
// 6.1.c
|
139
|
+
var a:int = h0;
|
140
|
+
var b:int = h1;
|
141
|
+
var c:int = h2;
|
142
|
+
var d:int = h3;
|
143
|
+
var e:int = h4;
|
144
|
+
|
145
|
+
// 80 steps to process each block
|
146
|
+
// TODO: unroll for faster execution, or 4 loops of
|
147
|
+
// 20 each to avoid the k and f function calls
|
148
|
+
for ( var t:int = 0; t < 80; t++ ) {
|
149
|
+
|
150
|
+
if ( t < 16 ) {
|
151
|
+
// 6.1.a
|
152
|
+
w[ t ] = blocks[ i + t ];
|
153
|
+
} else {
|
154
|
+
// 6.1.b
|
155
|
+
w[ t ] = IntUtil.rol( w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ], 1 );
|
156
|
+
}
|
157
|
+
|
158
|
+
// 6.1.d
|
159
|
+
var temp:int = IntUtil.rol( a, 5 ) + f( t, b, c, d ) + e + int( w[ t ] ) + k( t );
|
160
|
+
|
161
|
+
e = d;
|
162
|
+
d = c;
|
163
|
+
c = IntUtil.rol( b, 30 );
|
164
|
+
b = a;
|
165
|
+
a = temp;
|
166
|
+
}
|
167
|
+
|
168
|
+
// 6.1.e
|
169
|
+
h0 += a;
|
170
|
+
h1 += b;
|
171
|
+
h2 += c;
|
172
|
+
h3 += d;
|
173
|
+
h4 += e;
|
174
|
+
}
|
175
|
+
|
176
|
+
var byteArray:ByteArray = new ByteArray();
|
177
|
+
byteArray.writeInt(h0);
|
178
|
+
byteArray.writeInt(h1);
|
179
|
+
byteArray.writeInt(h2);
|
180
|
+
byteArray.writeInt(h3);
|
181
|
+
byteArray.writeInt(h4);
|
182
|
+
byteArray.position = 0;
|
183
|
+
return byteArray;
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Performs the logical function based on t
|
188
|
+
*/
|
189
|
+
private static function f( t:int, b:int, c:int, d:int ):int {
|
190
|
+
if ( t < 20 ) {
|
191
|
+
return ( b & c ) | ( ~b & d );
|
192
|
+
} else if ( t < 40 ) {
|
193
|
+
return b ^ c ^ d;
|
194
|
+
} else if ( t < 60 ) {
|
195
|
+
return ( b & c ) | ( b & d ) | ( c & d );
|
196
|
+
}
|
197
|
+
return b ^ c ^ d;
|
198
|
+
}
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Determines the constant value based on t
|
202
|
+
*/
|
203
|
+
private static function k( t:int ):int {
|
204
|
+
if ( t < 20 ) {
|
205
|
+
return 0x5a827999;
|
206
|
+
} else if ( t < 40 ) {
|
207
|
+
return 0x6ed9eba1;
|
208
|
+
} else if ( t < 60 ) {
|
209
|
+
return 0x8f1bbcdc;
|
210
|
+
}
|
211
|
+
return 0xca62c1d6;
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Converts a ByteArray to a sequence of 16-word blocks
|
216
|
+
* that we'll do the processing on. Appends padding
|
217
|
+
* and length in the process.
|
218
|
+
*
|
219
|
+
* @param data The data to split into blocks
|
220
|
+
* @return An array containing the blocks into which data was split
|
221
|
+
*/
|
222
|
+
private static function createBlocksFromByteArray( data:ByteArray ):Array
|
223
|
+
{
|
224
|
+
var oldPosition:int = data.position;
|
225
|
+
data.position = 0;
|
226
|
+
|
227
|
+
var blocks:Array = new Array();
|
228
|
+
var len:int = data.length * 8;
|
229
|
+
var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
|
230
|
+
for( var i:int = 0; i < len; i += 8 )
|
231
|
+
{
|
232
|
+
blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
|
233
|
+
}
|
234
|
+
|
235
|
+
// append padding and length
|
236
|
+
blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
|
237
|
+
blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
|
238
|
+
|
239
|
+
data.position = oldPosition;
|
240
|
+
|
241
|
+
return blocks;
|
242
|
+
}
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Converts a string to a sequence of 16-word blocks
|
246
|
+
* that we'll do the processing on. Appends padding
|
247
|
+
* and length in the process.
|
248
|
+
*
|
249
|
+
* @param s The string to split into blocks
|
250
|
+
* @return An array containing the blocks that s was split into.
|
251
|
+
*/
|
252
|
+
private static function createBlocksFromString( s:String ):Array
|
253
|
+
{
|
254
|
+
var blocks:Array = new Array();
|
255
|
+
var len:int = s.length * 8;
|
256
|
+
var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
|
257
|
+
for( var i:int = 0; i < len; i += 8 ) {
|
258
|
+
blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
|
259
|
+
}
|
260
|
+
|
261
|
+
// append padding and length
|
262
|
+
blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
|
263
|
+
blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
|
264
|
+
return blocks;
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
}
|
@@ -0,0 +1,255 @@
|
|
1
|
+
/*
|
2
|
+
Adobe Systems Incorporated(r) Source Code License Agreement
|
3
|
+
Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
4
|
+
|
5
|
+
Please read this Source Code License Agreement carefully before using
|
6
|
+
the source code.
|
7
|
+
|
8
|
+
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
9
|
+
no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
10
|
+
prepare derivative works of, publicly display, publicly perform, and
|
11
|
+
distribute this source code and such derivative works in source or
|
12
|
+
object code form without any attribution requirements.
|
13
|
+
|
14
|
+
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
15
|
+
derived from the source code without prior written permission.
|
16
|
+
|
17
|
+
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
18
|
+
against any loss, damage, claims or lawsuits, including attorney's
|
19
|
+
fees that arise or result from your use or distribution of the source
|
20
|
+
code.
|
21
|
+
|
22
|
+
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
23
|
+
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
24
|
+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
25
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
26
|
+
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
27
|
+
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
28
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
29
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
30
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
33
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
package com.adobe.crypto
|
37
|
+
{
|
38
|
+
import com.adobe.utils.IntUtil;
|
39
|
+
import flash.utils.ByteArray;
|
40
|
+
import mx.utils.Base64Encoder;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* The SHA-224 algorithm
|
44
|
+
*
|
45
|
+
* @see http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
|
46
|
+
*/
|
47
|
+
public class SHA224
|
48
|
+
{
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Performs the SHA224 hash algorithm on a string.
|
52
|
+
*
|
53
|
+
* @param s The string to hash
|
54
|
+
* @return A string containing the hash value of s
|
55
|
+
* @langversion ActionScript 3.0
|
56
|
+
* @playerversion 9.0
|
57
|
+
* @tiptext
|
58
|
+
*/
|
59
|
+
public static function hash( s:String ):String {
|
60
|
+
var blocks:Array = createBlocksFromString( s );
|
61
|
+
var byteArray:ByteArray = hashBlocks( blocks );
|
62
|
+
return IntUtil.toHex( byteArray.readInt(), true )
|
63
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
64
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
65
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
66
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
67
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
68
|
+
+ IntUtil.toHex( byteArray.readInt(), true );
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Performs the SHA224 hash algorithm on a ByteArray.
|
73
|
+
*
|
74
|
+
* @param data The ByteArray data to hash
|
75
|
+
* @return A string containing the hash value of data
|
76
|
+
* @langversion ActionScript 3.0
|
77
|
+
* @playerversion 9.0
|
78
|
+
*/
|
79
|
+
public static function hashBytes( data:ByteArray ):String
|
80
|
+
{
|
81
|
+
var blocks:Array = createBlocksFromByteArray( data );
|
82
|
+
var byteArray:ByteArray = hashBlocks(blocks);
|
83
|
+
return IntUtil.toHex( byteArray.readInt(), true )
|
84
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
85
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
86
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
87
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
88
|
+
+ IntUtil.toHex( byteArray.readInt(), true )
|
89
|
+
+ IntUtil.toHex( byteArray.readInt(), true );
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Performs the SHA224 hash algorithm on a string, then does
|
94
|
+
* Base64 encoding on the result.
|
95
|
+
*
|
96
|
+
* @param s The string to hash
|
97
|
+
* @return The base64 encoded hash value of s
|
98
|
+
* @langversion ActionScript 3.0
|
99
|
+
* @playerversion 9.0
|
100
|
+
* @tiptext
|
101
|
+
*/
|
102
|
+
public static function hashToBase64( s:String ):String
|
103
|
+
{
|
104
|
+
var blocks:Array = createBlocksFromString( s );
|
105
|
+
var byteArray:ByteArray = hashBlocks(blocks);
|
106
|
+
|
107
|
+
// ByteArray.toString() returns the contents as a UTF-8 string,
|
108
|
+
// which we can't use because certain byte sequences might trigger
|
109
|
+
// a UTF-8 conversion. Instead, we convert the bytes to characters
|
110
|
+
// one by one.
|
111
|
+
var charsInByteArray:String = "";
|
112
|
+
byteArray.position = 0;
|
113
|
+
for (var j:int = 0; j < byteArray.length; j++)
|
114
|
+
{
|
115
|
+
var byte:uint = byteArray.readUnsignedByte();
|
116
|
+
charsInByteArray += String.fromCharCode(byte);
|
117
|
+
}
|
118
|
+
|
119
|
+
var encoder:Base64Encoder = new Base64Encoder();
|
120
|
+
encoder.encode(charsInByteArray);
|
121
|
+
return encoder.flush();
|
122
|
+
}
|
123
|
+
|
124
|
+
private static function hashBlocks( blocks:Array ):ByteArray {
|
125
|
+
var h0:int = 0xc1059ed8;
|
126
|
+
var h1:int = 0x367cd507;
|
127
|
+
var h2:int = 0x3070dd17;
|
128
|
+
var h3:int = 0xf70e5939;
|
129
|
+
var h4:int = 0xffc00b31;
|
130
|
+
var h5:int = 0x68581511;
|
131
|
+
var h6:int = 0x64f98fa7;
|
132
|
+
var h7:int = 0xbefa4fa4;
|
133
|
+
|
134
|
+
var k:Array = new Array(0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2);
|
135
|
+
|
136
|
+
var len:int = blocks.length;
|
137
|
+
var w:Array = new Array();
|
138
|
+
|
139
|
+
// loop over all of the blocks
|
140
|
+
for ( var i:int = 0; i < len; i += 16 ) {
|
141
|
+
|
142
|
+
var a:int = h0;
|
143
|
+
var b:int = h1;
|
144
|
+
var c:int = h2;
|
145
|
+
var d:int = h3;
|
146
|
+
var e:int = h4;
|
147
|
+
var f:int = h5;
|
148
|
+
var g:int = h6;
|
149
|
+
var h:int = h7;
|
150
|
+
|
151
|
+
for(var t:int = 0; t < 64; t++) {
|
152
|
+
|
153
|
+
if ( t < 16 ) {
|
154
|
+
w[t] = blocks[ i + t ];
|
155
|
+
if(isNaN(w[t])) { w[t] = 0; }
|
156
|
+
} else {
|
157
|
+
var ws0:int = IntUtil.ror(w[t-15], 7) ^ IntUtil.ror(w[t-15], 18) ^ (w[t-15] >>> 3);
|
158
|
+
var ws1:int = IntUtil.ror(w[t-2], 17) ^ IntUtil.ror(w[t-2], 19) ^ (w[t-2] >>> 10);
|
159
|
+
w[t] = w[t-16] + ws0 + w[t-7] + ws1;
|
160
|
+
}
|
161
|
+
|
162
|
+
var s0:int = IntUtil.ror(a, 2) ^ IntUtil.ror(a, 13) ^ IntUtil.ror(a, 22);
|
163
|
+
var maj:int = (a & b) ^ (a & c) ^ (b & c);
|
164
|
+
var t2:int = s0 + maj;
|
165
|
+
var s1:int = IntUtil.ror(e, 6) ^ IntUtil.ror(e, 11) ^ IntUtil.ror(e, 25);
|
166
|
+
var ch:int = (e & f) ^ ((~e) & g);
|
167
|
+
var t1:int = h + s1 + ch + k[t] + w[t];
|
168
|
+
|
169
|
+
h = g;
|
170
|
+
g = f;
|
171
|
+
f = e;
|
172
|
+
e = d + t1;
|
173
|
+
d = c;
|
174
|
+
c = b;
|
175
|
+
b = a;
|
176
|
+
a = t1 + t2;
|
177
|
+
}
|
178
|
+
|
179
|
+
//Add this chunk's hash to result so far:
|
180
|
+
h0 += a;
|
181
|
+
h1 += b;
|
182
|
+
h2 += c;
|
183
|
+
h3 += d;
|
184
|
+
h4 += e;
|
185
|
+
h5 += f;
|
186
|
+
h6 += g;
|
187
|
+
h7 += h;
|
188
|
+
}
|
189
|
+
|
190
|
+
var byteArray:ByteArray = new ByteArray();
|
191
|
+
byteArray.writeInt(h0);
|
192
|
+
byteArray.writeInt(h1);
|
193
|
+
byteArray.writeInt(h2);
|
194
|
+
byteArray.writeInt(h3);
|
195
|
+
byteArray.writeInt(h4);
|
196
|
+
byteArray.writeInt(h5);
|
197
|
+
byteArray.writeInt(h6);
|
198
|
+
byteArray.position = 0;
|
199
|
+
return byteArray;
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Converts a ByteArray to a sequence of 16-word blocks
|
204
|
+
* that we'll do the processing on. Appends padding
|
205
|
+
* and length in the process.
|
206
|
+
*
|
207
|
+
* @param data The data to split into blocks
|
208
|
+
* @return An array containing the blocks into which data was split
|
209
|
+
*/
|
210
|
+
private static function createBlocksFromByteArray( data:ByteArray ):Array
|
211
|
+
{
|
212
|
+
var oldPosition:int = data.position;
|
213
|
+
data.position = 0;
|
214
|
+
|
215
|
+
var blocks:Array = new Array();
|
216
|
+
var len:int = data.length * 8;
|
217
|
+
var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
|
218
|
+
for( var i:int = 0; i < len; i += 8 )
|
219
|
+
{
|
220
|
+
blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
|
221
|
+
}
|
222
|
+
|
223
|
+
// append padding and length
|
224
|
+
blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
|
225
|
+
blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
|
226
|
+
|
227
|
+
data.position = oldPosition;
|
228
|
+
|
229
|
+
return blocks;
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Converts a string to a sequence of 16-word blocks
|
234
|
+
* that we'll do the processing on. Appends padding
|
235
|
+
* and length in the process.
|
236
|
+
*
|
237
|
+
* @param s The string to split into blocks
|
238
|
+
* @return An array containing the blocks that s was split into.
|
239
|
+
*/
|
240
|
+
private static function createBlocksFromString( s:String ):Array
|
241
|
+
{
|
242
|
+
var blocks:Array = new Array();
|
243
|
+
var len:int = s.length * 8;
|
244
|
+
var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
|
245
|
+
for( var i:int = 0; i < len; i += 8 ) {
|
246
|
+
blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
|
247
|
+
}
|
248
|
+
|
249
|
+
// append padding and length
|
250
|
+
blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
|
251
|
+
blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
|
252
|
+
return blocks;
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|