コード例 #1
0
 protected void ValidateParameters(
     byte[] inputBuffer,
     int inputOffset,
     int inputCount,
     byte[] outputBuffer,
     int outputOffset,
     bool allowZeroCount)
 {
     this.ValidateInputBufferParameters(inputBuffer, inputOffset, inputCount, true, allowZeroCount);
     OperationStream.ValidateBufferParameters(outputBuffer, outputOffset, 0, true);
 }
コード例 #2
0
 protected void ValidateInputBufferParameters(
     byte[] inputBuffer,
     int inputOffset,
     int inputCount,
     bool validateBlockSize,
     bool allowZeroCount)
 {
     OperationStream.ValidateBufferParameters(inputBuffer, inputOffset, inputCount, allowZeroCount);
     if (this.FixedInputBlockSize && validateBlockSize && inputCount % this.InputBlockSize != 0)
     {
         throw new ArgumentException("Invalid value.", nameof(inputCount));
     }
 }
コード例 #3
0
ファイル: OperationStream.cs プロジェクト: RichardHaggard/BDC
        internal virtual void FlushFinalBlock()
        {
            if (this.finalBlockTransformed)
            {
                throw new NotSupportedException("Can't flush final block twice");
            }
            byte[] buffer = new byte[0];
            if (this.inputBuffer != null)
            {
                buffer = this.Transform.TransformFinalBlock(this.inputBuffer, 0, this.inputBufferIndex);
            }
            this.finalBlockTransformed  = true;
            this.TotalTransformedCount += (long)buffer.Length;
            if (this.baseStream != null && this.CanWrite)
            {
                if (this.outputBufferIndex > 0)
                {
                    this.baseStream.Write(this.outputBuffer, 0, this.outputBufferIndex);
                    this.outputBufferIndex = 0;
                }
                this.baseStream.Write(buffer, 0, buffer.Length);
            }
            OperationStream baseStream = this.baseStream as OperationStream;

            if (baseStream == null)
            {
                try
                {
                    if (this.baseStream.CanRead)
                    {
                        this.baseStream.Flush();
                    }
                }
                catch (NotSupportedException ex)
                {
                }
            }
            else if (!baseStream.HasFlushedFinalBlock && baseStream.CanWrite)
            {
                baseStream.FlushFinalBlock();
            }
            if (this.inputBuffer != null)
            {
                Array.Clear((Array)this.inputBuffer, 0, this.inputBuffer.Length);
            }
            if (this.outputBuffer == null)
            {
                return;
            }
            Array.Clear((Array)this.outputBuffer, 0, this.outputBuffer.Length);
        }
コード例 #4
0
ファイル: Crc32.cs プロジェクト: RichardHaggard/BDC
 public uint UpdateChecksum(uint checksum, byte[] buffer, int offset, int length)
 {
     if (checksum == 1U || buffer == null)
     {
         checksum = 0U;
     }
     if (buffer != null)
     {
         OperationStream.ValidateBufferParameters(buffer, offset, length, true);
         checksum ^= uint.MaxValue;
         for (int index = 0; index < length; ++index)
         {
             checksum = Crc32.ComputeCrc32(checksum, buffer[offset + index]);
         }
         checksum ^= uint.MaxValue;
     }
     return(checksum);
 }
