/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as
ActionScript | 44 lines | 30 code | 4 blank | 10 comment | 3 complexity | 5ab5ee99b9306361a29b6a6b4dded3a7 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 */ 9package com.hurlant.crypto.symmetric { 10 import flash.utils.ByteArray; 11 import com.hurlant.util.Hex; 12 import com.hurlant.crypto.tls.TLSError; 13 14 public class SSLPad implements IPad { 15 private var blockSize:uint; 16 17 public function SSLPad(blockSize:uint=0) { 18 this.blockSize = blockSize; 19 } 20 public function pad(a:ByteArray):void { 21 var c:uint = blockSize - (a.length+1)%blockSize; 22 for (var i:uint=0;i<=c;i++) { 23 a[a.length] = c; 24 } 25 26 } 27 public function unpad(a:ByteArray):void { 28 var c:uint = a.length%blockSize; 29 if (c!=0) throw new TLSError("SSLPad::unpad: ByteArray.length isn't a multiple of the blockSize", TLSError.bad_record_mac); 30 c = a[a.length-1]; 31 for (var i:uint=c;i>0;i--) { 32 var v:uint = a[a.length-1]; 33 a.length--; 34 // But LOOK! SSL 3.0 doesn't care about this, bytes are arbitrary! 35 // if (c!=v) throw new TLSError("SSLPad:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]", TLSError.bad_record_mac); 36 } 37 a.length--; 38 39 } 40 public function setBlockSize(bs:uint):void { 41 blockSize = bs; 42 } 43 } 44}