public void TransformBlock_Throws_IfParametersAreInvalid() { var inputBuffer = new byte[BlockSizeBytes]; var outputBuffer = new byte[BlockSizeBytes]; var inputOffset = 0; var inputCount = BlockSizeBytes; var outputOffset = 0; using var transform = new SimpleSymmetricAlgorithm(); using var encryptor = transform.CreateEncryptor(); Assert.Throws <ArgumentNullException>(nameof(inputBuffer), () => encryptor.TransformBlock(null !, inputOffset, inputCount, outputBuffer, outputOffset)); Assert.Throws <ArgumentNullException>(nameof(outputBuffer), () => encryptor.TransformBlock(inputBuffer, inputOffset, inputCount, null !, outputOffset)); Assert.Throws <ArgumentOutOfRangeException>(nameof(inputOffset), () => encryptor.TransformBlock(inputBuffer, -1, inputCount, outputBuffer, outputOffset)); Assert.Throws <ArgumentOutOfRangeException>(nameof(outputOffset), () => encryptor.TransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, -1)); Assert.Throws <ArgumentOutOfRangeException>(nameof(inputCount), () => encryptor.TransformBlock(inputBuffer, inputOffset, 0, outputBuffer, outputOffset)); Assert.Throws <ArgumentException>(null, () => encryptor.TransformBlock(inputBuffer, inputCount, inputCount, outputBuffer, outputOffset)); Assert.Throws <CryptographicException>( () => encryptor.TransformBlock(inputBuffer, inputOffset, inputCount - 1, outputBuffer, outputOffset)); }
public void TransformBlockInvalidArgumentsTest() { using (var transform = new SimpleSymmetricAlgorithm()) { using (var encryptor = transform.CreateEncryptor()) { Assert.Throws <ArgumentNullException>(() => encryptor.TransformBlock(null, 0, BlockSizeBytes, new byte[BlockSizeBytes], 0)); Assert.Throws <ArgumentNullException>(() => encryptor.TransformBlock(new byte[BlockSizeBytes], 0, BlockSizeBytes, null, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => encryptor.TransformBlock(new byte[BlockSizeBytes], -1, BlockSizeBytes, new byte[BlockSizeBytes], 0)); Assert.Throws <ArgumentOutOfRangeException>(() => encryptor.TransformBlock(new byte[BlockSizeBytes], 0, BlockSizeBytes, new byte[BlockSizeBytes], -1)); Assert.Throws <ArgumentOutOfRangeException>(() => encryptor.TransformBlock(new byte[BlockSizeBytes], 0, 0, new byte[BlockSizeBytes], 0)); Assert.Throws <ArgumentException>(() => encryptor.TransformBlock(new byte[BlockSizeBytes], BlockSizeBytes, BlockSizeBytes, new byte[BlockSizeBytes], 0)); Assert.Throws <CryptographicException>(() => encryptor.TransformBlock(new byte[BlockSizeBytes], 0, BlockSizeBytes - 1, new byte[BlockSizeBytes], 0)); } } }