BraintreeEncryption.Library.BouncyCastle.Crypto.Encodings.Pkcs1Encoding.DecodeBlock C# (CSharp) Method

DecodeBlock() private method

private DecodeBlock ( byte input, int inOff, int inLen ) : byte[]
input byte
inOff int
inLen int
return byte[]
        private byte[] DecodeBlock(
			byte[]	input,
			int		inOff,
			int		inLen)
        {
            byte[] block = engine.ProcessBlock(input, inOff, inLen);

            if (block.Length < GetOutputBlockSize())
            {
                throw new InvalidCipherTextException("block truncated");
            }

            byte type = block[0];

            if (type != 1 && type != 2)
            {
                throw new InvalidCipherTextException("unknown block type");
            }

            if (useStrictLength && block.Length != engine.GetOutputBlockSize())
            {
                throw new InvalidCipherTextException("block incorrect size");
            }

            //
            // find and extract the message block.
            //
            int start;
            for (start = 1; start != block.Length; start++)
            {
                byte pad = block[start];

                if (pad == 0)
                {
                    break;
                }

                if (type == 1 && pad != (byte)0xff)
                {
                    throw new InvalidCipherTextException("block padding incorrect");
                }
            }

            start++;           // data should start at the next byte

            if (start > block.Length || start < HeaderLength)
            {
                throw new InvalidCipherTextException("no data in block");
            }

            byte[] result = new byte[block.Length - start];

            Array.Copy(block, start, result, 0, result.Length);

            return result;
        }