PageRenderTime 244ms CodeModel.GetById 120ms app.highlight 5ms RepoModel.GetById 116ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 58 lines | 40 code | 4 blank | 14 comment | 4 complexity | 54c9ff4e7cde2a6a05d588f30dd58dab MD5 | raw file
 1/**
 2 * SHA224Test
 3 * 
 4 * A test class for SHA224
 5 * Copyright (c) 2007 Henri Torgemane
 6 * 
 7 * See LICENSE.txt for full license information.
 8 */
 9package com.hurlant.crypto.tests
10{
11	import com.hurlant.crypto.hash.SHA224;
12	import com.hurlant.util.Hex;
13	
14	import flash.utils.ByteArray;
15	
16	public class SHA224Test extends TestCase
17	{
18		public function SHA224Test(h:ITestHarness)
19		{
20			super(h,"SHA-224 Test");
21			runTest(testSha224,"SHA-224 Test Vectors");
22			// takes a few seconds, but uncomment if you must.
23			//runTest(testLongSha224,"SHA-224 Long Test Vectors");
24			h.endTestCase();
25		}
26		
27		/**
28		 * Test vectors courtesy of
29		 * http://www.ietf.org/rfc/rfc3874.txt
30		 */
31		public function testSha224():void {
32			var srcs:Array = [
33			Hex.fromString("abc"),
34			Hex.fromString("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")];
35			var hashes:Array = [
36			"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7",
37			"75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525"];
38			
39			var sha224:SHA224 = new SHA224;
40			for (var i:uint=0;i<srcs.length;i++) {
41				var src:ByteArray = Hex.toArray(srcs[i]);
42				var digest:ByteArray = sha224.hash(src);
43				assert("SHA224 Test "+i, Hex.fromArray(digest) == hashes[i]);
44			}
45		}
46		public function testLongSha224():void {
47			var src:ByteArray = new ByteArray;
48			var a:uint = "a".charCodeAt(0);
49			for (var i:uint=0;i<1e6;i++) {
50				src[i] = a;
51			}
52			var sha224:SHA224 = new SHA224;
53			var digest:ByteArray = sha224.hash(src);
54			var hash:String = "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67";
55			assert("SHA224 Long Test", Hex.fromArray(digest) == hash);
56		}
57	}
58}