PageRenderTime 158ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 4ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 71 lines | 52 code | 8 blank | 11 comment | 3 complexity | 0ebfb489fe55ae16f91a6ee69fb5b005 MD5 | raw file
 1/**
 2 * SHABase
 3 * 
 4 * An ActionScript 3 abstract class for the SHA family of hash functions
 5 * Copyright (c) 2007 Henri Torgemane
 6 * 
 7 * See LICENSE.txt for full license information.
 8 */
 9package com.hurlant.crypto.hash
10{
11	import flash.utils.ByteArray;
12	import flash.utils.Endian;
13
14	public class SHABase implements IHash
15	{
16
17        public function SHABase() { }
18
19		public var pad_size:int = 40;
20		public function getInputSize():uint
21		{
22			return 64;
23		}
24		
25		public function getHashSize():uint
26		{
27			return 0;
28		}
29		
30		public function getPadSize():int 
31		{
32			return pad_size;
33		}
34		
35		public function hash(src:ByteArray):ByteArray
36		{
37			var savedLength:uint = src.length;
38			var savedEndian:String = src.endian;
39			
40			src.endian = Endian.BIG_ENDIAN;
41			var len:uint = savedLength *8;
42			// pad to nearest int.
43			while (src.length%4!=0) {
44				src[src.length]=0;
45			}
46			// convert ByteArray to an array of uint
47			src.position=0;
48			var a:Array = [];
49			for (var i:uint=0;i<src.length;i+=4) {
50				a.push(src.readUnsignedInt());
51			}
52			var h:Array = core(a, len);
53			var out:ByteArray = new ByteArray;
54			var words:uint = getHashSize()/4;
55			for (i=0;i<words;i++) {
56				out.writeUnsignedInt(h[i]);
57			}
58			// unpad, to leave the source untouched.
59			src.length = savedLength;
60			src.endian = savedEndian;
61			return out;
62		}
63		protected function core(x:Array, len:uint):Array {
64			return null;
65		}
66		
67		public function toString():String {
68			return "sha";
69		}
70	}
71}