示例#1
0
 //
 public override long Seek(long offset, SeekOrigin origin)
 {
     throw new NotSupportedException(SR.GetString(SR.net_noseek));
 }
示例#2
0
        private BufferOffsetSize[] EncryptBuffers(BufferOffsetSize[] buffers, byte[] lastHandshakePayload)
        {
            List <BufferOffsetSize> list = null;
            SecurityStatus          oK   = SecurityStatus.OK;

            foreach (BufferOffsetSize size in buffers)
            {
                int    num2;
                int    count     = Math.Min(size.Size, this._SslState.MaxDataSize);
                byte[] outBuffer = null;
                oK = this._SslState.EncryptData(size.Buffer, size.Offset, count, ref outBuffer, out num2);
                if (oK != SecurityStatus.OK)
                {
                    break;
                }
                if ((count != size.Size) || (list != null))
                {
                    if (list == null)
                    {
                        list = new List <BufferOffsetSize>(buffers.Length * ((size.Size / count) + 1));
                        if (lastHandshakePayload != null)
                        {
                            list.Add(new BufferOffsetSize(lastHandshakePayload, false));
                        }
                        foreach (BufferOffsetSize size2 in buffers)
                        {
                            if (size2 == size)
                            {
                                break;
                            }
                            list.Add(size2);
                        }
                    }
                    list.Add(new BufferOffsetSize(outBuffer, 0, num2, false));
                    while ((size.Size -= count) != 0)
                    {
                        size.Offset += count;
                        count        = Math.Min(size.Size, this._SslState.MaxDataSize);
                        oK           = this._SslState.EncryptData(size.Buffer, size.Offset, count, ref outBuffer, out num2);
                        if (oK != SecurityStatus.OK)
                        {
                            break;
                        }
                        list.Add(new BufferOffsetSize(outBuffer, 0, num2, false));
                    }
                }
                else
                {
                    size.Buffer = outBuffer;
                    size.Offset = 0;
                    size.Size   = num2;
                }
                if (oK != SecurityStatus.OK)
                {
                    break;
                }
            }
            if (oK != SecurityStatus.OK)
            {
                ProtocolToken token = new ProtocolToken(null, oK);
                throw new IOException(SR.GetString("net_io_encrypt"), token.GetException());
            }
            if (list != null)
            {
                buffers = list.ToArray();
                return(buffers);
            }
            if (lastHandshakePayload != null)
            {
                BufferOffsetSize[] destinationArray = new BufferOffsetSize[buffers.Length + 1];
                Array.Copy(buffers, 0, destinationArray, 1, buffers.Length);
                destinationArray[0] = new BufferOffsetSize(lastHandshakePayload, false);
                buffers             = destinationArray;
            }
            return(buffers);
        }