_mode = mode;
_disposed = false;
if (transform != null) {
- if (mode == CryptoStreamMode.Read) {
- _currentBlock = new byte [transform.InputBlockSize];
- _workingBlock = new byte [transform.InputBlockSize];
- }
- else if (mode == CryptoStreamMode.Write) {
- _currentBlock = new byte [transform.OutputBlockSize];
- _workingBlock = new byte [transform.OutputBlockSize];
- }
+ _workingBlock = new byte [transform.InputBlockSize];
}
}
}
if (_stream == null)
- throw new ArgumentNullException ("inner stream was diposed");
+ throw new ArgumentNullException ("inner stream was disposed");
int buffer_length = count;
int bufferPos = offset;
while (count > 0) {
if (_partialCount == _transform.InputBlockSize) {
+ if (_currentBlock == null)
+ _currentBlock = new byte [_transform.OutputBlockSize];
+
// use partial block to avoid (re)allocation
int len = _transform.TransformBlock (_workingBlock, 0, _partialCount, _currentBlock, 0);
_stream.Write (_currentBlock, 0, len);
CryptoStream cs = new CryptoStream (Stream.Null, SHA1.Create (), (CryptoStreamMode) 0xff);
}
+ [Test]
+ public void OutputBlock_Smaller ()
+ {
+ // The OutputBlockSize is smaller than the InputBlockSize
+ using (CryptoStream cs = new CryptoStream(Stream.Null, new MyCryptAlgorithm(), CryptoStreamMode.Write)) {
+ byte[] buffer = new byte[512 * 1024];
+ cs.Write(buffer, 0, buffer.Length);
+ }
+ }
+
class MyCryptoStream : CryptoStream {
public bool DisposeCalled { get; private set;}
}
}
+ class MyCryptAlgorithm : ICryptoTransform {
+ public bool CanReuseTransform { get { return true; } }
+ public bool CanTransformMultipleBlocks { get { return false; } }
+ public int InputBlockSize { get { return 128 * 1024; } }
+ public int OutputBlockSize { get { return 64 * 1024; } }
+
+ public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
+ {
+ return this.OutputBlockSize;
+ }
+
+ public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
+ {
+ return new byte[this.OutputBlockSize];
+ }
+
+ public void Dispose() {}
+ }
+
class MyStream : Stream {
public bool FlushCounterEnabled;
public int FlushCounter;