public void GetPacketHeader_Throws_For_Null_Segment() { Action getPacketLength = () => RollingIv.GetPacketLength(null); getPacketLength .ShouldThrow <ArgumentNullException>(); }
public void GetPacketHeader_Throws_When_Segment_Shorter_Than_4_Bytes() { Action getPacketLength = () => RollingIv.GetPacketLength(new byte[] { 0x01, 0x02, 0x03 }); getPacketLength .ShouldThrow <ArgumentException>() .WithMessagePrefix(SegmentMustBeLongerThan4()); }
public void Transform_Throws_On_Null_Buffer() { var algorithm = Mock.Of <ICryptoAlgorithm>(); var rollingIv = new RollingIv(algorithm, new byte[] { 0x12, 0x34, 0x56, 0x78 }, 0x1234); rollingIv .Invoking(iv => iv.Transform(null)) .ShouldThrow <ArgumentNullException>(); }
public void ValidateHeader_Throws_On_Null_Segment() { var algorithm = new Mock <ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); rollingIv .Invoking(iv => iv.ValidateHeader(null)) .ShouldThrow <ArgumentNullException>(); }
public void ConstructHeader_Throws_For_Packets_Shorter_Than_2_Bytes() { var algorithm = new Mock <ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); rollingIv .Invoking(iv => iv.ConstructHeader(1).Whatever()) .ShouldThrow <ArgumentOutOfRangeException>() .WithMessagePrefix(CommonStrings.PacketLengthMustBeMoreThan2Bytes); }
public void ValidateHeader_Throws_When_Segment_Shorter_Than_4_Bytes() { var algorithm = new Mock <ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); rollingIv .Invoking(iv => iv.ValidateHeader(new byte[] { 0x01, 0x02, 0x03 })) .ShouldThrow <ArgumentException>() .WithMessagePrefix(SegmentMustBeLongerThan4()); }
public void ConstructHeader_Throws_For_Packets_Shorter_Than_2_Bytes() { var algorithm = new Mock<ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); rollingIv .Invoking(iv => iv.ConstructHeader(1).Whatever()) .ShouldThrow<ArgumentOutOfRangeException>() .WithMessagePrefix(CommonStrings.PacketLengthMustBeMoreThan2Bytes); }
public void Transform_Calls_TransformArraySegment_And_ShuffleIv() { var algorithm = new Mock <ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); var data = new byte[] { 0x12, 0x34 }; rollingIv.Transform(data); algorithm.Verify(m => m.TransformArraySegment(AnyByteArray(), AnyByteArray(), 0, 2), Times.Once()); algorithm.Verify(m => m.ShuffleIv(AnyByteArray()), Times.Once()); }
public void Transform_Calls_TransformArraySegment_And_ShuffleIv() { var algorithm = new Mock<ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); var data = new byte[] { 0x12, 0x34 }; rollingIv.Transform(data); algorithm.Verify(m => m.TransformArraySegment(AnyByteArray(), AnyByteArray(), 0, 2), Times.Once()); algorithm.Verify(m => m.ShuffleIv(AnyByteArray()), Times.Once()); }
/// <summary> /// Attempts to extract the length of a packet from its header. /// </summary> /// <remarks> /// When overriding this method in a derived class, /// do not call the base implementation. /// </remarks> /// <param name="header">The header byte array to process.</param> /// <param name="length">A variable to hold the result.</param> /// <returns><see langword="true"/> if the extraction was successful; otherwise, <see langword="false"/>.</returns> public bool TryGetLength(byte[] header, out int length) { if (_decryptor.ValidateHeader(header)) { length = RollingIv.GetPacketLength(header); return(true); } else { length = default(int); return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="EndpointCrypto"/> class. /// </summary> /// <param name="encryptor">The IV used for encryption.</param> /// <param name="decryptor">The IV used for decryption.</param> private EndpointCrypto(RollingIv encryptor, RollingIv decryptor) { _encryptor = encryptor; _decryptor = decryptor; }
/// <summary> /// Initializes a new instance of the <see cref="EndpointCrypto"/> class. /// </summary> /// <param name="encryptor">The IV used for encryption.</param> /// <param name="decryptor">The IV used for decryption.</param> private EndpointCrypto(RollingIv encryptor, RollingIv decryptor) { this.encryptor = encryptor; this.decryptor = decryptor; }
public void Transform_Throws_On_Null_Buffer() { var algorithm = Mock.Of<ICryptoAlgorithm>(); var rollingIv = new RollingIv(algorithm, new byte[] { 0x12, 0x34, 0x56, 0x78 }, 0x1234); rollingIv .Invoking(iv => iv.Transform(null)) .ShouldThrow<ArgumentNullException>(); }
public void ValidateHeader_Throws_When_Segment_Shorter_Than_4_Bytes() { var algorithm = new Mock<ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); rollingIv .Invoking(iv => iv.ValidateHeader(new byte[] { 0x01, 0x02, 0x03 })) .ShouldThrow<ArgumentException>() .WithMessagePrefix(SegmentMustBeLongerThan4()); }
public void ValidateHeader_Throws_On_Null_Segment() { var algorithm = new Mock<ICryptoAlgorithm>(MockBehavior.Loose); var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 }; var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234); rollingIv .Invoking(iv => iv.ValidateHeader(null)) .ShouldThrow<ArgumentNullException>(); }