コード例 #5
0
ファイル: OperationStream.cs プロジェクト: RichardHaggard/BDC
        public override void Write(byte[] buffer, int offset, int count)
        {
            this.EnsureNotDisposed();
            OperationStream.ValidateBufferParameters(buffer, offset, count, true);
            if (!this.CanWrite)
            {
                throw new NotSupportedException();
            }
            this.TotalPlainCount += (long)count;
            int count1 = count;
            int num1   = offset;

            if (this.inputBufferIndex > 0)
            {
                if (count < this.Transform.InputBlockSize - this.inputBufferIndex)
                {
                    Buffer.BlockCopy((Array)buffer, offset, (Array)this.inputBuffer, this.inputBufferIndex, count);
                    this.inputBufferIndex += count;
                    return;
                }
                Buffer.BlockCopy((Array)buffer, offset, (Array)this.inputBuffer, this.inputBufferIndex, this.Transform.InputBlockSize - this.inputBufferIndex);
                num1   += this.Transform.InputBlockSize - this.inputBufferIndex;
                count1 -= this.Transform.InputBlockSize - this.inputBufferIndex;
                this.inputBufferIndex = this.Transform.InputBlockSize;
            }
            if (this.outputBufferIndex > 0)
            {
                this.baseStream.Write(this.outputBuffer, 0, this.outputBufferIndex);
                this.outputBufferIndex = 0;
            }
            if (this.inputBufferIndex == this.Transform.InputBlockSize)
            {
                int count2 = this.Transform.TransformBlock(this.inputBuffer, 0, this.Transform.InputBlockSize, this.outputBuffer, 0);
                this.TotalTransformedCount += (long)count2;
                this.baseStream.Write(this.outputBuffer, 0, count2);
                this.inputBufferIndex = 0;
            }
            while (count1 > 0)
            {
                if (count1 < this.Transform.InputBlockSize)
                {
                    Buffer.BlockCopy((Array)buffer, num1, (Array)this.inputBuffer, 0, count1);
                    this.inputBufferIndex += count1;
                    break;
                }
                if (!this.Transform.CanTransformMultipleBlocks)
                {
                    int count2 = this.Transform.TransformBlock(buffer, num1, this.Transform.InputBlockSize, this.outputBuffer, 0);
                    this.TotalTransformedCount += (long)count2;
                    this.baseStream.Write(this.outputBuffer, 0, count2);
                    num1   += this.Transform.InputBlockSize;
                    count1 -= this.Transform.InputBlockSize;
                }
                else
                {
                    int    num2       = count1 / this.Transform.InputBlockSize;
                    int    inputCount = num2 * this.Transform.InputBlockSize;
                    byte[] numArray   = new byte[num2 * this.Transform.OutputBlockSize];
                    int    count2     = this.Transform.TransformBlock(buffer, num1, inputCount, numArray, 0);
                    this.TotalTransformedCount += (long)count2;
                    this.baseStream.Write(numArray, 0, count2);
                    num1   += inputCount;
                    count1 -= inputCount;
                }
            }
        }
