as3corelib 0.1.0 → 0.85.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/Gemfile +1 -4
  2. data/Gemfile.lock +7 -4
  3. data/README.textile +20 -10
  4. data/Rakefile +32 -2
  5. data/as3corelib.gemspec +13 -11
  6. data/lib/as3corelib.rb +10 -4
  7. data/lib/as3corelib/version.rb +4 -0
  8. metadata +31 -121
  9. data/build/build.properties +0 -48
  10. data/build/build.xml +0 -104
  11. data/examples/JSONExample/JSONExample.mxml +0 -73
  12. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +0 -313
  13. data/src/com/adobe/air/filesystem/FileMonitor.as +0 -245
  14. data/src/com/adobe/air/filesystem/FileUtil.as +0 -63
  15. data/src/com/adobe/air/filesystem/VolumeMonitor.as +0 -184
  16. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +0 -61
  17. data/src/com/adobe/air/logging/FileTarget.as +0 -95
  18. data/src/com/adobe/air/net/ResourceCache.as +0 -165
  19. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +0 -70
  20. data/src/com/adobe/crypto/HMAC.as +0 -127
  21. data/src/com/adobe/crypto/MD5.as +0 -281
  22. data/src/com/adobe/crypto/MD5Stream.as +0 -402
  23. data/src/com/adobe/crypto/SHA1.as +0 -289
  24. data/src/com/adobe/crypto/SHA224.as +0 -257
  25. data/src/com/adobe/crypto/SHA256.as +0 -261
  26. data/src/com/adobe/crypto/WSSEUsernameToken.as +0 -114
  27. data/src/com/adobe/errors/IllegalStateError.as +0 -63
  28. data/src/com/adobe/fileformats/vcard/Address.as +0 -47
  29. data/src/com/adobe/fileformats/vcard/Email.as +0 -39
  30. data/src/com/adobe/fileformats/vcard/Phone.as +0 -39
  31. data/src/com/adobe/fileformats/vcard/VCard.as +0 -54
  32. data/src/com/adobe/fileformats/vcard/VCardParser.as +0 -246
  33. data/src/com/adobe/images/BitString.as +0 -39
  34. data/src/com/adobe/images/JPGEncoder.as +0 -648
  35. data/src/com/adobe/images/PNGEncoder.as +0 -141
  36. data/src/com/adobe/net/DynamicURLLoader.as +0 -55
  37. data/src/com/adobe/net/IURIResolver.as +0 -76
  38. data/src/com/adobe/net/MimeTypeMap.as +0 -200
  39. data/src/com/adobe/net/URI.as +0 -2466
  40. data/src/com/adobe/net/URIEncodingBitmap.as +0 -139
  41. data/src/com/adobe/net/proxies/RFC2817Socket.as +0 -198
  42. data/src/com/adobe/protocols/dict/Database.as +0 -66
  43. data/src/com/adobe/protocols/dict/Definition.as +0 -71
  44. data/src/com/adobe/protocols/dict/Dict.as +0 -360
  45. data/src/com/adobe/protocols/dict/DictionaryServer.as +0 -60
  46. data/src/com/adobe/protocols/dict/MatchStrategy.as +0 -66
  47. data/src/com/adobe/protocols/dict/Response.as +0 -71
  48. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +0 -53
  49. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +0 -67
  50. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +0 -70
  51. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +0 -69
  52. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +0 -69
  53. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +0 -55
  54. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +0 -80
  55. data/src/com/adobe/protocols/dict/events/MatchEvent.as +0 -67
  56. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +0 -70
  57. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +0 -54
  58. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +0 -68
  59. data/src/com/adobe/protocols/dict/util/SocketHelper.as +0 -81
  60. data/src/com/adobe/serialization/json/JSON.as +0 -86
  61. data/src/com/adobe/serialization/json/JSONDecoder.as +0 -327
  62. data/src/com/adobe/serialization/json/JSONEncoder.as +0 -312
  63. data/src/com/adobe/serialization/json/JSONParseError.as +0 -87
  64. data/src/com/adobe/serialization/json/JSONToken.as +0 -104
  65. data/src/com/adobe/serialization/json/JSONTokenType.as +0 -69
  66. data/src/com/adobe/serialization/json/JSONTokenizer.as +0 -702
  67. data/src/com/adobe/utils/ArrayUtil.as +0 -187
  68. data/src/com/adobe/utils/DateUtil.as +0 -701
  69. data/src/com/adobe/utils/DictionaryUtil.as +0 -87
  70. data/src/com/adobe/utils/IntUtil.as +0 -99
  71. data/src/com/adobe/utils/NumberFormatter.as +0 -74
  72. data/src/com/adobe/utils/StringUtil.as +0 -239
  73. data/src/com/adobe/utils/XMLUtil.as +0 -168
  74. data/src/com/adobe/webapis/ServiceBase.as +0 -48
  75. data/src/com/adobe/webapis/URLLoaderBase.as +0 -108
  76. data/src/com/adobe/webapis/events/ServiceEvent.as +0 -82
  77. data/tests/src/CoreLibTestRunner-app.xml +0 -135
  78. data/tests/src/CoreLibTestRunner.as +0 -138
  79. data/tests/src/CoreLibTestRunner.mxml +0 -46
  80. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +0 -176
  81. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +0 -63
  82. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +0 -57
  83. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +0 -59
  84. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +0 -72
  85. data/tests/src/com/adobe/crypto/HMACMD5Test.as +0 -134
  86. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +0 -138
  87. data/tests/src/com/adobe/crypto/MD5Test.as +0 -82
  88. data/tests/src/com/adobe/crypto/SHA1Test.as +0 -151
  89. data/tests/src/com/adobe/crypto/SHA224Test.as +0 -104
  90. data/tests/src/com/adobe/crypto/SHA256Test.as +0 -116
  91. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +0 -87
  92. data/tests/src/com/adobe/images/JPGEncoderTest.as +0 -54
  93. data/tests/src/com/adobe/images/PNGEncoderTest.as +0 -54
  94. data/tests/src/com/adobe/net/URITest.as +0 -589
  95. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +0 -59
  96. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +0 -62
  97. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +0 -61
  98. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +0 -61
  99. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +0 -61
  100. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +0 -59
  101. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +0 -63
  102. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +0 -61
  103. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +0 -61
  104. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +0 -58
  105. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +0 -60
  106. data/tests/src/com/adobe/serialization/json/JSONTest.as +0 -522
  107. data/tests/src/com/adobe/serialization/json/SimpleClass.as +0 -85
  108. data/tests/src/com/adobe/utils/ArrayUtilTest.as +0 -173
  109. data/tests/src/com/adobe/utils/DateUtilTest.as +0 -436
  110. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +0 -93
  111. data/tests/src/com/adobe/utils/IntUtilTest.as +0 -73
  112. data/tests/src/com/adobe/utils/NumberFormatterTest.as +0 -70
  113. data/tests/src/com/adobe/utils/StringUtilTest.as +0 -304
  114. data/tests/src/com/adobe/utils/XMLUtilTest.as +0 -101
  115. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +0 -66
