PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 58 lines | 41 code | 5 blank | 12 comment | 2 complexity | 1b375085723ec6f38e4f78051c397753 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * MD5Test
  3. *
  4. * A test class for MD5
  5. * Copyright (c) 2007 Henri Torgemane
  6. *
  7. * See LICENSE.txt for full license information.
  8. */
  9. package com.hurlant.crypto.tests
  10. {
  11. import com.hurlant.crypto.hash.MD5;
  12. import com.hurlant.util.Hex;
  13. import flash.utils.ByteArray;
  14. public class MD5Test extends TestCase
  15. {
  16. public function MD5Test(h:ITestHarness)
  17. {
  18. super(h, "MD5 Test");
  19. runTest(testMd5,"MD5 Test Vectors");
  20. h.endTestCase();
  21. }
  22. /**
  23. * Test Vectors grabbed from
  24. * http://www.faqs.org/rfcs/rfc1321.html
  25. */
  26. public function testMd5():void {
  27. var srcs:Array = [
  28. "",
  29. Hex.fromString("a"),
  30. Hex.fromString("abc"),
  31. Hex.fromString("message digest"),
  32. Hex.fromString("abcdefghijklmnopqrstuvwxyz"),
  33. Hex.fromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
  34. Hex.fromString("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
  35. ];
  36. var hashes:Array = [
  37. "d41d8cd98f00b204e9800998ecf8427e",
  38. "0cc175b9c0f1b6a831c399e269772661",
  39. "900150983cd24fb0d6963f7d28e17f72",
  40. "f96b697d7cb7938d525a2f31aaf161d0",
  41. "c3fcd3d76192e4007dfb496cca67e13b",
  42. "d174ab98d277d9f5a5611c2c9f419d9f",
  43. "57edf4a22be3c955ac49da2e2107b67a"
  44. ];
  45. var md5:MD5 = new MD5;
  46. for (var i:uint=0;i<srcs.length;i++) {
  47. var src:ByteArray = Hex.toArray(srcs[i]);
  48. var digest:ByteArray = md5.hash(src);
  49. assert("MD5 Test "+i, Hex.fromArray(digest) == hashes[i]);
  50. }
  51. }
  52. }
  53. }