コード例 #6
0
ファイル: OperationStream.cs プロジェクト: RichardHaggard/BDC
        public override int Read(byte[] buffer, int offset, int count)
        {
            this.EnsureNotDisposed();
            OperationStream.ValidateBufferParameters(buffer, offset, count, true);
            if (!this.CanRead)
            {
                throw new NotSupportedException();
            }
            int num1      = count;
            int dstOffset = offset;

            if (this.outputBufferIndex != 0)
            {
                if (this.outputBufferIndex > count)
                {
                    Buffer.BlockCopy((Array)this.outputBuffer, 0, (Array)buffer, offset, count);
                    Buffer.BlockCopy((Array)this.outputBuffer, count, (Array)this.outputBuffer, 0, this.outputBufferIndex - count);
                    this.outputBufferIndex -= count;
                    return(count);
                }
                Buffer.BlockCopy((Array)this.outputBuffer, 0, (Array)buffer, offset, this.outputBufferIndex);
                num1      -= this.outputBufferIndex;
                dstOffset += this.outputBufferIndex;
                this.outputBufferIndex = 0;
            }
            if (this.finalBlockTransformed)
            {
                return(count - num1);
            }
            if (num1 > this.Transform.OutputBlockSize && this.Transform.CanTransformMultipleBlocks)
            {
                int    length   = (int)Math.Min((long)(num1 / this.Transform.OutputBlockSize * this.Transform.InputBlockSize), this.Length - this.Position);
                byte[] numArray = new byte[length];
                Buffer.BlockCopy((Array)this.inputBuffer, 0, (Array)numArray, 0, this.inputBufferIndex);
                int num2 = this.inputBufferIndex + this.baseStream.Read(numArray, this.inputBufferIndex, length - this.inputBufferIndex);
                this.TotalTransformedCount += (long)(num2 - this.inputBufferIndex);
                this.inputBufferIndex       = 0;
                if (num2 > this.Transform.InputBlockSize)
                {
                    int num3   = num2 / this.Transform.InputBlockSize * this.Transform.InputBlockSize;
                    int count1 = num2 - num3;
                    if (count1 != 0)
                    {
                        this.inputBufferIndex = count1;
                        Buffer.BlockCopy((Array)numArray, num3, (Array)this.inputBuffer, 0, count1);
                    }
                    byte[] outputBuffer = new byte[num3 / this.Transform.InputBlockSize * this.Transform.OutputBlockSize];
                    int    count2       = this.Transform.TransformBlock(numArray, 0, num3, outputBuffer, 0);
                    this.TotalPlainCount += (long)count2;
                    Buffer.BlockCopy((Array)outputBuffer, 0, (Array)buffer, dstOffset, count2);
                    Array.Clear((Array)numArray, 0, numArray.Length);
                    Array.Clear((Array)outputBuffer, 0, outputBuffer.Length);
                    num1      -= count2;
                    dstOffset += count2;
                }
                else
                {
                    this.inputBuffer      = numArray;
                    this.inputBufferIndex = num2;
                }
            }
            int count3;

            for (; num1 > 0; num1 -= count3)
            {
                int num2;
                for (; this.inputBufferIndex < this.Transform.InputBlockSize; this.inputBufferIndex += num2)
                {
                    num2 = this.baseStream.Read(this.inputBuffer, this.inputBufferIndex, (int)Math.Min((long)(this.Transform.InputBlockSize - this.inputBufferIndex), this.Length - this.Position));
                    this.TotalTransformedCount += (long)num2;
                    if (num2 == 0)
                    {
                        byte[] numArray = this.Transform.TransformFinalBlock(this.inputBuffer, 0, this.inputBufferIndex);
                        this.TotalPlainCount      += (long)numArray.Length;
                        this.outputBuffer          = numArray;
                        this.outputBufferIndex     = numArray.Length;
                        this.finalBlockTransformed = true;
                        if (num1 >= this.outputBufferIndex)
                        {
                            Buffer.BlockCopy((Array)this.outputBuffer, 0, (Array)buffer, dstOffset, this.outputBufferIndex);
                            int num3 = num1 - this.outputBufferIndex;
                            this.outputBufferIndex = 0;
                            return(count - num3);
                        }
                        Buffer.BlockCopy((Array)this.outputBuffer, 0, (Array)buffer, dstOffset, num1);
                        this.outputBufferIndex -= num1;
                        Buffer.BlockCopy((Array)this.outputBuffer, num1, (Array)this.outputBuffer, 0, this.outputBufferIndex);
                        return(count);
                    }
                }
                count3 = this.Transform.TransformBlock(this.inputBuffer, 0, this.Transform.InputBlockSize, this.outputBuffer, 0);
                this.TotalPlainCount += (long)count3;
                this.inputBufferIndex = 0;
                if (num1 < count3)
                {
                    Buffer.BlockCopy((Array)this.outputBuffer, 0, (Array)buffer, dstOffset, num1);
                    this.outputBufferIndex = count3 - num1;
                    Buffer.BlockCopy((Array)this.outputBuffer, num1, (Array)this.outputBuffer, 0, this.outputBufferIndex);
                    return(count);
                }
                Buffer.BlockCopy((Array)this.outputBuffer, 0, (Array)buffer, dstOffset, count3);
                dstOffset += count3;
            }
            return(count);
        }