Skip to content
Browse files

Initial import (minor modifications from revision 617 of the Adobe La…

0 parents commit fa0cdf00f77194432c44421786ee4b2465f2f4d6 @darronschall darronschall committed Dec 21, 2006
Showing with 9,909 additions and 0 deletions.
  1. +73 −0 examples/JSONExample/JSONExample.mxml
  2. +256 −0 src/com/adobe/crypto/MD5.as
  3. +221 −0 src/com/adobe/crypto/SHA1.as
  4. +117 −0 src/com/adobe/crypto/WSSEUsernameToken.as
  5. +84 −0 src/com/adobe/crypto/tests/MD5Test.as
  6. +117 −0 src/com/adobe/crypto/tests/SHA1Test.as
  7. +74 −0 src/com/adobe/crypto/tests/WSSEUsernameTokenTest.as
  8. +66 −0 src/com/adobe/errors/IllegalStateError.as
  9. +42 −0 src/com/adobe/images/BitString.as
  10. +630 −0 src/com/adobe/images/JPGEncoder.as
  11. +132 −0 src/com/adobe/images/PNGEncoder.as
  12. +58 −0 src/com/adobe/net/DynamicURLLoader.as
  13. +73 −0 src/com/adobe/net/IURIResolver.as
  14. +2,466 −0 src/com/adobe/net/URI.as
  15. +133 −0 src/com/adobe/net/URIEncodingBitmap.as
  16. +204 −0 src/com/adobe/net/proxies/RFC2817Socket.as
  17. +592 −0 src/com/adobe/net/tests/URITest.as
  18. +88 −0 src/com/adobe/serialization/json/JSON.as
  19. +218 −0 src/com/adobe/serialization/json/JSONDecoder.as
  20. +273 −0 src/com/adobe/serialization/json/JSONEncoder.as
  21. +90 −0 src/com/adobe/serialization/json/JSONParseError.as
  22. +107 −0 src/com/adobe/serialization/json/JSONToken.as
  23. +70 −0 src/com/adobe/serialization/json/JSONTokenType.as
  24. +550 −0 src/com/adobe/serialization/json/JSONTokenizer.as
  25. +297 −0 src/com/adobe/serialization/json/tests/JSONTest.as
  26. +190 −0 src/com/adobe/utils/ArrayUtil.as
  27. +666 −0 src/com/adobe/utils/DateUtil.as
  28. +57 −0 src/com/adobe/utils/IntUtil.as
  29. +77 −0 src/com/adobe/utils/NumberFormatter.as
  30. +257 −0 src/com/adobe/utils/StringUtil.as
  31. +147 −0 src/com/adobe/utils/XMLUtil.as
  32. +176 −0 src/com/adobe/utils/tests/ArrayUtilTest.as
  33. +398 −0 src/com/adobe/utils/tests/DateUtilTest.as
  34. +75 −0 src/com/adobe/utils/tests/IntUtilTest.as
  35. +73 −0 src/com/adobe/utils/tests/NumberFormatterTest.as
  36. +307 −0 src/com/adobe/utils/tests/StringUtilTest.as
  37. +104 −0 src/com/adobe/utils/tests/XMLUtilTest.as
  38. +51 −0 src/com/adobe/webapis/ServiceBase.as
  39. +99 −0 src/com/adobe/webapis/URLLoaderBase.as
  40. +78 −0 src/com/adobe/webapis/events/ServiceEvent.as
  41. +73 −0 tests/CoreLibTestRunner/CoreLibTestRunner.as
  42. +50 −0 tests/CoreLibTestRunner/CoreLibTestRunner.mxml
73 examples/JSONExample/JSONExample.mxml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
+ layout="absolute"
+ creationComplete="service.send()" viewSourceURL="srcview/index.html">
+
+ <mx:Script>
+ <![CDATA[
+ import mx.collections.ArrayCollection;
+ import mx.rpc.events.ResultEvent;
+ import com.adobe.serialization.json.JSON;
+
+ private function onJSONLoad(event:ResultEvent):void
+ {
+ var rawData:String = String(event.result);
+ var arr:Array = (JSON.decode(rawData) as Array);
+
+ var dp:ArrayCollection = new ArrayCollection(arr);
+
+ grid.dataProvider = dp;
+ }
+ ]]>
+ </mx:Script>
+
+ <mx:HTTPService
+ id="service"
+ resultFormat="text"
+ url="http://weblogs.macromedia.com/mesh/mashedpotato.json"
+ result="onJSONLoad(event)" />
+
+ <mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10">
+ <mx:columns>
+ <mx:DataGridColumn headerText="Service" dataField="src"/>
+ <mx:DataGridColumn headerText="Title" dataField="title"/>
+ </mx:columns>
+ </mx:DataGrid>
+
+</mx:Application>
256 src/com/adobe/crypto/MD5.as
@@ -0,0 +1,256 @@
+/*
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.crypto {
+
+ import com.adobe.utils.IntUtil;
+
+ /**
+ * The MD5 Message-Digest Algorithm
+ *
+ * Implementation based on algorithm description at
+ * http://www.faqs.org/rfcs/rfc1321.html
+ */
+ public class MD5 {
+
+ /**
+ * Performs the MD5 hash algorithm on a string.
+ *
+ * @param s The string to hash
+ * @return A string containing the hash value of s
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 8.5
+ * @tiptext
+ */
+ public static function hash( s:String ):String {
+ // initialize the md buffers
+ var a:int = 1732584193;
+ var b:int = -271733879;
+ var c:int = -1732584194;
+ var d:int = 271733878;
+
+ // variables to store previous values
+ var aa:int;
+ var bb:int;
+ var cc:int;
+ var dd:int;
+
+ // create the blocks from the string and
+ // save the length as a local var to reduce
+ // lookup in the loop below
+ var x:Array = createBlocks( s );
+ var len:int = x.length;
+
+ // loop over all of the blocks
+ for ( var i:int = 0; i < len; i += 16) {
+ // save previous values
+ aa = a;
+ bb = b;
+ cc = c;
+ dd = d;
+
+ // Round 1
+ a = ff( a, b, c, d, x[i+ 0], 7, -680876936 ); // 1
+ d = ff( d, a, b, c, x[i+ 1], 12, -389564586 ); // 2
+ c = ff( c, d, a, b, x[i+ 2], 17, 606105819 ); // 3
+ b = ff( b, c, d, a, x[i+ 3], 22, -1044525330 ); // 4
+ a = ff( a, b, c, d, x[i+ 4], 7, -176418897 ); // 5
+ d = ff( d, a, b, c, x[i+ 5], 12, 1200080426 ); // 6
+ c = ff( c, d, a, b, x[i+ 6], 17, -1473231341 ); // 7
+ b = ff( b, c, d, a, x[i+ 7], 22, -45705983 ); // 8
+ a = ff( a, b, c, d, x[i+ 8], 7, 1770035416 ); // 9
+ d = ff( d, a, b, c, x[i+ 9], 12, -1958414417 ); // 10
+ c = ff( c, d, a, b, x[i+10], 17, -42063 ); // 11
+ b = ff( b, c, d, a, x[i+11], 22, -1990404162 ); // 12
+ a = ff( a, b, c, d, x[i+12], 7, 1804603682 ); // 13
+ d = ff( d, a, b, c, x[i+13], 12, -40341101 ); // 14
+ c = ff( c, d, a, b, x[i+14], 17, -1502002290 ); // 15
+ b = ff( b, c, d, a, x[i+15], 22, 1236535329 ); // 16
+
+ // Round 2
+ a = gg( a, b, c, d, x[i+ 1], 5, -165796510 ); // 17
+ d = gg( d, a, b, c, x[i+ 6], 9, -1069501632 ); // 18
+ c = gg( c, d, a, b, x[i+11], 14, 643717713 ); // 19
+ b = gg( b, c, d, a, x[i+ 0], 20, -373897302 ); // 20
+ a = gg( a, b, c, d, x[i+ 5], 5, -701558691 ); // 21
+ d = gg( d, a, b, c, x[i+10], 9, 38016083 ); // 22
+ c = gg( c, d, a, b, x[i+15], 14, -660478335 ); // 23
+ b = gg( b, c, d, a, x[i+ 4], 20, -405537848 ); // 24
+ a = gg( a, b, c, d, x[i+ 9], 5, 568446438 ); // 25
+ d = gg( d, a, b, c, x[i+14], 9, -1019803690 ); // 26
+ c = gg( c, d, a, b, x[i+ 3], 14, -187363961 ); // 27
+ b = gg( b, c, d, a, x[i+ 8], 20, 1163531501 ); // 28
+ a = gg( a, b, c, d, x[i+13], 5, -1444681467 ); // 29
+ d = gg( d, a, b, c, x[i+ 2], 9, -51403784 ); // 30
+ c = gg( c, d, a, b, x[i+ 7], 14, 1735328473 ); // 31
+ b = gg( b, c, d, a, x[i+12], 20, -1926607734 ); // 32
+
+ // Round 3
+ a = hh( a, b, c, d, x[i+ 5], 4, -378558 ); // 33
+ d = hh( d, a, b, c, x[i+ 8], 11, -2022574463 ); // 34
+ c = hh( c, d, a, b, x[i+11], 16, 1839030562 ); // 35
+ b = hh( b, c, d, a, x[i+14], 23, -35309556 ); // 36
+ a = hh( a, b, c, d, x[i+ 1], 4, -1530992060 ); // 37
+ d = hh( d, a, b, c, x[i+ 4], 11, 1272893353 ); // 38
+ c = hh( c, d, a, b, x[i+ 7], 16, -155497632 ); // 39
+ b = hh( b, c, d, a, x[i+10], 23, -1094730640 ); // 40
+ a = hh( a, b, c, d, x[i+13], 4, 681279174 ); // 41
+ d = hh( d, a, b, c, x[i+ 0], 11, -358537222 ); // 42
+ c = hh( c, d, a, b, x[i+ 3], 16, -722521979 ); // 43
+ b = hh( b, c, d, a, x[i+ 6], 23, 76029189 ); // 44
+ a = hh( a, b, c, d, x[i+ 9], 4, -640364487 ); // 45
+ d = hh( d, a, b, c, x[i+12], 11, -421815835 ); // 46
+ c = hh( c, d, a, b, x[i+15], 16, 530742520 ); // 47
+ b = hh( b, c, d, a, x[i+ 2], 23, -995338651 ); // 48
+
+ // Round 4
+ a = ii( a, b, c, d, x[i+ 0], 6, -198630844 ); // 49
+ d = ii( d, a, b, c, x[i+ 7], 10, 1126891415 ); // 50
+ c = ii( c, d, a, b, x[i+14], 15, -1416354905 ); // 51
+ b = ii( b, c, d, a, x[i+ 5], 21, -57434055 ); // 52
+ a = ii( a, b, c, d, x[i+12], 6, 1700485571 ); // 53
+ d = ii( d, a, b, c, x[i+ 3], 10, -1894986606 ); // 54
+ c = ii( c, d, a, b, x[i+10], 15, -1051523 ); // 55
+ b = ii( b, c, d, a, x[i+ 1], 21, -2054922799 ); // 56
+ a = ii( a, b, c, d, x[i+ 8], 6, 1873313359 ); // 57
+ d = ii( d, a, b, c, x[i+15], 10, -30611744 ); // 58
+ c = ii( c, d, a, b, x[i+ 6], 15, -1560198380 ); // 59
+ b = ii( b, c, d, a, x[i+13], 21, 1309151649 ); // 60
+ a = ii( a, b, c, d, x[i+ 4], 6, -145523070 ); // 61
+ d = ii( d, a, b, c, x[i+11], 10, -1120210379 ); // 62
+ c = ii( c, d, a, b, x[i+ 2], 15, 718787259 ); // 63
+ b = ii( b, c, d, a, x[i+ 9], 21, -343485551 ); // 64
+
+ a += aa;
+ b += bb;
+ c += cc;
+ d += dd;
+ }
+
+ // Finish up by concatening the buffers with their hex output
+ return IntUtil.toHex( a ) + IntUtil.toHex( b ) + IntUtil.toHex( c ) + IntUtil.toHex( d );
+ }
+
+ /**
+ * Auxiliary function f as defined in RFC
+ */
+ private static function f( x:int, y:int, z:int ):int {
+ return ( x & y ) | ( (~x) & z );
+ }
+
+ /**
+ * Auxiliary function g as defined in RFC
+ */
+ private static function g( x:int, y:int, z:int ):int {
+ return ( x & z ) | ( y & (~z) );
+ }
+
+ /**
+ * Auxiliary function h as defined in RFC
+ */
+ private static function h( x:int, y:int, z:int ):int {
+ return x ^ y ^ z;
+ }
+
+ /**
+ * Auxiliary function i as defined in RFC
+ */
+ private static function i( x:int, y:int, z:int ):int {
+ return y ^ ( x | (~z) );
+ }
+
+ /**
+ * A generic transformation function. The logic of ff, gg, hh, and
+ * ii are all the same, minus the function used, so pull that logic
+ * out and simplify the method bodies for the transoformation functions.
+ */
+ private static function transform( func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int):int {
+ var tmp:int = a + int( func( b, c, d ) ) + x + t;
+ return IntUtil.rol( tmp, s ) + b;
+ }
+
+ /**
+ * ff transformation function
+ */
+ private static function ff ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
+ return transform( f, a, b, c, d, x, s, t );
+ }
+
+ /**
+ * gg transformation function
+ */
+ private static function gg ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
+ return transform( g, a, b, c, d, x, s, t );
+ }
+
+ /**
+ * hh transformation function
+ */
+ private static function hh ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
+ return transform( h, a, b, c, d, x, s, t );
+ }
+
+ /**
+ * ii transformation function
+ */
+ private static function ii ( a:int, b:int, c:int, d:int, x:int, s:int, t:int ):int {
+ return transform( i, a, b, c, d, x, s, t );
+ }
+
+ /**
+ * Converts a string to a sequence of 16-word blocks
+ * that we'll do the processing on. Appends padding
+ * and length in the process.
+ *
+ * @param s The string to split into blocks
+ * @return An array containing the blocks that s was
+ * split into.
+ */
+ private static function createBlocks( s:String ):Array {
+ var blocks:Array = new Array();
+ var len:int = s.length * 8;
+ var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
+ for( var i:int = 0; i < len; i += 8 ) {
+ blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( i % 32 );
+ }
+
+ // append padding and length
+ blocks[ len >> 5 ] |= 0x80 << ( len % 32 );
+ blocks[ ( ( ( len + 64 ) >>> 9 ) << 4 ) + 14 ] = len;
+ return blocks;
+ }
+
+ }
+}
221 src/com/adobe/crypto/SHA1.as
@@ -0,0 +1,221 @@
+/*
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.crypto {
+
+ import com.adobe.utils.IntUtil;
+
+ import flash.utils.ByteArray;
+
+ import mx.utils.Base64Encoder;
+
+ /**
+ * US Secure Hash Algorithm 1 (SHA1)
+ *
+ * Implementation based on algorithm description at
+ * http://www.faqs.org/rfcs/rfc3174.html
+ */
+ public class SHA1 {
+
+ /**
+ * Performs the SHA1 hash algorithm on a string.
+ *
+ * @param s The string to hash
+ * @return A string containing the hash value of s
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 8.5
+ * @tiptext
+ */
+ public static function hash( s:String ):String {
+ var byteArray:ByteArray = hashToByteArray(s);
+
+ return IntUtil.toHex( byteArray.readInt(), true )
+ + IntUtil.toHex( byteArray.readInt(), true )
+ + IntUtil.toHex( byteArray.readInt(), true )
+ + IntUtil.toHex( byteArray.readInt(), true )
+ + IntUtil.toHex( byteArray.readInt(), true );
+ }
+
+ /**
+ * Performs the SHA1 hash algorithm on a string, then does
+ * Base64 encoding on the result.
+ *
+ * @param s The string to hash
+ * @return The base64 encoded hash value of s
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 8.5
+ * @tiptext
+ */
+ public static function hashToBase64( s:String ):String {
+ var byteArray:ByteArray = hashToByteArray(s);
+
+ // ByteArray.toString() returns the contents as a UTF-8 string,
+ // which we can't use because certain byte sequences might trigger
+ // a UTF-8 conversion. Instead, we convert the bytes to characters
+ // one by one.
+ var charsInByteArray:String = "";
+ byteArray.position = 0;
+ for (var j:int = 0; j < byteArray.length; j++)
+ {
+ var byte:uint = byteArray.readUnsignedByte();
+ charsInByteArray += String.fromCharCode(byte);
+ }
+
+ var encoder:Base64Encoder = new Base64Encoder();
+ encoder.encode(charsInByteArray);
+ return encoder.flush();
+ }
+
+ private static function hashToByteArray( s:String ):ByteArray {
+ // initialize the h's
+ var h0:int = 0x67452301;
+ var h1:int = 0xefcdab89;
+ var h2:int = 0x98badcfe;
+ var h3:int = 0x10325476;
+ var h4:int = 0xc3d2e1f0;
+
+ // create the blocks from the string and
+ // save the length as a local var to reduce
+ // lookup in the loop below
+ var blocks:Array = createBlocks( s );
+ var len:int = blocks.length;
+
+ var w:Array = new Array( 80 );
+
+ // loop over all of the blocks
+ for ( var i:int = 0; i < len; i += 16 ) {
+
+ // 6.1.c
+ var a:int = h0;
+ var b:int = h1;
+ var c:int = h2;
+ var d:int = h3;
+ var e:int = h4;
+
+ // 80 steps to process each block
+ // TODO: unroll for faster execution, or 4 loops of
+ // 20 each to avoid the k and f function calls
+ for ( var t:int = 0; t < 80; t++ ) {
+
+ if ( t < 16 ) {
+ // 6.1.a
+ w[ t ] = blocks[ i + t ];
+ } else {
+ // 6.1.b
+ w[ t ] = IntUtil.rol( w[ t - 3 ] ^ w[ t - 8 ] ^ w[ t - 14 ] ^ w[ t - 16 ], 1 );
+ }
+
+ // 6.1.d
+ var temp:int = IntUtil.rol( a, 5 ) + f( t, b, c, d ) + e + int( w[ t ] ) + k( t );
+
+ e = d;
+ d = c;
+ c = IntUtil.rol( b, 30 );
+ b = a;
+ a = temp;
+ }
+
+ // 6.1.e
+ h0 += a;
+ h1 += b;
+ h2 += c;
+ h3 += d;
+ h4 += e;
+ }
+
+ var byteArray:ByteArray = new ByteArray();
+ byteArray.writeInt(h0);
+ byteArray.writeInt(h1);
+ byteArray.writeInt(h2);
+ byteArray.writeInt(h3);
+ byteArray.writeInt(h4);
+ byteArray.position = 0;
+ return byteArray;
+ }
+
+
+ /**
+ * Performs the logical function based on t
+ */
+ private static function f( t:int, b:int, c:int, d:int ):int {
+ if ( t < 20 ) {
+ return ( b & c ) | ( ~b & d );
+ } else if ( t < 40 ) {
+ return b ^ c ^ d;
+ } else if ( t < 60 ) {
+ return ( b & c ) | ( b & d ) | ( c & d );
+ }
+ return b ^ c ^ d;
+ }
+
+ /**
+ * Determines the constant value based on t
+ */
+ private static function k( t:int ):int {
+ if ( t < 20 ) {
+ return 0x5a827999;
+ } else if ( t < 40 ) {
+ return 0x6ed9eba1;
+ } else if ( t < 60 ) {
+ return 0x8f1bbcdc;
+ }
+ return 0xca62c1d6;
+ }
+
+ /**
+ * Converts a string to a sequence of 16-word blocks
+ * that we'll do the processing on. Appends padding
+ * and length in the process.
+ *
+ * @param s The string to split into blocks
+ * @return An array containing the blocks that s was
+ * split into.
+ */
+ private static function createBlocks( s:String ):Array {
+ var blocks:Array = new Array();
+ var len:int = s.length * 8;
+ var mask:int = 0xFF; // ignore hi byte of characters > 0xFF
+ for( var i:int = 0; i < len; i += 8 ) {
+ blocks[ i >> 5 ] |= ( s.charCodeAt( i / 8 ) & mask ) << ( 24 - i % 32 );
+ }
+
+ // append padding and length
+ blocks[ len >> 5 ] |= 0x80 << ( 24 - len % 32 );
+ blocks[ ( ( ( len + 64 ) >> 9 ) << 4 ) + 15 ] = len;
+ return blocks;
+ }
+
+ }
+}
117 src/com/adobe/crypto/WSSEUsernameToken.as
@@ -0,0 +1,117 @@
+/*
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.crypto
+{
+ import mx.formatters.DateFormatter;
+ import mx.utils.Base64Encoder;
+
+ /**
+ * Web Services Security Username Token
+ *
+ * Implementation based on algorithm description at
+ * http://www.oasis-open.org/committees/wss/documents/WSS-Username-02-0223-merged.pdf
+ */
+ public class WSSEUsernameToken
+ {
+ /**
+ * Generates a WSSE Username Token.
+ *
+ * @param username The username
+ * @param password The password
+ * @param nonce A cryptographically random nonce (if null, the nonce
+ * will be generated)
+ * @param timestamp The time at which the token is generated (if null,
+ * the time will be set to the moment of execution)
+ * @return The generated token
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 8.5
+ * @tiptext
+ */
+ public static function getUsernameToken(username:String, password:String, nonce:String=null, timestamp:Date=null):String
+ {
+ if (nonce == null)
+ {
+ nonce = generateNonce();
+ }
+ nonce = base64Encode(nonce);
+
+ var created:String = generateTimestamp(timestamp);
+
+ var password64:String = getBase64Digest(nonce,
+ created,
+ password);
+
+ var token:String = new String("UsernameToken Username=\"");
+ token += username + "\", " +
+ "PasswordDigest=\"" + password64 + "\", " +
+ "Nonce=\"" + nonce + "\", " +
+ "Created=\"" + created + "\"";
+ return token;
+ }
+
+ private static function generateNonce():String
+ {
+ // Math.random returns a Number between 0 and 1. We don't want our
+ // nonce to contain invalid characters (e.g. the period) so we
+ // strip them out before returning the result.
+ var s:String = Math.random().toString();
+ return s.replace(".", "");
+ }
+
+ private static function base64Encode(s:String):String
+ {
+ var encoder:Base64Encoder = new Base64Encoder();
+ encoder.encode(s);
+ return encoder.flush();
+ }
+
+ private static function generateTimestamp(timestamp:Date):String
+ {
+ if (timestamp == null)
+ {
+ timestamp = new Date();
+ }
+ var dateFormatter:DateFormatter = new DateFormatter();
+ dateFormatter.formatString = "YYYY-MM-DDTJJ:NN:SS"
+ return dateFormatter.format(timestamp) + "Z";
+ }
+
+ private static function getBase64Digest(nonce:String, created:String, password:String):String
+ {
+ return SHA1.hashToBase64(nonce + created + password);
+ }
+ }
+}
84 src/com/adobe/crypto/tests/MD5Test.as
@@ -0,0 +1,84 @@
+/*
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.crypto.tests {
+
+ import flexunit.framework.TestCase;
+ import flexunit.framework.TestSuite;
+
+ import com.adobe.crypto.MD5;
+
+ public class MD5Test extends TestCase {
+
+ public function MD5Test( methodName:String = null) {
+ super( methodName );
+ }
+
+ public function testEmpty():void {
+ assertMD5( "", "d41d8cd98f00b204e9800998ecf8427e" );
+ }
+
+ public function testA():void {
+ assertMD5( "a", "0cc175b9c0f1b6a831c399e269772661" );
+ }
+
+ public function testABC():void {
+ assertMD5( "abc", "900150983cd24fb0d6963f7d28e17f72" );
+ }
+
+ public function testMD():void {
+ assertMD5( "message digest", "f96b697d7cb7938d525a2f31aaf161d0" );
+ }
+
+ public function testAlphabet():void {
+ assertMD5( "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" );
+ }
+
+ public function testAlphaNumeric():void {
+ assertMD5( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f" );
+ }
+
+ public function testRepeatingNumeric():void {
+ assertMD5( "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" );
+ }
+
+ private function assertMD5( value:String, expected:String ):void {
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + MD5.hash( value ) + " ')",
+ MD5.hash( value ) == expected );
+ };
+
+ }
+
+}
117 src/com/adobe/crypto/tests/SHA1Test.as
@@ -0,0 +1,117 @@
+/*
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.crypto.tests {
+
+ import flash.utils.ByteArray;
+ import flexunit.framework.TestCase;
+ import flexunit.framework.TestSuite;
+
+ import com.adobe.crypto.SHA1;
+ import com.adobe.utils.IntUtil;
+
+ public class SHA1Test extends TestCase {
+
+ public function SHA1Test( methodName:String = null ) {
+ super( methodName );
+ }
+
+ public function testSHA1():void {
+
+ assertSHA1( "abc", "a9993e364706816aba3e25717850c26c9cd0d89d" );
+
+ assertSHA1( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "84983e441c3bd26ebaae4aa1f95129e5e54670f1" );
+
+ assertSHA1( "The quick brown fox jumps over the lazy dog",
+ "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" );
+
+ assertSHA1( "The quick brown fox jumps over the lazy cog",
+ "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" );
+
+ assertSHA1( "",
+ "da39a3ee5e6b4b0d3255bfef95601890afd80709" );
+
+ assertSHA1( "d36e316282959a9ed4c89851497a717f2003-12-15T14:43:07Ztaadtaadpstcsm",
+ "aae47f1162c0578c4b7fd66acb0e290e67d5f4e6" );
+
+ var millionAs:String = new String("");
+ for ( var i:int = 0; i < 1000000; i++ ) {
+ millionAs += "a";
+ }
+ assertSHA1( millionAs, "34aa973cd4c4daa4f61eeb2bdbad27316534016f" );
+ }
+
+ public function testSHA1Base64():void {
+ assertSHA1Base64( "abc", "qZk+NkcGgWq6PiVxeFDCbJzQ2J0=" );
+
+ assertSHA1Base64( "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "hJg+RBw70m66rkqh+VEp5eVGcPE=");
+
+ assertSHA1Base64( "The quick brown fox jumps over the lazy dog",
+ "L9ThxnotKPzthJ7hu3bnORuT6xI=" );
+
+ assertSHA1Base64( "The quick brown fox jumps over the lazy cog",
+ "3p8sf9JeGzr60+haC9F9mxANtLM=" );
+
+ assertSHA1Base64( "",
+ "2jmj7l5rSw0yVb/vlWAYkK/YBwk=" );
+
+ assertSHA1Base64( "d36e316282959a9ed4c89851497a717f2003-12-15T14:43:07Ztaadtaadpstcsm",
+ "quR/EWLAV4xLf9Zqyw4pDmfV9OY=" );
+
+ var millionAs:String = new String("");
+ for ( var i:int = 0; i < 1000000; i++ ) {
+ millionAs += "a";
+ }
+ assertSHA1Base64( millionAs, "NKqXPNTE2qT2Husr260nMWU0AW8=" );
+ }
+
+ private function assertSHA1( value:String, expected:String ):void {
+ var result:String = SHA1.hash( value );
+
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
+ result == expected );
+ }
+
+ private function assertSHA1Base64( value:String, expected:String ):void {
+ var result:String = SHA1.hashToBase64( value );
+
+ assertTrue( "Hash of '" + value + "' returned wrong value ('" + result + "')",
+ result == expected );
+ }
+
+ }
+}
74 src/com/adobe/crypto/tests/WSSEUsernameTokenTest.as
@@ -0,0 +1,74 @@
+/*
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.crypto.tests {
+
+ import com.adobe.crypto.WSSEUsernameToken;
+
+ import flexunit.framework.TestCase;
+ import flexunit.framework.TestSuite;
+
+ public class WSSEUsernameTokenTest extends TestCase {
+
+ public function WSSEUsernameTokenTest( methodName:String = null ) {
+ super( methodName );
+ }
+
+ public function testWSSEUsernameToken():void {
+
+ // Results generated from stripped-down version of Claude
+ // Montpetit's WSSE-enabled Atom API client (see
+ // http://www.montpetit.net/en/2004/06/06/11h32/index.html).
+ //
+
+ assertWSSEUsernameToken( "abc", "abc", "0123456789", new Date(Date.parse("05/09/2006 13:43:21 GMT-0700")),
+ "UsernameToken Username=\"abc\", PasswordDigest=\"3ywhFZ7z+hyAPXgBFXsN4F+443E=\", Nonce=\"MDEyMzQ1Njc4OQ==\", Created=\"2006-05-09T13:43:21Z\"" );
+
+ assertWSSEUsernameToken( "fe31_449", "168fqo4659", "1147216300992", new Date(Date.parse("05/09/2006 16:11:46 GMT-0700")),
+ "UsernameToken Username=\"fe31_449\", PasswordDigest=\"o95p2xXn26wPNqybTfKmYULWFOQ=\", Nonce=\"MTE0NzIxNjMwMDk5Mg==\", Created=\"2006-05-09T16:11:46Z\"" );
+
+ assertWSSEUsernameToken( "candy", "dandy", "2018558572", new Date(Date.parse("08/16/2006 01:48:28 GMT-0700")),
+ "UsernameToken Username=\"candy\", PasswordDigest=\"9F/nvNF47WErFaElKOO0OGhFqPI=\", Nonce=\"MjAxODU1ODU3Mg==\", Created=\"2006-08-16T01:48:28Z\"" );
+ }
+
+ private function assertWSSEUsernameToken( username:String, password:String, nonce:String,
+ timestamp:Date, expected:String ):void {
+ var result:String = WSSEUsernameToken.getUsernameToken( username, password, nonce, timestamp );
+
+ assertTrue( "WSSEUsernameToken returned wrong value ('" + result + "')",
+ result == expected );
+ }
+ }
+}
66 src/com/adobe/errors/IllegalStateError.as
@@ -0,0 +1,66 @@
+/*
+ Adobe Systems Incorporated(r) Source Code License Agreement
+ Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+ Please read this Source Code License Agreement carefully before using
+ the source code.
+
+ Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+ no-charge, royalty-free, irrevocable copyright license, to reproduce,
+ prepare derivative works of, publicly display, publicly perform, and
+ distribute this source code and such derivative works in source or
+ object code form without any attribution requirements.
+
+ The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+ derived from the source code without prior written permission.
+
+ You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+ against any loss, damage, claims or lawsuits, including attorney's
+ fees that arise or result from your use or distribution of the source
+ code.
+
+ THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+ NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+ OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.errors
+{
+ /**
+ * This class represents an Error that is thrown when a method is called when
+ * the receiving instance is in an invalid state.
+ *
+ * For example, this may occur if a method has been called, and other properties
+ * in the instance have not been initialized properly.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 8.5
+ * @tiptext
+ *
+ */
+ public class IllegalStateError extends Error
+ {
+ /**
+ * Constructor
+ *
+ * @param message A message describing the error in detail.
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 8.5
+ * @tiptext
+ */
+ public function IllegalStateError(message:String)
+ {
+ super(message);
+ }
+ }
+}
42 src/com/adobe/images/BitString.as
@@ -0,0 +1,42 @@
+/*
+ Adobe Systems Incorporated(r) Source Code License Agreement
+ Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+ Please read this Source Code License Agreement carefully before using
+ the source code.
+
+ Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+ no-charge, royalty-free, irrevocable copyright license, to reproduce,
+ prepare derivative works of, publicly display, publicly perform, and
+ distribute this source code and such derivative works in source or
+ object code form without any attribution requirements.
+
+ The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+ derived from the source code without prior written permission.
+
+ You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+ against any loss, damage, claims or lawsuits, including attorney's
+ fees that arise or result from your use or distribution of the source
+ code.
+
+ THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+ NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+ OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package com.adobe.images
+{
+ public class BitString
+ {
+ public var len:int = 0;
+ public var val:int = 0;
+ }
+}
630 src/com/adobe/images/JPGEncoder.as
@@ -0,0 +1,630 @@
+/*
+ Adobe Systems Incorporated(r) Source Code License Agreement
+ Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+ Please read this Source Code License Agreement carefully before using
+ the source code.
+
+ Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+ no-charge, royalty-free, irrevocable copyright license, to reproduce,
+ prepare derivative works of, publicly display, publicly perform, and
+ distribute this source code and such derivative works in source or
+ object code form without any attribution requirements.
+
+ The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+ derived from the source code without prior written permission.
+
+ You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+ against any loss, damage, claims or lawsuits, including attorney's
+ fees that arise or result from your use or distribution of the source
+ code.
+
+ THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+ NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+ OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package com.adobe.images
+{
+ import flash.geom.*;
+ import flash.display.*;
+ import flash.utils.*;
+
+ public class JPGEncoder
+ {
+
+ // Static table initialization
+
+ private var ZigZag:Array = [
+ 0, 1, 5, 6,14,15,27,28,
+ 2, 4, 7,13,16,26,29,42,
+ 3, 8,12,17,25,30,41,43,
+ 9,11,18,24,31,40,44,53,
+ 10,19,23,32,39,45,52,54,
+ 20,22,33,38,46,51,55,60,
+ 21,34,37,47,50,56,59,61,
+ 35,36,48,49,57,58,62,63
+ ];
+
+ private var YTable:Array = new Array(64);
+ private var UVTable:Array = new Array(64);
+ private var fdtbl_Y:Array = new Array(64);
+ private var fdtbl_UV:Array = new Array(64);
+
+ private function initQuantTables(sf:int):void
+ {
+ var i:int;
+ var t:Number;
+ var YQT:Array = [
+ 16, 11, 10, 16, 24, 40, 51, 61,
+ 12, 12, 14, 19, 26, 58, 60, 55,
+ 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62,
+ 18, 22, 37, 56, 68,109,103, 77,
+ 24, 35, 55, 64, 81,104,113, 92,
+ 49, 64, 78, 87,103,121,120,101,
+ 72, 92, 95, 98,112,100,103, 99
+ ];
+ for (i = 0; i < 64; i++) {
+ t = Math.floor((YQT[i]*sf+50)/100);
+ if (t < 1) {
+ t = 1;
+ } else if (t > 255) {
+ t = 255;
+ }
+ YTable[ZigZag[i]] = t;
+ }
+ var UVQT:Array = [
+ 17, 18, 24, 47, 99, 99, 99, 99,
+ 18, 21, 26, 66, 99, 99, 99, 99,
+ 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99
+ ];
+ for (i = 0; i < 64; i++) {
+ t = Math.floor((UVQT[i]*sf+50)/100);
+ if (t < 1) {
+ t = 1;
+ } else if (t > 255) {
+ t = 255;
+ }
+ UVTable[ZigZag[i]] = t;
+ }
+ var aasf:Array = [
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
+ 1.0, 0.785694958, 0.541196100, 0.275899379
+ ];
+ i = 0;
+ for (var row:int = 0; row < 8; row++)
+ {
+ for (var col:int = 0; col < 8; col++)
+ {
+ fdtbl_Y[i] = (1.0 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
+ fdtbl_UV[i] = (1.0 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
+ i++;
+ }
+ }
+ }
+
+ private var YDC_HT:Array;
+ private var UVDC_HT:Array;
+ private var YAC_HT:Array;
+ private var UVAC_HT:Array;
+
+ private function computeHuffmanTbl(nrcodes:Array, std_table:Array):Array
+ {
+ var codevalue:int = 0;
+ var pos_in_table:int = 0;
+ var HT:Array = new Array();
+ for (var k:int=1; k<=16; k++) {
+ for (var j:int=1; j<=nrcodes[k]; j++) {
+ HT[std_table[pos_in_table]] = new BitString();
+ HT[std_table[pos_in_table]].val = codevalue;
+ HT[std_table[pos_in_table]].len = k;
+ pos_in_table++;
+ codevalue++;
+ }
+ codevalue*=2;
+ }
+ return HT;
+ }
+
+ private var std_dc_luminance_nrcodes:Array = [0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0];
+ private var std_dc_luminance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
+ private var std_ac_luminance_nrcodes:Array = [0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d];
+ private var std_ac_luminance_values:Array = [
+ 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
+ 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
+ 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
+ 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
+ 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
+ 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
+ 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
+ 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
+ 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
+ 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
+ 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
+ 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
+ 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
+ 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
+ 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
+ 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
+ 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
+ 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
+ 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
+ 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa
+ ];
+
+ private var std_dc_chrominance_nrcodes:Array = [0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0];
+ private var std_dc_chrominance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
+ private var std_ac_chrominance_nrcodes:Array = [0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77];
+ private var std_ac_chrominance_values:Array = [
+ 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
+ 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
+ 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
+ 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
+ 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
+ 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
+ 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
+ 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
+ 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
+ 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
+ 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
+ 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
+ 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
+ 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
+ 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
+ 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
+ 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
+ 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
+ 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
+ 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa
+ ];
+
+ private function initHuffmanTbl():void
+ {
+ YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
+ UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
+ YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
+ UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
+ }
+
+ private var bitcode:Array = new Array(65535);
+ private var category:Array = new Array(65535);
+
+ private function initCategoryNumber():void
+ {
+ var nrlower:int = 1;
+ var nrupper:int = 2;
+ var nr:int;
+ for (var cat:int=1; cat<=15; cat++) {
+ //Positive numbers
+ for (nr=nrlower; nr<nrupper; nr++) {
+ category[32767+nr] = cat;
+ bitcode[32767+nr] = new BitString();
+ bitcode[32767+nr].len = cat;
+ bitcode[32767+nr].val = nr;
+ }
+ //Negative numbers
+ for (nr=-(nrupper-1); nr<=-nrlower; nr++) {
+ category[32767+nr] = cat;
+ bitcode[32767+nr] = new BitString();
+ bitcode[32767+nr].len = cat;
+ bitcode[32767+nr].val = nrupper-1+nr;
+ }
+ nrlower <<= 1;
+ nrupper <<= 1;
+ }
+ }
+
+ // IO functions
+
+ private var byteout:ByteArray;
+ private var bytenew:int = 0;
+ private var bytepos:int = 7;
+
+ private function writeBits(bs:BitString):void
+ {
+ var value:int = bs.val;
+ var posval:int = bs.len-1;
+ while ( posval >= 0 ) {
+ if (value & uint(1 << posval) ) {
+ bytenew |= uint(1 << bytepos);
+ }
+ posval--;
+ bytepos--;
+ if (bytepos < 0) {
+ if (bytenew == 0xFF) {
+ writeByte(0xFF);
+ writeByte(0);
+ }
+ else {
+ writeByte(bytenew);
+ }
+ bytepos=7;
+ bytenew=0;
+ }
+ }
+ }
+
+ private function writeByte(value:int):void
+ {
+ byteout.writeByte(value);
+ }
+
+ private function writeWord(value:int):void
+ {
+ writeByte((value>>8)&0xFF);
+ writeByte((value )&0xFF);
+ }
+
+ // DCT & quantization core
+
+ private function fDCTQuant(data:Array, fdtbl:Array):Array
+ {
+ var tmp0:Number, tmp1:Number, tmp2:Number, tmp3:Number, tmp4:Number, tmp5:Number, tmp6:Number, tmp7:Number;
+ var tmp10:Number, tmp11:Number, tmp12:Number, tmp13:Number;
+ var z1:Number, z2:Number, z3:Number, z4:Number, z5:Number, z11:Number, z13:Number;
+ var i:int;
+ /* Pass 1: process rows. */
+ var dataOff:int=0;
+ for (i=0; i<8; i++) {
+ tmp0 = data[dataOff+0] + data[dataOff+7];
+ tmp7 = data[dataOff+0] - data[dataOff+7];
+ tmp1 = data[dataOff+1] + data[dataOff+6];
+ tmp6 = data[dataOff+1] - data[dataOff+6];
+ tmp2 = data[dataOff+2] + data[dataOff+5];
+ tmp5 = data[dataOff+2] - data[dataOff+5];
+ tmp3 = data[dataOff+3] + data[dataOff+4];
+ tmp4 = data[dataOff+3] - data[dataOff+4];
+
+ /* Even part */
+ tmp10 = tmp0 + tmp3; /* phase 2 */
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ data[dataOff+0] = tmp10 + tmp11; /* phase 3 */
+ data[dataOff+4] = tmp10 - tmp11;
+
+ z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
+ data[dataOff+2] = tmp13 + z1; /* phase 5 */
+ data[dataOff+6] = tmp13 - z1;
+
+ /* Odd part */
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
+ z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
+ z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
+ z3 = tmp11 * 0.707106781; /* c4 */
+
+ z11 = tmp7 + z3; /* phase 5 */
+ z13 = tmp7 - z3;
+
+ data[dataOff+5] = z13 + z2; /* phase 6 */
+ data[dataOff+3] = z13 - z2;
+ data[dataOff+1] = z11 + z4;
+ data[dataOff+7] = z11 - z4;
+
+ dataOff += 8; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns. */
+ dataOff = 0;
+ for (i=0; i<8; i++) {
+ tmp0 = data[dataOff+ 0] + data[dataOff+56];
+ tmp7 = data[dataOff+ 0] - data[dataOff+56];
+ tmp1 = data[dataOff+ 8] + data[dataOff+48];
+ tmp6 = data[dataOff+ 8] - data[dataOff+48];
+ tmp2 = data[dataOff+16] + data[dataOff+40];
+ tmp5 = data[dataOff+16] - data[dataOff+40];
+ tmp3 = data[dataOff+24] + data[dataOff+32];
+ tmp4 = data[dataOff+24] - data[dataOff+32];
+
+ /* Even part */
+ tmp10 = tmp0 + tmp3; /* phase 2 */
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ data[dataOff+ 0] = tmp10 + tmp11; /* phase 3 */
+ data[dataOff+32] = tmp10 - tmp11;
+
+ z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
+ data[dataOff+16] = tmp13 + z1; /* phase 5 */
+ data[dataOff+48] = tmp13 - z1;
+
+ /* Odd part */
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
+ z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
+ z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
+ z3 = tmp11 * 0.707106781; /* c4 */
+
+ z11 = tmp7 + z3; /* phase 5 */
+ z13 = tmp7 - z3;
+
+ data[dataOff+40] = z13 + z2; /* phase 6 */
+ data[dataOff+24] = z13 - z2;
+ data[dataOff+ 8] = z11 + z4;
+ data[dataOff+56] = z11 - z4;
+
+ dataOff++; /* advance pointer to next column */
+ }
+
+ // Quantize/descale the coefficients
+ for (i=0; i<64; i++) {
+ // Apply the quantization and scaling factor & Round to nearest integer
+ data[i] = Math.round((data[i]*fdtbl[i]));
+ }
+ return data;
+ }
+
+ // Chunk writing
+
+ private function writeAPP0():void
+ {
+ writeWord(0xFFE0); // marker
+ writeWord(16); // length
+ writeByte(0x4A); // J
+ writeByte(0x46); // F
+ writeByte(0x49); // I
+ writeByte(0x46); // F
+ writeByte(0); // = "JFIF",'\0'
+ writeByte(1); // versionhi
+ writeByte(1); // versionlo
+ writeByte(0); // xyunits
+ writeWord(1); // xdensity
+ writeWord(1); // ydensity
+ writeByte(0); // thumbnwidth
+ writeByte(0); // thumbnheight
+ }
+
+ private function writeSOF0(width:int, height:int):void
+ {
+ writeWord(0xFFC0); // marker
+ writeWord(17); // length, truecolor YUV JPG
+ writeByte(8); // precision
+ writeWord(height);
+ writeWord(width);
+ writeByte(3); // nrofcomponents
+ writeByte(1); // IdY
+ writeByte(0x11); // HVY
+ writeByte(0); // QTY
+ writeByte(2); // IdU
+ writeByte(0x11); // HVU
+ writeByte(1); // QTU
+ writeByte(3); // IdV
+ writeByte(0x11); // HVV
+ writeByte(1); // QTV
+ }
+
+ private function writeDQT():void
+ {
+ writeWord(0xFFDB); // marker
+ writeWord(132); // length
+ writeByte(0);
+ var i:int;
+ for (i=0; i<64; i++) {
+ writeByte(YTable[i]);
+ }
+ writeByte(1);
+ for (i=0; i<64; i++) {
+ writeByte(UVTable[i]);
+ }
+ }
+
+ private function writeDHT():void
+ {
+ writeWord(0xFFC4); // marker
+ writeWord(0x01A2); // length
+ var i:int;
+
+ writeByte(0); // HTYDCinfo
+ for (i=0; i<16; i++) {
+ writeByte(std_dc_luminance_nrcodes[i+1]);
+ }
+ for (i=0; i<=11; i++) {
+ writeByte(std_dc_luminance_values[i]);
+ }
+
+ writeByte(0x10); // HTYACinfo
+ for (i=0; i<16; i++) {
+ writeByte(std_ac_luminance_nrcodes[i+1]);
+ }
+ for (i=0; i<=161; i++) {
+ writeByte(std_ac_luminance_values[i]);
+ }
+
+ writeByte(1); // HTUDCinfo
+ for (i=0; i<16; i++) {
+ writeByte(std_dc_chrominance_nrcodes[i+1]);
+ }
+ for (i=0; i<=11; i++) {
+ writeByte(std_dc_chrominance_values[i]);
+ }
+
+ writeByte(0x11); // HTUACinfo
+ for (i=0; i<16; i++) {
+ writeByte(std_ac_chrominance_nrcodes[i+1]);
+ }
+ for (i=0; i<=161; i++) {
+ writeByte(std_ac_chrominance_values[i]);
+ }
+ }
+
+ private function writeSOS():void
+ {
+ writeWord(0xFFDA); // marker
+ writeWord(12); // length
+ writeByte(3); // nrofcomponents
+ writeByte(1); // IdY
+ writeByte(0); // HTY
+ writeByte(2); // IdU
+ writeByte(0x11); // HTU
+ writeByte(3); // IdV
+ writeByte(0x11); // HTV
+ writeByte(0); // Ss
+ writeByte(0x3f); // Se
+ writeByte(0); // Bf
+ }
+
+ // Core processing
+ private var DU:Array = new Array(64);
+
+ private function processDU(CDU:Array, fdtbl:Array, DC:Number, HTDC:Array, HTAC:Array):Number
+ {
+ var EOB:BitString = HTAC[0x00];
+ var M16zeroes:BitString = HTAC[0xF0];
+ var i:int;
+
+ var DU_DCT:Array = fDCTQuant(CDU, fdtbl);
+ //ZigZag reorder
+ for (i=0;i<64;i++) {
+ DU[ZigZag[i]]=DU_DCT[i];
+ }
+ var Diff:int = DU[0] - DC; DC = DU[0];
+ //Encode DC
+ if (Diff==0) {
+ writeBits(HTDC[0]); // Diff might be 0
+ } else {
+ writeBits(HTDC[category[32767+Diff]]);
+ writeBits(bitcode[32767+Diff]);
+ }
+ //Encode ACs
+ var end0pos:int = 63;
+ for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {
+ };
+ //end0pos = first element in reverse order !=0
+ if ( end0pos == 0) {
+ writeBits(EOB);
+ return DC;
+ }
+ i = 1;
+ while ( i <= end0pos ) {
+ var startpos:int = i;
+ for (; (DU[i]==0) && (i<=end0pos); i++) {
+ }
+ var nrzeroes:int = i-startpos;
+ if ( nrzeroes >= 16 ) {
+ for (var nrmarker:int=1; nrmarker <= nrzeroes/16; nrmarker++) {
+ writeBits(M16zeroes);
+ }
+ nrzeroes = int(nrzeroes&0xF);
+ }
+ writeBits(HTAC[nrzeroes*16+category[32767+DU[i]]]);
+ writeBits(bitcode[32767+DU[i]]);
+ i++;
+ }
+ if ( end0pos != 63 ) {
+ writeBits(EOB);
+ }
+ return DC;
+ }
+
+ private var YDU:Array = new Array(64);
+ private var UDU:Array = new Array(64);
+ private var VDU:Array = new Array(64);
+
+ private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void
+ {
+ var pos:int=0;
+ for (var y:int=0; y<8; y++) {
+ for (var x:int=0; x<8; x++) {
+ var P:uint = img.getPixel32(xpos+x,ypos+y);
+ var R:Number = Number((P>>16)&0xFF);
+ var G:Number = Number((P>> 8)&0xFF);
+ var B:Number = Number((P )&0xFF);
+ YDU[pos]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-128;
+ UDU[pos]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B));
+ VDU[pos]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B));
+ pos++;
+ }
+ }
+ }
+
+ public function JPGEncoder(quality:Number = 50)
+ {
+ if (quality <= 0) {
+ quality = 1;
+ }
+ if (quality > 100) {
+ quality = 100;
+ }
+ var sf:int = 0;
+ if (quality < 50) {
+ sf = int(5000 / quality);
+ } else {
+ sf = int(200 - quality*2);
+ }
+ // Create tables
+ initHuffmanTbl();
+ initCategoryNumber();
+ initQuantTables(sf);
+ }
+
+ public function encode(image:BitmapData):ByteArray
+ {
+ // Initialize bit writer
+ byteout = new ByteArray();
+ bytenew=0;
+ bytepos=7;
+
+ // Add JPEG headers
+ writeWord(0xFFD8); // SOI
+ writeAPP0();
+ writeDQT();
+ writeSOF0(image.width,image.height);
+ writeDHT();
+ writeSOS();
+
+
+ // Encode 8x8 macroblocks
+ var DCY:Number=0;
+ var DCU:Number=0;
+ var DCV:Number=0;
+ bytenew=0;
+ bytepos=7;
+ for (var ypos:int=0; ypos<image.height; ypos+=8) {
+ for (var xpos:int=0; xpos<image.width; xpos+=8) {
+ RGB2YUV(image, xpos, ypos);
+ DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
+ DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
+ DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
+ }
+ }
+
+ // Do the bit alignment of the EOI marker
+ if ( bytepos >= 0 ) {
+ var fillbits:BitString = new BitString();
+ fillbits.len = bytepos+1;
+ fillbits.val = (1<<(bytepos+1))-1;
+ writeBits(fillbits);
+ }
+
+ writeWord(0xFFD9); //EOI
+ return byteout;
+ }
+ }
+}
132 src/com/adobe/images/PNGEncoder.as
@@ -0,0 +1,132 @@
+/*
+ Adobe Systems Incorporated(r) Source Code License Agreement
+ Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+ Please read this Source Code License Agreement carefully before using
+ the source code.
+
+ Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+ no-charge, royalty-free, irrevocable copyright license, to reproduce,
+ prepare derivative works of, publicly display, publicly perform, and
+ distribute this source code and such derivative works in source or
+ object code form without any attribution requirements.
+
+ The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+ derived from the source code without prior written permission.
+
+ You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+ against any loss, damage, claims or lawsuits, including attorney's
+ fees that arise or result from your use or distribution of the source
+ code.
+
+ THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+ NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+ OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package com.adobe.images
+{
+ import flash.geom.*;
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
+ import flash.utils.ByteArray;
+
+ public class PNGEncoder
+ {
+ public static function encode(img:BitmapData):ByteArray {
+ // Create output byte array
+ var png:ByteArray = new ByteArray();
+ // Write PNG signature
+ png.writeUnsignedInt(0x89504e47);
+ png.writeUnsignedInt(0x0D0A1A0A);
+ // Build IHDR chunk
+ var IHDR:ByteArray = new ByteArray();
+ IHDR.writeInt(img.width);
+ IHDR.writeInt(img.height);
+ IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA
+ IHDR.writeByte(0);
+ writeChunk(png,0x49484452,IHDR);
+ // Build IDAT chunk
+ var IDAT:ByteArray= new ByteArray();
+ for(var i:int=0;i < img.height;i++) {
+ // no filter
+ IDAT.writeByte(0);
+ var p:uint;
+ var j:int;
+ if ( !img.transparent ) {
+ for(j=0;j < img.width;j++) {
+ p = img.getPixel(j,i);
+ IDAT.writeUnsignedInt(
+ uint(((p&0xFFFFFF) << 8)|0xFF));
+ }
+ } else {
+ for(j=0;j < img.width;j++) {
+ p = img.getPixel32(j,i);
+ IDAT.writeUnsignedInt(
+ uint(((p&0xFFFFFF) << 8)|
+ (p>>>24)));
+ }
+ }
+ }
+ IDAT.compress();
+ writeChunk(png,0x49444154,IDAT);
+ // Build IEND chunk
+ writeChunk(png,0x49454E44,null);
+ // return PNG
+ return png;
+ }
+
+ private static var crcTable:Array;
+ private static var crcTableComputed:Boolean = false;
+
+ private static function writeChunk(png:ByteArray,
+ type:uint, data:ByteArray):void {
+ if (!crcTableComputed) {
+ crcTableComputed = true;
+ crcTable = [];
+ var c:uint;
+ for (var n:uint = 0; n < 256; n++) {
+ c = n;
+ for (var k:uint = 0; k < 8; k++) {
+ if (c & 1) {
+ c = uint(uint(0xedb88320) ^
+ uint(c >>> 1));
+ } else {
+ c = uint(c >>> 1);
+ }
+ }
+ crcTable[n] = c;
+ }
+ }
+ var len:uint = 0;
+ if (data != null) {
+ len = data.length;
+ }
+ png.writeUnsignedInt(len);
+ var p:uint = png.position;
+ png.writeUnsignedInt(type);
+ if ( data != null ) {
+ png.writeBytes(data);
+ }
+ var e:uint = png.position;
+ png.position = p;
+ c = 0xffffffff;
+ for (var i:int = 0; i < (e-p); i++) {
+ c = uint(crcTable[
+ (c ^ png.readUnsignedByte()) &
+ uint(0xff)] ^ uint(c >>> 8));
+ }
+ c = uint(c^uint(0xffffffff));
+ png.position = e;
+ png.writeUnsignedInt(c);
+ }
+ }
+}
58 src/com/adobe/net/DynamicURLLoader.as
@@ -0,0 +1,58 @@
+/*
+ Adobe Systems Incorporated(r) Source Code License Agreement
+ Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+ Please read this Source Code License Agreement carefully before using
+ the source code.
+
+ Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+ no-charge, royalty-free, irrevocable copyright license, to reproduce,
+ prepare derivative works of, publicly display, publicly perform, and
+ distribute this source code and such derivative works in source or
+ object code form without any attribution requirements.
+
+ The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+ derived from the source code without prior written permission.
+
+ You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+ against any loss, damage, claims or lawsuits, including attorney's
+ fees that arise or result from your use or distribution of the source
+ code.
+
+ THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+ NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+ OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.net
+{
+ import flash.net.URLLoader;
+
+ /**
+ * Class that provides a dynamic implimentation of the URLLoader class.
+ *
+ * This class provides no API implimentations. However, since the class is
+ * declared as dynamic, it can be used in place of URLLoader, and allow
+ * you to dynamically attach properties to it (which URLLoader does not allow).
+ *
+ * @langversion ActionScript 3.0
+ * @playerversion Flash 8.5
+ * @tiptext
+ */
+ public dynamic class DynamicURLLoader extends URLLoader
+ {
+ public function DynamicURLLoader()
+ {
+ super();
+ }
+ }
+}
73 src/com/adobe/net/IURIResolver.as
@@ -0,0 +1,73 @@
+/*
+ Adobe Systems Incorporated(r) Source Code License Agreement
+ Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+ Please read this Source Code License Agreement carefully before using
+ the source code.
+
+ Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+ no-charge, royalty-free, irrevocable copyright license, to reproduce,
+ prepare derivative works of, publicly display, publicly perform, and
+ distribute this source code and such derivative works in source or
+ object code form without any attribution requirements.
+
+ The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+ derived from the source code without prior written permission.
+
+ You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+ against any loss, damage, claims or lawsuits, including attorney's
+ fees that arise or result from your use or distribution of the source
+ code.
+
+ THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+ NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+ OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.net
+{
+ /**
+ * The URI class cannot know about DNS aliases, virtual hosts, or
+ * symbolic links that may be involved. The application can provide
+ * an implementation of this interface to resolve the URI before the
+ * URI class makes any comparisons. For example, a web host has
+ * two aliases:
+ *
+ * <p><code>
+ * http://www.site.com/
+ * http://www.site.net/
+ * </code></p>
+ *
+ * <p>The application can provide an implementation that automatically
+ * resolves site.net to site.com before URI compares two URI objects.
+ * Only the application can know and understand the context in which
+ * the URI's are being used.</p>
+ *
+ * <p>Use the URI.resolver accessor to assign a custom resolver to
+ * the URI class. Any resolver specified is global to all instances
+ * of URI.</p>
+ *
+ * <p>URI will call this before performing URI comparisons in the
+ * URI.getRelation() and URI.getCommonParent() functions.
+ *
+ * @see URI.getRelation
+ * @see URI.getCommonParent
+ */
+ public interface IURIResolver
+ {
+ /**
+ * Implement this method to provide custom URI resolution for
+ * your application.
+ */
+ function resolve(uri:URI) : URI;
+ }
+}
2,466 src/com/adobe/net/URI.as
@@ -0,0 +1,2466 @@
+/*
+Adobe Systems Incorporated(r) Source Code License Agreement
+Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
+
+Please read this Source Code License Agreement carefully before using
+the source code.
+
+Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable copyright license, to reproduce,
+prepare derivative works of, publicly display, publicly perform, and
+distribute this source code and such derivative works in source or
+object code form without any attribution requirements.
+
+The name "Adobe Systems Incorporated" must not be used to endorse or promote products
+derived from the source code without prior written permission.
+
+You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
+against any loss, damage, claims or lawsuits, including attorney's
+fees that arise or result from your use or distribution of the source
+code.
+
+THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
+ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
+NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
+OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.net
+{
+ import flash.utils.ByteArray;
+
+ /**
+ * This class implements functions and utilities for working with URI's
+ * (Universal Resource Identifiers). For technical description of the
+ * URI syntax, please see RFC 3986 at http://www.ietf.org/rfc/rfc3986.txt
+ * or do a web search for "rfc 3986".
+ *
+ * <p>The most important aspect of URI's to understand is that URI's
+ * and URL's are not strings. URI's are complex data structures that
+ * encapsulate many pieces of information. The string version of a
+ * URI is the serialized representation of that data structure. This
+ * string serialization is used to provide a human readable
+ * representation and a means to transport the data over the network
+ * where it can then be parsed back into its' component parts.</p>
+ *
+ * <p>URI's fall into one of three categories:
+ * <ul>
+ * <li>&lt;scheme&gt;:&lt;scheme-specific-part&gt;#&lt;fragment&gt; (non-hierarchical)</li>
+ * <li>&lt;scheme&gt;:<authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt; (hierarchical)</li>
+ * <li>&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt; (relative hierarchical)</li>
+ * </ul></p>
+ *
+ * <p>The query and fragment parts are optional.</p>
+ *
+ * <p>This class supports both non-hierarchical and hierarchical URI's</p>
+ *
+ * <p>This class is intended to be used "as-is" for the vast majority
+ * of common URI's. However, if your application requires a custom
+ * URI syntax (e.g. custom query syntax or special handling of
+ * non-hierarchical URI's), this class can be fully subclassed. If you
+ * intended to subclass URI, please see the source code for complete
+ * documation on protected members and protected fuctions.</p>
+ */
+ public class URI
+ {
+ // Here we define which characters must be escaped for each
+ // URI part. The characters that must be escaped for each
+ // part differ depending on what would cause ambiguous parsing.
+ // RFC 3986 sec. 2.4 states that characters should only be
+ // encoded when they would conflict with subcomponent delimiters.
+ // We don't want to over-do the escaping. We only want to escape
+ // the minimum needed to prevent parsing problems.
+
+ // space and % must be escaped in all cases. '%' is the delimiter
+ // for escaped characters.
+ public static const URImustEscape:String = " %";
+
+ // Baseline of what characters must be escaped
+ public static const URIbaselineEscape:String = URImustEscape + ":?#/@";
+
+ // Characters that must be escaped in the part part.
+ public static const URIpathEscape:String = URImustEscape + "?#";
+
+ // Characters that must be escaped in the query part, if setting
+ // the query as a whole string. If the query is set by
+ // name/value, URIqueryPartEscape is used instead.
+ public static const URIqueryEscape:String = URImustEscape + "#";
+
+ // This is what each name/value pair must escape "&=" as well
+ // so they don't conflict with the "param=value&param2=value2"
+ // syntax.
+ public static const URIqueryPartEscape:String = URImustEscape + "#&=";
+
+ // Non-hierarchical URI's can have query and fragment parts, but
+ // we also want to prevent '/' otherwise it might end up looking
+ // like a hierarchical URI to the parser.
+ public static const URInonHierEscape:String = URImustEscape + "?#/";
+
+ // Baseline uninitialized setting for the URI scheme.
+ public static const UNKNOWN_SCHEME:String = "unknown";
+
+ // The following bitmaps are used for performance enhanced
+ // character escaping.
+
+ // Baseline characters that need to be escaped. Many parts use
+ // this.
+ protected static const URIbaselineExcludedBitmap:URIEncodingBitmap =
+ new URIEncodingBitmap(URIbaselineEscape);
+
+ // Scheme escaping bitmap
+ protected static const URIschemeExcludedBitmap:URIEncodingBitmap =
+ URIbaselineExcludedBitmap;
+
+ // User/pass escaping bitmap
+ protected static const URIuserpassExcludedBitmap:URIEncodingBitmap =
+ URIbaselineExcludedBitmap;
+
+ // Authority escaping bitmap
+ protected static const URIauthorityExcludedBitmap:URIEncodingBitmap =
+ URIbaselineExcludedBitmap;
+
+ // Port escaping bitmap
+ protected static const URIportExludedBitmap:URIEncodingBitmap =
+ URIbaselineExcludedBitmap;
+
+ // Path escaping bitmap
+ protected static const URIpathExcludedBitmap:URIEncodingBitmap =
+ new URIEncodingBitmap(URIpathEscape);
+
+ // Query (whole) escaping bitmap
+ protected static const URIqueryExcludedBitmap:URIEncodingBitmap =
+ new URIEncodingBitmap(URIqueryEscape);
+
+ // Query (individual parts) escaping bitmap
+ protected static const URIqueryPartExcludedBitmap:URIEncodingBitmap =
+ new URIEncodingBitmap(URIqueryPartEscape);
+
+ // Fragments are the last part in the URI. They only need to
+ // escape space, '#', and '%'. Turns out that is what query
+ // uses too.
+ protected static const URIfragmentExcludedBitmap:URIEncodingBitmap =
+ URIqueryExcludedBitmap;
+
+ // Characters that need to be escaped in the non-hierarchical part
+ protected static const URInonHierexcludedBitmap:URIEncodingBitmap =
+ new URIEncodingBitmap(URInonHierEscape);
+
+ // Values used by getRelation()
+ public static const NOT_RELATED:int = 0;
+ public static const CHILD:int = 1;
+ public static const EQUAL:int = 2;
+ public static const PARENT:int = 3;
+
+ //-------------------------------------------------------------------
+ // protected class members
+ //-------------------------------------------------------------------
+ protected var _valid:Boolean = false;
+ protected var _relative:Boolean = false;
+ protected var _scheme:String = "";
+ protected var _authority:String = "";
+ protected var _username:String = "";
+ protected var _password:String = "";
+ protected var _port:String = "";
+ protected var _path:String = "";
+ protected var _query:String = "";
+ protected var _fragment:String = "";
+ protected var _nonHierarchical:String = "";
+ protected static var _resolver:IURIResolver = null;
+
+
+ /**
+ * URI Constructor. If no string is given, this will initialize
+ * this URI object to a blank URI.
+ */
+ public function URI(uri:String = null)