/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as
ActionScript | 42 lines | 31 code | 2 blank | 9 comment | 4 complexity | 4ebb39986b8610a52eab5feff4cac3cf 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 */ 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 TLSPad implements IPad { 15 private var blockSize:uint; 16 17 public function TLSPad(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 public function unpad(a:ByteArray):void { 27 var c:uint = a.length%blockSize; 28 if (c!=0) throw new TLSError("TLSPad::unpad: ByteArray.length isn't a multiple of the blockSize", TLSError.bad_record_mac); 29 c = a[a.length-1]; 30 for (var i:uint=c;i>0;i--) { 31 var v:uint = a[a.length-1]; 32 a.length--; 33 if (c!=v) throw new TLSError("TLSPad:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]", TLSError.bad_record_mac); 34 } 35 a.length--; 36 // mostly ripped off from PKCS5.as, but with subtle differences 37 } 38 public function setBlockSize(bs:uint):void { 39 blockSize = bs; 40 } 41 } 42}