as3corelib 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +28 -0
  3. data/README.textile +79 -0
  4. data/Rakefile +3 -0
  5. data/as3corelib.gemspec +23 -0
  6. data/build/build.properties +48 -0
  7. data/build/build.xml +104 -0
  8. data/examples/JSONExample/JSONExample.mxml +73 -0
  9. data/lib/as3corelib.rb +15 -0
  10. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +313 -0
  11. data/src/com/adobe/air/filesystem/FileMonitor.as +245 -0
  12. data/src/com/adobe/air/filesystem/FileUtil.as +63 -0
  13. data/src/com/adobe/air/filesystem/VolumeMonitor.as +184 -0
  14. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +61 -0
  15. data/src/com/adobe/air/logging/FileTarget.as +95 -0
  16. data/src/com/adobe/air/net/ResourceCache.as +165 -0
  17. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +70 -0
  18. data/src/com/adobe/crypto/HMAC.as +127 -0
  19. data/src/com/adobe/crypto/MD5.as +281 -0
  20. data/src/com/adobe/crypto/MD5Stream.as +402 -0
  21. data/src/com/adobe/crypto/SHA1.as +289 -0
  22. data/src/com/adobe/crypto/SHA224.as +257 -0
  23. data/src/com/adobe/crypto/SHA256.as +261 -0
  24. data/src/com/adobe/crypto/WSSEUsernameToken.as +114 -0
  25. data/src/com/adobe/errors/IllegalStateError.as +63 -0
  26. data/src/com/adobe/fileformats/vcard/Address.as +47 -0
  27. data/src/com/adobe/fileformats/vcard/Email.as +39 -0
  28. data/src/com/adobe/fileformats/vcard/Phone.as +39 -0
  29. data/src/com/adobe/fileformats/vcard/VCard.as +54 -0
  30. data/src/com/adobe/fileformats/vcard/VCardParser.as +246 -0
  31. data/src/com/adobe/images/BitString.as +39 -0
  32. data/src/com/adobe/images/JPGEncoder.as +648 -0
  33. data/src/com/adobe/images/PNGEncoder.as +141 -0
  34. data/src/com/adobe/net/DynamicURLLoader.as +55 -0
  35. data/src/com/adobe/net/IURIResolver.as +76 -0
  36. data/src/com/adobe/net/MimeTypeMap.as +200 -0
  37. data/src/com/adobe/net/URI.as +2466 -0
  38. data/src/com/adobe/net/URIEncodingBitmap.as +139 -0
  39. data/src/com/adobe/net/proxies/RFC2817Socket.as +198 -0
  40. data/src/com/adobe/protocols/dict/Database.as +66 -0
  41. data/src/com/adobe/protocols/dict/Definition.as +71 -0
  42. data/src/com/adobe/protocols/dict/Dict.as +360 -0
  43. data/src/com/adobe/protocols/dict/DictionaryServer.as +60 -0
  44. data/src/com/adobe/protocols/dict/MatchStrategy.as +66 -0
  45. data/src/com/adobe/protocols/dict/Response.as +71 -0
  46. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +53 -0
  47. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +67 -0
  48. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +70 -0
  49. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +69 -0
  50. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +69 -0
  51. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +55 -0
  52. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +80 -0
  53. data/src/com/adobe/protocols/dict/events/MatchEvent.as +67 -0
  54. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +70 -0
  55. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +54 -0
  56. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +68 -0
  57. data/src/com/adobe/protocols/dict/util/SocketHelper.as +81 -0
  58. data/src/com/adobe/serialization/json/JSON.as +86 -0
  59. data/src/com/adobe/serialization/json/JSONDecoder.as +327 -0
  60. data/src/com/adobe/serialization/json/JSONEncoder.as +312 -0
  61. data/src/com/adobe/serialization/json/JSONParseError.as +87 -0
  62. data/src/com/adobe/serialization/json/JSONToken.as +104 -0
  63. data/src/com/adobe/serialization/json/JSONTokenType.as +69 -0
  64. data/src/com/adobe/serialization/json/JSONTokenizer.as +702 -0
  65. data/src/com/adobe/utils/ArrayUtil.as +187 -0
  66. data/src/com/adobe/utils/DateUtil.as +701 -0
  67. data/src/com/adobe/utils/DictionaryUtil.as +87 -0
  68. data/src/com/adobe/utils/IntUtil.as +99 -0
  69. data/src/com/adobe/utils/NumberFormatter.as +74 -0
  70. data/src/com/adobe/utils/StringUtil.as +239 -0
  71. data/src/com/adobe/utils/XMLUtil.as +168 -0
  72. data/src/com/adobe/webapis/ServiceBase.as +48 -0
  73. data/src/com/adobe/webapis/URLLoaderBase.as +108 -0
  74. data/src/com/adobe/webapis/events/ServiceEvent.as +82 -0
  75. data/tests/src/CoreLibTestRunner-app.xml +135 -0
  76. data/tests/src/CoreLibTestRunner.as +138 -0
  77. data/tests/src/CoreLibTestRunner.mxml +46 -0
  78. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +176 -0
  79. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +63 -0
  80. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +57 -0
  81. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +59 -0
  82. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +72 -0
  83. data/tests/src/com/adobe/crypto/HMACMD5Test.as +134 -0
  84. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +138 -0
  85. data/tests/src/com/adobe/crypto/MD5Test.as +82 -0
  86. data/tests/src/com/adobe/crypto/SHA1Test.as +151 -0
  87. data/tests/src/com/adobe/crypto/SHA224Test.as +104 -0
  88. data/tests/src/com/adobe/crypto/SHA256Test.as +116 -0
  89. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +87 -0
  90. data/tests/src/com/adobe/images/JPGEncoderTest.as +54 -0
  91. data/tests/src/com/adobe/images/PNGEncoderTest.as +54 -0
  92. data/tests/src/com/adobe/net/URITest.as +589 -0
  93. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +59 -0
  94. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +62 -0
  95. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +61 -0
  96. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +61 -0
  97. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +61 -0
  98. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +59 -0
  99. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +63 -0
  100. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +61 -0
  101. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +61 -0
  102. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +58 -0
  103. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +60 -0
  104. data/tests/src/com/adobe/serialization/json/JSONTest.as +522 -0
  105. data/tests/src/com/adobe/serialization/json/SimpleClass.as +85 -0
  106. data/tests/src/com/adobe/utils/ArrayUtilTest.as +173 -0
  107. data/tests/src/com/adobe/utils/DateUtilTest.as +436 -0
  108. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +93 -0
  109. data/tests/src/com/adobe/utils/IntUtilTest.as +73 -0
  110. data/tests/src/com/adobe/utils/NumberFormatterTest.as +70 -0
  111. data/tests/src/com/adobe/utils/StringUtilTest.as +304 -0
  112. data/tests/src/com/adobe/utils/XMLUtilTest.as +101 -0
  113. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +66 -0
  114. metadata +196 -0
