/// <summary> /// Write the specified buffer, offset and count. /// </summary> /// <returns>The write.</returns> /// <param name="buffer">Buffer.</param> /// <param name="offset">Offset.</param> /// <param name="count">Count.</param> public override void Write(byte[] buffer, int offset, int count) { base.Write(buffer, offset, count); CurrentPosition += count; if (!FinishedHashing) { Algorithm.AppendBlock(buffer, offset, count); } }
public override int Read(byte[] buffer, int offset, int count) { int num = base.Read(buffer, offset, count); CurrentPosition += num; if (!FinishedHashing) { Algorithm.AppendBlock(buffer, offset, num); } return(num); }
/// <summary> /// Asynchronously reads a sequence of bytes from the current stream, advances /// the position within the stream by the number of bytes read, and monitors /// cancellation requests. /// </summary> /// <param name="buffer"> /// An array of bytes. When this method returns, the buffer contains the specified /// byte array with the values between offset and (offset + count - 1) replaced /// by the bytes read from the current source. /// </param> /// <param name="offset"> /// The zero-based byte offset in buffer at which to begin storing the data read /// from the current stream. /// </param> /// <param name="count"> /// The maximum number of bytes to be read from the current stream. /// </param> /// <param name="cancellationToken"> /// The token to monitor for cancellation requests. The default value is /// System.Threading.CancellationToken.None. /// </param> /// <returns> /// A task that represents the asynchronous read operation. The value of the TResult /// parameter contains the total number of bytes read into the buffer. This can be /// less than the number of bytes requested if that many bytes are not currently /// available, or zero (0) if the end of the stream has been reached. /// </returns> public async override Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { int result = await base.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false); CurrentPosition += result; if (!FinishedHashing) { Algorithm.AppendBlock(buffer, offset, result); } return(result); }
/// <summary> /// Reads a sequence of bytes from the current stream and advances the position /// within the stream by the number of bytes read. /// </summary> /// <param name="buffer"> /// An array of bytes. When this method returns, the buffer contains the specified /// byte array with the values between offset and (offset + count - 1) replaced /// by the bytes read from the current source. /// </param> /// <param name="offset"> /// The zero-based byte offset in buffer at which to begin storing the data read /// from the current stream. /// </param> /// <param name="count"> /// The maximum number of bytes to be read from the current stream. /// </param> /// <returns> /// The total number of bytes read into the buffer. This can be less than the /// number of bytes requested if that many bytes are not currently available, /// or zero (0) if the end of the stream has been reached. /// </returns> public override int Read(byte[] buffer, int offset, int count) { int result = base.Read(buffer, offset, count); CurrentPosition += result; if (!FinishedHashing) { Algorithm.AppendBlock(buffer, offset, result); } // Calculate the hash if this was the final read if (result == 0) { CalculateHash(); } return(result); }
private int Append(byte[] buffer, int offset, int readBytes) { if (readBytes == 0) { return(0); } int numBytesRead = 0; while (numBytesRead < readBytes) { numBytesRead += Algorithm.AppendBlock(buffer, offset, InternalEncryptionBlockSize, internalBuffer, 0); Buffer.BlockCopy(internalBuffer, 0, buffer, offset, InternalEncryptionBlockSize); offset = offset + InternalEncryptionBlockSize; } Buffer.BlockCopy(buffer, numBytesRead - InternalEncryptionBlockSize, InitializationVector, 0, InternalEncryptionBlockSize); return(numBytesRead); }