AddData() public méthode

Add some data to our buffer.
public AddData ( byte data, int offset, int len ) : void
data byte A byte-array to read data from.
offset int How many bytes to skip at the beginning of the array.
len int How many bytes to read from the array.
Résultat void
Exemple #1
0
        private int ReceiveRecord(byte[] buf, int off, int len, int waitMillis)
        {
            if (mRecordQueue.Available > 0)
            {
                int length = 0;
                if (mRecordQueue.Available >= RECORD_HEADER_LENGTH)
                {
                    byte[] lengthBytes = new byte[2];
                    mRecordQueue.Read(lengthBytes, 0, 2, 11);
                    length = TlsUtilities.ReadUint16(lengthBytes, 0);
                }

                int received = System.Math.Min(mRecordQueue.Available, RECORD_HEADER_LENGTH + length);
                mRecordQueue.RemoveData(buf, off, received, 0);
                return(received);
            }

            {
                int received = mTransport.Receive(buf, off, len, waitMillis);
                if (received >= RECORD_HEADER_LENGTH)
                {
                    int fragmentLength = TlsUtilities.ReadUint16(buf, off + 11);
                    int recordLength   = RECORD_HEADER_LENGTH + fragmentLength;
                    if (received > recordLength)
                    {
                        mRecordQueue.AddData(buf, off + recordLength, received - recordLength);
                        received = recordLength;
                    }
                }
                return(received);
            }
        }
        private int ReceiveRecord(byte[] buf, int off, int len, int waitMillis)
        {
            if (mRecordQueue.Available > 0)
            {
                int num = 0;
                if (mRecordQueue.Available >= 13)
                {
                    byte[] buf2 = new byte[2];
                    mRecordQueue.Read(buf2, 0, 2, 11);
                    num = TlsUtilities.ReadUint16(buf2, 0);
                }
                int num2 = Math.Min(mRecordQueue.Available, 13 + num);
                mRecordQueue.RemoveData(buf, off, num2, 0);
                return(num2);
            }
            int num3 = mTransport.Receive(buf, off, len, waitMillis);

            if (num3 >= 13)
            {
                int num4 = TlsUtilities.ReadUint16(buf, off + 11);
                int num5 = 13 + num4;
                if (num3 > num5)
                {
                    mRecordQueue.AddData(buf, off + num5, num3 - num5);
                    num3 = num5;
                }
            }
            return(num3);
        }
Exemple #3
0
        protected internal void ProcessRecord(byte protocol, byte[] buf, int offset, int len)
        {
            switch (protocol)
            {
            case 21:
                mAlertQueue.AddData(buf, offset, len);
                ProcessAlert();
                break;

            case 23:
                if (!mAppDataReady)
                {
                    throw new TlsFatalAlert(10);
                }
                mApplicationDataQueue.AddData(buf, offset, len);
                ProcessApplicationData();
                break;

            case 20:
                ProcessChangeCipherSpec(buf, offset, len);
                break;

            case 22:
                mHandshakeQueue.AddData(buf, offset, len);
                ProcessHandshake();
                break;

            case 24:
                if (!mAppDataReady)
                {
                    throw new TlsFatalAlert(10);
                }
                break;
            }
        }
Exemple #4
0
        internal void ProcessData(
            short protocol,
            byte[]  buf,
            int offset,
            int len)
        {
            /*
             * Have a look at the protocol type, and add it to the correct queue.
             */
            switch (protocol)
            {
            case RL_CHANGE_CIPHER_SPEC:
                changeCipherSpecQueue.AddData(buf, offset, len);
                processChangeCipherSpec();
                break;

            case RL_ALERT:
                alertQueue.AddData(buf, offset, len);
                processAlert();
                break;

            case RL_HANDSHAKE:
                handshakeQueue.AddData(buf, offset, len);
                processHandshake();
                break;

            case RL_APPLICATION_DATA:
                if (!appDataReady)
                {
                    this.FailWithError(AL_fatal, AP_unexpected_message);
                }
                applicationDataQueue.AddData(buf, offset, len);
                processApplicationData();
                break;

            default:
                /*
                 * Uh, we don't know this protocol.
                 *
                 * RFC2246 defines on page 13, that we should ignore this.
                 */
                break;
            }
        }
        internal void ProcessData(
            ContentType protocol,
            byte[]          buf,
            int offset,
            int len)
        {
            /*
             * Have a look at the protocol type, and add it to the correct queue.
             */
            switch (protocol)
            {
            case ContentType.change_cipher_spec:
                changeCipherSpecQueue.AddData(buf, offset, len);
                ProcessChangeCipherSpec();
                break;

            case ContentType.alert:
                alertQueue.AddData(buf, offset, len);
                ProcessAlert();
                break;

            case ContentType.handshake:
                handshakeQueue.AddData(buf, offset, len);
                ProcessHandshake();
                break;

            case ContentType.application_data:
                if (!appDataReady)
                {
                    this.FailWithError(AlertLevel.fatal, AlertDescription.unexpected_message);
                }
                applicationDataQueue.AddData(buf, offset, len);
                ProcessApplicationData();
                break;

            default:
                /*
                 * Uh, we don't know this protocol.
                 *
                 * RFC2246 defines on page 13, that we should ignore this.
                 */
                break;
            }
        }
Exemple #6
0
 public virtual void Write(byte[] buf)
 {
     buffer.AddData(buf, 0, buf.Length);
 }