/// <summary> /// Applies this processor to the /// given <paramref name="bytes"/>. /// </summary> /// <param name="bytes">Bytes to apply the processor to.</param> /// <returns>Modified bytes.</returns> public override byte[] Apply(byte[] bytes) { _byteIndexProvider.CreatePossibleByteIndexes(); while (_byteIndexProvider.ByteIndexPool.Count != 0) { bytes[_byteIndexProvider.GetNextByteIndex()] = ByteProvider.GetByte(); } return(bytes); }
/// <summary> /// Applies this processor to the /// given <paramref name="bytes"/>. /// </summary> /// <param name="bytes">Bytes to apply the processor to.</param> /// <returns>Modified bytes.</returns> public override byte[] Apply(byte[] bytes) { _byteIndexProvider.CreatePossibleByteIndexes(); while (_byteIndexProvider.ByteIndexPool.Count != 0) { uint byteIndex = _byteIndexProvider.GetNextByteIndex(); byte byteToShift = bytes[byteIndex]; if (Direction == ShiftDirection.Left) bytes[byteIndex] = (byte)(byteToShift << ByteProvider.GetByte()); else bytes[byteIndex] = (byte)(byteToShift >> ByteProvider.GetByte()); } return bytes; }
public void ProvideTest() { // given: ByteProvider with bytes byte[] bytes = new byte[] { 0, 1, 2, 3, 4 }; ByteProvider provider = new ByteProvider(bytes); // when: getting the bytes byte[] actual = new byte[10]; for (int i = 0; i < actual.Length; i++) { actual[i] = provider.GetByte(); } // then: correct bytes were provided. byte[] expected = new byte[] { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 }; CollectionAssert.AreEqual(expected, actual); }
/// <summary> /// Applies this processor to the /// given <paramref name="bytes"/>. /// </summary> /// <param name="bytes">Bytes to apply the processor to.</param> /// <returns>Modified bytes.</returns> public override byte[] Apply(byte[] bytes) { _byteIndexProvider.CreatePossibleByteIndexes(); while (_byteIndexProvider.ByteIndexPool.Count != 0) { uint byteIndex = _byteIndexProvider.GetNextByteIndex(); byte original = bytes[byteIndex]; byte value = ByteProvider.GetByte(); switch (OperationToPerform) { case Operation.Add: bytes[byteIndex] = AddByte(original, value); break; case Operation.Subtract: bytes[byteIndex] = SubtractByte(original, value); break; } } return(bytes); }