@@ -0,0 +1,138 @@
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
+
36
+ import flash.utils.ByteArray;
37
+ import flexunit.framework.TestCase;
38
+ import flexunit.framework.TestSuite;
39
+ import com.adobe.crypto.HMAC;
40
+ import com.adobe.crypto.SHA1;
41
+ /**
42
+ * Test Cases for HMAC-MD5 and HMAC-SHA-1
43
+ * Implementation based on test cases description at
44
+ * http://www.faqs.org/rfcs/rfc2202.html
45
+ */
46
+ public class HMACSHA1Test extends TestCase
47
+ {
48
+ private var key:ByteArray;
49
+ private var data:ByteArray;
50
+ private var x:int;
51
+
52
+ public function HMACSHA1Test( methodName:String = null) {
53
+ super( methodName );
54
+ }
55
+
56
+ override public function setUp():void
57
+ {
58
+ super.setUp();
59
+ key = new ByteArray();
60
+ data = new ByteArray();
61
+ }
62
+
63
+ public function test1():void {
64
+ for ( x = 0; x < 20; x++ ) {
65
+ key.writeByte(0x0b);
66
+ }
67
+ data.writeUTFBytes("Hi There");
68
+ assertHMAC(key, data, "b617318655057264e28bc0b6fb378c8ef146be00");
69
+ }
70
+
71
+ public function test2():void {
72
+ key.writeUTFBytes("Jefe");
73
+ data.writeUTFBytes("what do ya want for nothing?");
74
+ assertHMAC(key, data, "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79");
75
+ }
76
+
77
+ public function test3():void {
78
+ for ( x = 0; x < 20; x++ ) {
79
+ key.writeByte(0xaa);
80
+ }
81
+
82
+ for ( x = 0; x < 50; x++ ) {
83
+ data.writeByte(0xdd);
84
+ }
85
+
86
+ assertHMAC(key, data, "125d7342b9ac11cd91a39af48aa17b4f63f175d3");
87
+ }
88
+
89
+ public function test4():void {
90
+ for ( x = 0; x < 25; x++ ) {
91
+ key.writeByte( x + 1 );
92
+ }
93
+
94
+ for ( x = 0; x < 50; x++ ) {
95
+ data.writeByte(0xcd);
96
+ }
97
+
98
+ assertHMAC(key, data, "4c9007f4026250c6bc8414f9bf50c86c2d7235da");
99
+ }
100
+
101
+ public function test5():void {
102
+ for ( x = 0; x < 20; x++ ) {
103
+ key.writeByte(0x0c);
104
+ }
105
+
106
+ data.writeUTFBytes("Test With Truncation");
107
+
108
+ assertHMAC(key, data, "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04");
109
+ }
110
+
111
+ public function test6():void {
112
+ for ( x = 0; x < 80; x++ ) {
113
+ key.writeByte( 0xaa );
114
+ }
115
+
116
+ data.writeUTFBytes("Test Using Larger Than Block-Size Key - Hash Key First");
117
+
118
+ assertHMAC(key, data, "aa4ae5e15272d00e95705637ce8a3b55ed402112");
119
+ }
120
+
121
+ public function test7():void {
122
+ for ( x = 0; x < 80; x++ ) {
123
+ key.writeByte( 0xaa );
124
+ }
125
+
126
+ data.writeUTFBytes("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data");
127
+
128
+ assertHMAC(key, data, "e8e99d0f45237d786d6bbaa7965c7808bbff1a91");
129
+ }
130
+
131
+ private function assertHMAC( key:ByteArray, value:ByteArray, expected:String):void {
132
+ assertTrue( "Hash of '" + value.toString() + "' with key '" + key.toString() + "' returned wrong value ('" + HMAC.hashBytes(key,value,SHA1) + " ')",
133
+ HMAC.hashBytes(key,value, SHA1) == expected );
134
+ };
135
+
136
+ }
137
+
138
+ }
@@ -0,0 +1,82 @@
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
+
36
+ import flexunit.framework.TestCase;
37
+ import flexunit.framework.TestSuite;
38
+
39
+ import com.adobe.crypto.MD5;
40
+
41
+ public class MD5Test extends TestCase {
42
+
43
+ public function MD5Test( methodName:String = null) {
44
+ super( methodName );
45
+ }
46
+
47
+ public function testEmpty():void {
48
+ assertMD5( "", "d41d8cd98f00b204e9800998ecf8427e" );
49
+ }
50
+
51
+ public function testA():void {
52
+ assertMD5( "a", "0cc175b9c0f1b6a831c399e269772661" );
53
+ }
54
+
55
+ public function testABC():void {
56
+ assertMD5( "abc", "900150983cd24fb0d6963f7d28e17f72" );
57
+ }
58
+
59
+ public function testMD():void {
60
+ assertMD5( "message digest", "f96b697d7cb7938d525a2f31aaf161d0" );
61
+ }
62
+
63
+ public function testAlphabet():void {
64
+ assertMD5( "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" );
65
+ }
66
+
67
+ public function testAlphaNumeric():void {
68
+ assertMD5( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f" );
69
+ }
70
+
71
+ public function testRepeatingNumeric():void {
72
+ assertMD5( "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" );
73
+ }
74
+
75
+ private function assertMD5( value:String, expected:String ):void {
76
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + MD5.hash( value ) + " ')",
77
+ MD5.hash( value ) == expected );
78
+ };
79
+
80
+ }
81
+
82
+ }
@@ -0,0 +1,151 @@
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
+
36
+ import flash.utils.ByteArray;
37
+ import flexunit.framework.TestCase;
38
+ import flexunit.framework.TestSuite;
39
+
40
+ import com.adobe.crypto.SHA1;
41
+ import com.adobe.utils.IntUtil;
42
+
43
+ public class SHA1Test extends TestCase {
44
+
45
+ public function SHA1Test( methodName:String = null ) {
46
+ super( methodName );
47
+ }
48
+
49
+ public function testSHA1():void {
50
+
51
+ assertSHA1( "abc", "a9993e364706816aba3e25717850c26c9cd0d89d" );
52
+
53
+ assertSHA1( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
54
+ "84983e441c3bd26ebaae4aa1f95129e5e54670f1" );
55
+
56
+ assertSHA1( "The quick brown fox jumps over the lazy dog",
57
+ "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" );
58
+
59
+ assertSHA1( "The quick brown fox jumps over the lazy cog",
60
+ "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" );
61
+
62
+ assertSHA1( "",
63
+ "da39a3ee5e6b4b0d3255bfef95601890afd80709" );
64
+
65
+ assertSHA1( "d36e316282959a9ed4c89851497a717f2003-12-15T14:43:07Ztaadtaadpstcsm",
66
+ "aae47f1162c0578c4b7fd66acb0e290e67d5f4e6" );
67
+
68
+ var millionAs:String = new String("");
69
+ for ( var i:int = 0; i < 1000000; i++ ) {
70
+ millionAs += "a";
71
+ }
72
+ assertSHA1( millionAs, "34aa973cd4c4daa4f61eeb2bdbad27316534016f" );
73
+ }
74
+
75
+ public function testSHA1Binary():void {
76
+
77
+ assertSHA1Binary( "abc", "a9993e364706816aba3e25717850c26c9cd0d89d" );
78
+
79
+ assertSHA1Binary( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
80
+ "84983e441c3bd26ebaae4aa1f95129e5e54670f1" );
81
+
82
+ assertSHA1Binary( "The quick brown fox jumps over the lazy dog",
83
+ "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" );
84
+
85
+ assertSHA1Binary( "The quick brown fox jumps over the lazy cog",
86
+ "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" );
87
+
88
+ assertSHA1Binary( "",
89
+ "da39a3ee5e6b4b0d3255bfef95601890afd80709" );
90
+
91
+ assertSHA1Binary( "d36e316282959a9ed4c89851497a717f2003-12-15T14:43:07Ztaadtaadpstcsm",
92
+ "aae47f1162c0578c4b7fd66acb0e290e67d5f4e6" );
93
+
94
+ var millionAs:String = new String("");
95
+ for ( var i:int = 0; i < 1000000; i++ ) {
96
+ millionAs += "a";
97
+ }
98
+ assertSHA1Binary( millionAs, "34aa973cd4c4daa4f61eeb2bdbad27316534016f" );
99
+ }
100
+
101
+ public function testSHA1Base64():void {
102
+ assertSHA1Base64( "abc", "qZk+NkcGgWq6PiVxeFDCbJzQ2J0=" );
103
+
104
+ assertSHA1Base64( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
105
+ "hJg+RBw70m66rkqh+VEp5eVGcPE=");
106
+
107
+ assertSHA1Base64( "The quick brown fox jumps over the lazy dog",
108
+ "L9ThxnotKPzthJ7hu3bnORuT6xI=" );
109
+
110
+ assertSHA1Base64( "The quick brown fox jumps over the lazy cog",
111
+ "3p8sf9JeGzr60+haC9F9mxANtLM=" );
112
+
113
+ assertSHA1Base64( "",
114
+ "2jmj7l5rSw0yVb/vlWAYkK/YBwk=" );
115
+
116
+ assertSHA1Base64( "d36e316282959a9ed4c89851497a717f2003-12-15T14:43:07Ztaadtaadpstcsm",
117
+ "quR/EWLAV4xLf9Zqyw4pDmfV9OY=" );
118
+
119
+ var millionAs:String = new String("");
120
+ for ( var i:int = 0; i < 1000000; i++ ) {
121
+ millionAs += "a";
122
+ }
123
+ assertSHA1Base64( millionAs, "NKqXPNTE2qT2Husr260nMWU0AW8=" );
124
+ }
125
+
126
+ private function assertSHA1( value:String, expected:String ):void {
127
+ var result:String = SHA1.hash( value );
128
+
129
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
130
+ result == expected );
131
+ }
132
+
133
+ private function assertSHA1Binary(value:String, expected:String):void {
134
+
135
+ var byteArray:ByteArray = new ByteArray();
136
+ byteArray.writeUTFBytes(value);
137
+
138
+ var result:String = SHA1.hashBytes( byteArray );
139
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
140
+ result == expected );
141
+ }
142
+
143
+ private function assertSHA1Base64( value:String, expected:String ):void {
144
+ var result:String = SHA1.hashToBase64( value );
145
+
146
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
147
+ result == expected );
148
+ }
149
+
150
+ }
151
+ }
@@ -0,0 +1,104 @@
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
+
36
+ import flash.utils.ByteArray;
37
+ import flexunit.framework.TestCase;
38
+ import flexunit.framework.TestSuite;
39
+
40
+ import com.adobe.crypto.SHA256;
41
+
42
+ public class SHA224Test extends TestCase {
43
+
44
+ public function SHA224Test( methodName:String = null ) {
45
+ super( methodName );
46
+ }
47
+
48
+ public function testSHA224():void {
49
+
50
+ // from the spec ( http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf )
51
+ assertSHA224( "abc", "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" );
52
+ assertSHA224( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" );
53
+
54
+ var millionAs:String = new String("");
55
+ for ( var i:int = 0; i < 1000000; i++ ) {
56
+ millionAs += "a";
57
+ }
58
+ assertSHA224( millionAs, "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" );
59
+
60
+ }
61
+
62
+ public function testSHA224Binary():void {
63
+
64
+ // from the spec ( http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf )
65
+ assertSHA224Binary( "abc", "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" );
66
+ assertSHA224Binary( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" );
67
+
68
+ var millionAs:String = new String("");
69
+ for ( var i:int = 0; i < 1000000; i++ ) {
70
+ millionAs += "a";
71
+ }
72
+ assertSHA224Binary( millionAs, "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" );
73
+ }
74
+
75
+ public function testSHA224Base64():void {
76
+
77
+ }
78
+
79
+ private function assertSHA224( value:String, expected:String ):void {
80
+ var result:String = SHA224.hash( value );
81
+
82
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
83
+ result == expected );
84
+ }
85
+
86
+ private function assertSHA224Binary(value:String, expected:String):void {
87
+
88
+ var byteArray:ByteArray = new ByteArray();
89
+ byteArray.writeUTFBytes(value);
90
+
91
+ var result:String = SHA224.hashBytes( byteArray );
92
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
93
+ result == expected );
94
+ }
95
+
96
+ private function assertSHA224Base64( value:String, expected:String ):void {
97
+ var result:String = SHA224.hashToBase64( value );
98
+
99
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
100
+ result == expected );
101
+ }
102
+
103
+ }
104
+ }
@@ -0,0 +1,116 @@
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
+
36
+ import flash.utils.ByteArray;
37
+ import flexunit.framework.TestCase;
38
+ import flexunit.framework.TestSuite;
39
+
40
+ import com.adobe.crypto.SHA256;
41
+
42
+ public class SHA256Test extends TestCase {
43
+
44
+ public function SHA256Test( methodName:String = null ) {
45
+ super( methodName );
46
+ }
47
+
48
+ public function testSHA256():void {
49
+
50
+
51
+ // from the spec ( http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf )
52
+ assertSHA256( "abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" );
53
+ assertSHA256( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
54
+
55
+ var millionAs:String = new String("");
56
+ for ( var i:int = 0; i < 1000000; i++ ) {
57
+ millionAs += "a";
58
+ }
59
+ assertSHA256( millionAs, "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" );
60
+
61
+ // from wikipedia
62
+ assertSHA256( "The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592" );
63
+ assertSHA256( "The quick brown fox jumps over the lazy cog", "e4c4d8f3bf76b692de791a173e05321150f7a345b46484fe427f6acc7ecc81be" );
64
+ assertSHA256( "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" );
65
+
66
+ }
67
+
68
+ public function testSHA256Binary():void {
69
+
70
+ // from the spec ( http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf )
71
+ assertSHA256Binary( "abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" );
72
+ assertSHA256Binary( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
73
+
74
+ var millionAs:String = new String("");
75
+ for ( var i:int = 0; i < 1000000; i++ ) {
76
+ millionAs += "a";
77
+ }
78
+ assertSHA256Binary( millionAs, "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" );
79
+
80
+ // from wikipedia
81
+ assertSHA256Binary( "The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592" );
82
+ assertSHA256Binary( "The quick brown fox jumps over the lazy cog", "e4c4d8f3bf76b692de791a173e05321150f7a345b46484fe427f6acc7ecc81be" );
83
+ assertSHA256Binary( "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" );
84
+
85
+ }
86
+
87
+ public function testSHA256Base64():void {
88
+
89
+ }
90
+
91
+ private function assertSHA256( value:String, expected:String ):void {
92
+ var result:String = SHA256.hash( value );
93
+
94
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
95
+ result == expected );
96
+ }
97
+
98
+ private function assertSHA256Binary(value:String, expected:String):void {
99
+
100
+ var byteArray:ByteArray = new ByteArray();
101
+ byteArray.writeUTFBytes(value);
102
+
103
+ var result:String = SHA256.hashBytes( byteArray );
104
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
105
+ result == expected );
106
+ }
107
+
108
+ private function assertSHA256Base64( value:String, expected:String ):void {
109
+ var result:String = SHA256.hashToBase64( value );
110
+
111
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
112
+ result == expected );
113
+ }
114
+
115
+ }
116
+ }
@@ -0,0 +1,87 @@
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
+
36
+ import com.adobe.crypto.WSSEUsernameToken;
37
+
38
+ import flexunit.framework.TestCase;
39
+ import flexunit.framework.TestSuite;
40
+
41
+ public class WSSEUsernameTokenTest extends TestCase {
42
+
43
+ public function WSSEUsernameTokenTest( methodName:String = null ) {
44
+ super( methodName );
45
+ }
46
+
47
+ public function testWSSEUsernameToken():void {
48
+
49
+ // Results generated from stripped-down version of Claude
50
+ // Montpetit's WSSE-enabled Atom API client (see
51
+ // http://www.montpetit.net/en/2004/06/06/11h32/index.html).
52
+ //
53
+
54
+ var date:Date = new Date(Date.parse("05/09/2006 13:43:21 GMT-0700"));
55
+ assertWSSEUsernameToken( "abc", "abc", "0123456789", date,
56
+ "UsernameToken Username=\"abc\", PasswordDigest=\""
57
+ + WSSEUsernameToken.getBase64Digest( WSSEUsernameToken.base64Encode( "0123456789" ),
58
+ WSSEUsernameToken.generateTimestamp( date ),
59
+ "abc" )
60
+ + "\", Nonce=\"MDEyMzQ1Njc4OQ==\", Created=\"2006-05-09T" + ( date.hours < 10 ? "0" + date.hours : date.hours ) + ":43:21Z\"" );
61
+
62
+ date = new Date(Date.parse("05/09/2006 16:11:46 GMT-0700"));
63
+ assertWSSEUsernameToken( "fe31_449", "168fqo4659", "1147216300992", date,
64
+ "UsernameToken Username=\"fe31_449\", PasswordDigest=\""
65
+ + WSSEUsernameToken.getBase64Digest( WSSEUsernameToken.base64Encode( "1147216300992" ),
66
+ WSSEUsernameToken.generateTimestamp( date ),
67
+ "168fqo4659" )
68
+ + "\", Nonce=\"MTE0NzIxNjMwMDk5Mg==\", Created=\"2006-05-09T" + ( date.hours < 10 ? "0" + date.hours : date.hours ) + ":11:46Z\"" );
69
+
70
+ date = new Date(Date.parse("08/16/2006 01:48:28 GMT-0700"));
71
+ assertWSSEUsernameToken( "candy", "dandy", "2018558572", date,
72
+ "UsernameToken Username=\"candy\", PasswordDigest=\""
73
+ + WSSEUsernameToken.getBase64Digest( WSSEUsernameToken.base64Encode( "2018558572" ),
74
+ WSSEUsernameToken.generateTimestamp( date ),
75
+ "dandy" )
76
+ + "\", Nonce=\"MjAxODU1ODU3Mg==\", Created=\"2006-08-16T" + ( date.hours < 10 ? "0" + date.hours : date.hours ) + ":48:28Z\"" );
77
+ }
78
+
79
+ private function assertWSSEUsernameToken( username:String, password:String, nonce:String,
80
+ timestamp:Date, expected:String ):void {
81
+ var result:String = WSSEUsernameToken.getUsernameToken( username, password, nonce, timestamp );
82
+
83
+ assertTrue( "WSSEUsernameToken returned wrong value ('" + result + "')" + expected,
84
+ result == expected );
85
+ }
86
+ }
87
+ }