Exemplo n.º 1
0
            public void Discard(int byteCount)
            {
                Debug.Assert(byteCount <= _decryptedLength, "byteCount <= _decryptedBytes");

                _buffer.Discard(byteCount);
                _decryptedLength -= byteCount;

                // if drained all decrypted data, discard also the tail of the frame so that only
                // encrypted part of the active memory of the _buffer remains
                if (_decryptedLength == 0)
                {
                    _buffer.Discard(_decryptedPadding);
                    _decryptedPadding = 0;
                }
            }
Exemplo n.º 2
0
        private async ValueTask <ProtocolToken> ReceiveBlobAsync <TIOAdapter>(TIOAdapter adapter)
            where TIOAdapter : ISslIOAdapter
        {
            int readBytes = await FillHandshakeBufferAsync(adapter, SecureChannel.ReadHeaderSize).ConfigureAwait(false);

            if (readBytes == 0)
            {
                throw new IOException(SR.net_io_eof);
            }

            if (_framing == Framing.Unified || _framing == Framing.Unknown)
            {
                _framing = DetectFraming(_handshakeBuffer.ActiveReadOnlySpan);
            }

            int frameSize = GetFrameSize(_handshakeBuffer.ActiveReadOnlySpan);

            if (frameSize < 0)
            {
                throw new IOException(SR.net_frame_read_size);
            }

            if (_handshakeBuffer.ActiveLength < frameSize)
            {
                await FillHandshakeBufferAsync(adapter, frameSize).ConfigureAwait(false);
            }

            ProtocolToken token = _context.NextMessage(_handshakeBuffer.ActiveReadOnlySpan.Slice(0, frameSize));

            _handshakeBuffer.Discard(frameSize);

            return(token);
        }