internal virtual byte[] DecodeAndVerify(byte type, Stream input, int len) { RecordStream.CheckLength(len, this.mCiphertextLimit, 22); byte[] array = TlsUtilities.ReadFully(len, input); TlsCipher arg_34_0 = this.mReadCipher; long seqNo; this.mReadSeqNo = (seqNo = this.mReadSeqNo) + 1L; byte[] array2 = arg_34_0.DecodeCiphertext(seqNo, type, array, 0, array.Length); RecordStream.CheckLength(array2.Length, this.mCompressedLimit, 22); Stream stream = this.mReadCompression.Decompress(this.mBuffer); if (stream != this.mBuffer) { stream.Write(array2, 0, array2.Length); stream.Flush(); array2 = this.GetBufferContents(); } RecordStream.CheckLength(array2.Length, this.mPlaintextLimit, 30); if (array2.Length < 1 && type != 23) { throw new TlsFatalAlert(47); } return(array2); }
internal virtual void WriteRecord(byte type, byte[] plaintext, int plaintextOffset, int plaintextLength) { if (this.mWriteVersion == null) { return; } RecordStream.CheckType(type, 80); RecordStream.CheckLength(plaintextLength, this.mPlaintextLimit, 80); if (plaintextLength < 1 && type != 23) { throw new TlsFatalAlert(80); } if (type == 22) { this.UpdateHandshakeData(plaintext, plaintextOffset, plaintextLength); } Stream stream = this.mWriteCompression.Compress(this.mBuffer); byte[] array; if (stream == this.mBuffer) { TlsCipher arg_7B_0 = this.mWriteCipher; long seqNo; this.mWriteSeqNo = (seqNo = this.mWriteSeqNo) + 1L; array = arg_7B_0.EncodePlaintext(seqNo, type, plaintext, plaintextOffset, plaintextLength); } else { stream.Write(plaintext, plaintextOffset, plaintextLength); stream.Flush(); byte[] bufferContents = this.GetBufferContents(); RecordStream.CheckLength(bufferContents.Length, plaintextLength + 1024, 80); TlsCipher arg_CC_0 = this.mWriteCipher; long seqNo2; this.mWriteSeqNo = (seqNo2 = this.mWriteSeqNo) + 1L; array = arg_CC_0.EncodePlaintext(seqNo2, type, bufferContents, 0, bufferContents.Length); } RecordStream.CheckLength(array.Length, this.mCiphertextLimit, 80); byte[] array2 = new byte[array.Length + 5]; TlsUtilities.WriteUint8(type, array2, 0); TlsUtilities.WriteVersion(this.mWriteVersion, array2, 1); TlsUtilities.WriteUint16(array.Length, array2, 3); Array.Copy(array, 0, array2, 5, array.Length); this.mOutput.Write(array2, 0, array2.Length); this.mOutput.Flush(); }