PageRenderTime 23ms CodeModel.GetById 11ms 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/symmetric/SSLPad.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 44 lines | 30 code | 4 blank | 10 comment | 3 complexity | 5ab5ee99b9306361a29b6a6b4dded3a7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * TLSPad
  3. *
  4. * A padding implementation used by TLS
  5. * Copyright (c) 2007 Henri Torgemane
  6. *
  7. * See LICENSE.txt for full license information.
  8. */
  9. package com.hurlant.crypto.symmetric {
  10. import flash.utils.ByteArray;
  11. import com.hurlant.util.Hex;
  12. import com.hurlant.crypto.tls.TLSError;
  13. public class SSLPad implements IPad {
  14. private var blockSize:uint;
  15. public function SSLPad(blockSize:uint=0) {
  16. this.blockSize = blockSize;
  17. }
  18. public function pad(a:ByteArray):void {
  19. var c:uint = blockSize - (a.length+1)%blockSize;
  20. for (var i:uint=0;i<=c;i++) {
  21. a[a.length] = c;
  22. }
  23. }
  24. public function unpad(a:ByteArray):void {
  25. var c:uint = a.length%blockSize;
  26. if (c!=0) throw new TLSError("SSLPad::unpad: ByteArray.length isn't a multiple of the blockSize", TLSError.bad_record_mac);
  27. c = a[a.length-1];
  28. for (var i:uint=c;i>0;i--) {
  29. var v:uint = a[a.length-1];
  30. a.length--;
  31. // But LOOK! SSL 3.0 doesn't care about this, bytes are arbitrary!
  32. // if (c!=v) throw new TLSError("SSLPad:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]", TLSError.bad_record_mac);
  33. }
  34. a.length--;
  35. }
  36. public function setBlockSize(bs:uint):void {
  37. blockSize = bs;
  38. }
  39. }
  40. }