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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs · ActionScript · 42 lines · 31 code · 2 blank · 9 comment · 4 complexity · 4ebb39986b8610a52eab5feff4cac3cf MD5 · raw file

  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 TLSPad implements IPad {
  14. private var blockSize:uint;
  15. public function TLSPad(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("TLSPad::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. if (c!=v) throw new TLSError("TLSPad:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]", TLSError.bad_record_mac);
  32. }
  33. a.length--;
  34. // mostly ripped off from PKCS5.as, but with subtle differences
  35. }
  36. public function setBlockSize(bs:uint):void {
  37. blockSize = bs;
  38. }
  39. }
  40. }