@@ -1,289 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.crypto
34
- {
35
- import com.adobe.utils.IntUtil;
36
- import flash.utils.ByteArray;
37
- import mx.utils.Base64Encoder;
38
-
39
- /**
40
- * US Secure Hash Algorithm 1 (SHA1)
41
- *
42
- * Implementation based on algorithm description at
43
- * http://www.faqs.org/rfcs/rfc3174.html
44
- */
45
- public class SHA1
46
- {
47
- public static var digest:ByteArray;
48
-
49
- /**
50
- * Performs the SHA1 hash algorithm on a string.
51
- *
52
- * @param s The string to hash
53
- * @return A string containing the hash value of s
54
- * @langversion ActionScript 3.0
55
- * @playerversion 9.0
56
- * @tiptext
57
- */
58
- public static function hash( s:String ):String
59
- {
60
- var blocks:Array = createBlocksFromString( s );
61
- var byteArray:ByteArray = hashBlocks( blocks );
62
-
63
- return 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
- }
69
-
70
- /**
71
- * Performs the SHA1 hash algorithm on a ByteArray.
72
- *
73
- * @param data The ByteArray data to hash
74
- * @return A string containing the hash value of data
75
- * @langversion ActionScript 3.0
76
- * @playerversion 9.0
77
- */
78
- public static function hashBytes( data:ByteArray ):String
79
- {
80
- var blocks:Array = SHA1.createBlocksFromByteArray( data );
81
- var byteArray:ByteArray = hashBlocks(blocks);
82
-
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
- }
89
-
90
- /**
91
- * Performs the SHA1 hash algorithm on a string, then does
92
- * Base64 encoding on the result.
93
- *
94
- * @param s The string to hash
95
- * @return The base64 encoded hash value of s
96
- * @langversion ActionScript 3.0
97
- * @playerversion 9.0
98
- * @tiptext
99
- */
100
- public static function hashToBase64( s:String ):String
101
- {
102
- var blocks:Array = SHA1.createBlocksFromString( s );
103
- var byteArray:ByteArray = hashBlocks(blocks);
104
-
105
- // ByteArray.toString() returns the contents as a UTF-8 string,
106
- // which we can't use because certain byte sequences might trigger
107
- // a UTF-8 conversion. Instead, we convert the bytes to characters
108
- // one by one.
109
- var charsInByteArray:String = "";
110
- byteArray.position = 0;
111
- for (var j:int = 0; j < byteArray.length; j++)
112
- {
113
- var byte:uint = byteArray.readUnsignedByte();
114
- charsInByteArray += String.fromCharCode(byte);
115
- }
116
-
117
- var encoder:Base64Encoder = new Base64Encoder();
118
- encoder.encode(charsInByteArray);
119
- return encoder.flush();
120
- }
121
-
122
- private static function hashBlocks( blocks:Array ):ByteArray
123
- {
124
- // initialize the h's
125
- var h0:int = 0x67452301;
126
- var h1:int = 0xefcdab89;
127
- var h2:int = 0x98badcfe;
128
- var h3:int = 0x10325476;
129
- var h4:int = 0xc3d2e1f0;
130
-
131
- var len:int = blocks.length;
132
- var w:Array = new Array( 80 );
133
- var temp:int;
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
- var t:int;
147
- for ( t = 0; t < 20; t++ ) {
148
-
149
- if ( t < 16 ) {
150
- // 6.1.a
151
- w[ t ] = blocks[ i + t ];
152
- } else {
153
- // 6.1.b
154
- temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
155
- w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
156
- }
157
-
158
- // 6.1.d
159
- temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( ( b & c ) | ( ~b & d ) ) + e + int( w[ t ] ) + 0x5a827999;
160
-
161
- e = d;
162
- d = c;
163
- c = ( b << 30 ) | ( b >>> 2 );
164
- b = a;
165
- a = temp;
166
- }
167
- for ( ; t < 40; t++ )
168
- {
169
- // 6.1.b
170
- temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
171
- w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
172
-
173
- // 6.1.d
174
- temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( b ^ c ^ d ) + e + int( w[ t ] ) + 0x6ed9eba1;
175
-
176
- e = d;
177
- d = c;
178
- c = ( b << 30 ) | ( b >>> 2 );
179
- b = a;
180
- a = temp;
181
- }
182
- for ( ; t < 60; t++ )
183
- {
184
- // 6.1.b
185
- temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
186
- w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
187
-
188
- // 6.1.d
189
- temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( ( b & c ) | ( b & d ) | ( c & d ) ) + e + int( w[ t ] ) + 0x8f1bbcdc;
190
-
191
- e = d;
192
- d = c;
193
- c = ( b << 30 ) | ( b >>> 2 );
194
- b = a;
195
- a = temp;
196
- }
197
- for ( ; t < 80; t++ )
198
- {
199
- // 6.1.b
200
- temp = w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ];
201
- w[ t ] = ( temp << 1 ) | ( temp >>> 31 )
202
-
203
- // 6.1.d
204
- temp = ( ( a << 5 ) | ( a >>> 27 ) ) + ( b ^ c ^ d ) + e + int( w[ t ] ) + 0xca62c1d6;
205
-
206
- e = d;
207
- d = c;
208
- c = ( b << 30 ) | ( b >>> 2 );
209
- b = a;
210
- a = temp;
211
- }
212
-
213
- // 6.1.e
214
- h0 += a;
215
- h1 += b;
216
- h2 += c;
217
- h3 += d;
218
- h4 += e;
219
- }
220
-
221
- var byteArray:ByteArray = new ByteArray();
222
- byteArray.writeInt(h0);
223
- byteArray.writeInt(h1);
224
- byteArray.writeInt(h2);
225
- byteArray.writeInt(h3);
226
- byteArray.writeInt(h4);
227
- byteArray.position = 0;
228
-
229
- digest = new ByteArray();
230
- digest.writeBytes(byteArray);
231
- digest.position = 0;
232
- return byteArray;
233
- }
234
-
235
- /**
236
- * Converts a ByteArray to a sequence of 16-word blocks
237
- * that we'll do the processing on. Appends padding
238
- * and length in the process.
239
- *
240
- * @param data The data to split into blocks
241
- * @return An array containing the blocks into which data was split
242
- */
243
- private static function createBlocksFromByteArray( data:ByteArray ):Array
244
- {
245
- var oldPosition:int = data.position;
246
- data.position = 0;
247
-
248
- var blocks:Array = new Array();
249
- var len:int = data.length * 8;
250
- var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
251
- for( var i:int = 0; i < len; i += 8 )
252
- {
253
- blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
254
- }
255
-
256
- // append padding and length
257
- blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
258
- blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
259
-
260
- data.position = oldPosition;
261
-
262
- return blocks;
263
- }
264
-
265
- /**
266
- * Converts a string to a sequence of 16-word blocks
267
- * that we'll do the processing on. Appends padding
268
- * and length in the process.
269
- *
270
- * @param s The string to split into blocks
271
- * @return An array containing the blocks that s was split into.
272
- */
273
- private static function createBlocksFromString( s:String ):Array
274
- {
275
- var blocks:Array = new Array();
276
- var len:int = s.length * 8;
277
- var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
278
- for( var i:int = 0; i < len; i += 8 ) {
279
- blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
280
- }
281
-
282
- // append padding and length
283
- blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
284
- blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
285
- return blocks;
286
- }
287
-
288
- }
289
- }
@@ -1,257 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
-
33
- package com.adobe.crypto
34
- {
35
- import com.adobe.utils.IntUtil;
36
- import flash.utils.ByteArray;
37
- import mx.utils.Base64Encoder;
38
-
39
- /**
40
- * The SHA-224 algorithm
41
- *
42
- * @see http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
43
- */
44
- public class SHA224
45
- {
46
- public static var digest:ByteArray;
47
-
48
- /**
49
- * Performs the SHA224 hash algorithm on a string.
50
- *
51
- * @param s The string to hash
52
- * @return A string containing the hash value of s
53
- * @langversion ActionScript 3.0
54
- * @playerversion 9.0
55
- * @tiptext
56
- */
57
- public static function hash( s:String ):String {
58
- var blocks:Array = createBlocksFromString( s );
59
- var byteArray:ByteArray = hashBlocks( blocks );
60
- return IntUtil.toHex( byteArray.readInt(), true )
61
- + IntUtil.toHex( byteArray.readInt(), true )
62
- + 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
- }
68
-
69
- /**
70
- * Performs the SHA224 hash algorithm on a ByteArray.
71
- *
72
- * @param data The ByteArray data to hash
73
- * @return A string containing the hash value of data
74
- * @langversion ActionScript 3.0
75
- * @playerversion 9.0
76
- */
77
- public static function hashBytes( data:ByteArray ):String
78
- {
79
- var blocks:Array = createBlocksFromByteArray( data );
80
- var byteArray:ByteArray = hashBlocks(blocks);
81
- return IntUtil.toHex( byteArray.readInt(), true )
82
- + IntUtil.toHex( byteArray.readInt(), true )
83
- + 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
- }
89
-
90
- /**
91
- * Performs the SHA224 hash algorithm on a string, then does
92
- * Base64 encoding on the result.
93
- *
94
- * @param s The string to hash
95
- * @return The base64 encoded hash value of s
96
- * @langversion ActionScript 3.0
97
- * @playerversion 9.0
98
- * @tiptext
99
- */
100
- public static function hashToBase64( s:String ):String
101
- {
102
- var blocks:Array = createBlocksFromString( s );
103
- var byteArray:ByteArray = hashBlocks(blocks);
104
-
105
- // ByteArray.toString() returns the contents as a UTF-8 string,
106
- // which we can't use because certain byte sequences might trigger
107
- // a UTF-8 conversion. Instead, we convert the bytes to characters
108
- // one by one.
109
- var charsInByteArray:String = "";
110
- byteArray.position = 0;
111
- for (var j:int = 0; j < byteArray.length; j++)
112
- {
113
- var byte:uint = byteArray.readUnsignedByte();
114
- charsInByteArray += String.fromCharCode(byte);
115
- }
116
-
117
- var encoder:Base64Encoder = new Base64Encoder();
118
- encoder.encode(charsInByteArray);
119
- return encoder.flush();
120
- }
121
-
122
- private static function hashBlocks( blocks:Array ):ByteArray {
123
- var h0:int = 0xc1059ed8;
124
- var h1:int = 0x367cd507;
125
- var h2:int = 0x3070dd17;
126
- var h3:int = 0xf70e5939;
127
- var h4:int = 0xffc00b31;
128
- var h5:int = 0x68581511;
129
- var h6:int = 0x64f98fa7;
130
- var h7:int = 0xbefa4fa4;
131
-
132
- 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);
133
-
134
- var len:int = blocks.length;
135
- var w:Array = new Array();
136
-
137
- // loop over all of the blocks
138
- for ( var i:int = 0; i < len; i += 16 ) {
139
-
140
- var a:int = h0;
141
- var b:int = h1;
142
- var c:int = h2;
143
- var d:int = h3;
144
- var e:int = h4;
145
- var f:int = h5;
146
- var g:int = h6;
147
- var h:int = h7;
148
-
149
- for(var t:int = 0; t < 64; t++) {
150
-
151
- if ( t < 16 ) {
152
- w[t] = blocks[ i + t ];
153
- if(isNaN(w[t])) { w[t] = 0; }
154
- } else {
155
- var ws0:int = IntUtil.ror(w[t-15], 7) ^ IntUtil.ror(w[t-15], 18) ^ (w[t-15] >>> 3);
156
- var ws1:int = IntUtil.ror(w[t-2], 17) ^ IntUtil.ror(w[t-2], 19) ^ (w[t-2] >>> 10);
157
- w[t] = w[t-16] + ws0 + w[t-7] + ws1;
158
- }
159
-
160
- var s0:int = IntUtil.ror(a, 2) ^ IntUtil.ror(a, 13) ^ IntUtil.ror(a, 22);
161
- var maj:int = (a & b) ^ (a & c) ^ (b & c);
162
- var t2:int = s0 + maj;
163
- var s1:int = IntUtil.ror(e, 6) ^ IntUtil.ror(e, 11) ^ IntUtil.ror(e, 25);
164
- var ch:int = (e & f) ^ ((~e) & g);
165
- var t1:int = h + s1 + ch + k[t] + w[t];
166
-
167
- h = g;
168
- g = f;
169
- f = e;
170
- e = d + t1;
171
- d = c;
172
- c = b;
173
- b = a;
174
- a = t1 + t2;
175
- }
176
-
177
- //Add this chunk's hash to result so far:
178
- h0 += a;
179
- h1 += b;
180
- h2 += c;
181
- h3 += d;
182
- h4 += e;
183
- h5 += f;
184
- h6 += g;
185
- h7 += h;
186
- }
187
-
188
- var byteArray:ByteArray = new ByteArray();
189
- byteArray.writeInt(h0);
190
- byteArray.writeInt(h1);
191
- byteArray.writeInt(h2);
192
- byteArray.writeInt(h3);
193
- byteArray.writeInt(h4);
194
- byteArray.writeInt(h5);
195
- byteArray.writeInt(h6);
196
- byteArray.position = 0;
197
-
198
- digest = new ByteArray();
199
- digest.writeBytes(byteArray);
200
- digest.position = 0;
201
- return byteArray;
202
- }
203
-
204
- /**
205
- * Converts a ByteArray to a sequence of 16-word blocks
206
- * that we'll do the processing on. Appends padding
207
- * and length in the process.
208
- *
209
- * @param data The data to split into blocks
210
- * @return An array containing the blocks into which data was split
211
- */
212
- private static function createBlocksFromByteArray( data:ByteArray ):Array
213
- {
214
- var oldPosition:int = data.position;
215
- data.position = 0;
216
-
217
- var blocks:Array = new Array();
218
- var len:int = data.length * 8;
219
- var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
220
- for( var i:int = 0; i < len; i += 8 )
221
- {
222
- blocks[ i >> 5 ] |= ( data.readByte() & mask ) << ( 24 - i % 32 );
223
- }
224
-
225
- // append padding and length
226
- blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
227
- blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
228
-
229
- data.position = oldPosition;
230
-
231
- return blocks;
232
- }
233
-
234
- /**
235
- * Converts a string to a sequence of 16-word blocks
236
- * that we'll do the processing on. Appends padding
237
- * and length in the process.
238
- *
239
- * @param s The string to split into blocks
240
- * @return An array containing the blocks that s was split into.
241
- */
242
- private static function createBlocksFromString( s:String ):Array
243
- {
244
- var blocks:Array = new Array();
245
- var len:int = s.length * 8;
246
- var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
247
- for( var i:int = 0; i < len; i += 8 ) {
248
- blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
249
- }
250
-
251
- // append padding and length
252
- blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
253
- blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
254
- return blocks;
255
- }
256
- }
257
- }