#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR) using System; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Security; namespace Org.BouncyCastle.Crypto.Paddings { /// A padder that adds Trailing-Bit-Compliment padding to a block. ///

/// This padding pads the block out compliment of the last bit /// of the plain text. ///

///
public class TbcPadding : IBlockCipherPadding { /// Return the name of the algorithm the cipher implements. /// the name of the algorithm the cipher implements. /// public string PaddingName { get { return "TBC"; } } /// Initialise the padder. /// - a SecureRandom if available. /// public virtual void Init(SecureRandom random) { // nothing to do. } /// add the pad bytes to the passed in block, returning the /// number of bytes added. ///

/// Note: this assumes that the last block of plain text is always /// passed to it inside in. i.e. if inOff is zero, indicating the /// entire block is to be overwritten with padding the value of in /// should be the same as the last block of plain text. ///

///
public virtual int AddPadding(byte[] input, int inOff) { int count = input.Length - inOff; byte code; if (inOff > 0) { code = (byte)((input[inOff - 1] & 0x01) == 0?0xff:0x00); } else { code = (byte)((input[input.Length - 1] & 0x01) == 0?0xff:0x00); } while (inOff < input.Length) { input[inOff] = code; inOff++; } return count; } /// return the number of pad bytes present in the block. public virtual int PadCount(byte[] input) { byte code = input[input.Length - 1]; int index = input.Length - 1; while (index > 0 && input[index - 1] == code) { index--; } return input.Length - index; } } } #endif