public void Protect_LifetimeSpecified() { // Arrange // 0x08c1220247e44000 is the representation of midnight 2000-01-01 UTC. DateTimeOffset expiration = StringToDateTime("2000-01-01 00:00:00Z"); var mockInnerProtector = new Mock<IDataProtector>(); mockInnerProtector.Setup(o => o.CreateProtector("new purpose").CreateProtector(TimeLimitedPurposeString).Protect( new byte[] { 0x08, 0xc1, 0x22, 0x02, 0x47, 0xe4, 0x40, 0x00, /* header */ 0x01, 0x02, 0x03, 0x04, 0x05 /* payload */ })).Returns(new byte[] { 0x10, 0x11 }); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act var subProtector = timeLimitedProtector.CreateProtector("new purpose"); var protectedPayload = subProtector.Protect(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }, expiration); // Assert Assert.Equal(new byte[] { 0x10, 0x11 }, protectedPayload); }
public void Protect_LifetimeNotSpecified_UsesInfiniteLifetime() { // Arrange // 0x2bca2875f4373fff is the representation of DateTimeOffset.MaxValue. DateTimeOffset expiration = StringToDateTime("2000-01-01 00:00:00Z"); var mockInnerProtector = new Mock<IDataProtector>(); mockInnerProtector.Setup(o => o.CreateProtector("new purpose").CreateProtector(TimeLimitedPurposeString).Protect( new byte[] { 0x2b, 0xca, 0x28, 0x75, 0xf4, 0x37, 0x3f, 0xff, /* header */ 0x01, 0x02, 0x03, 0x04, 0x05 /* payload */ })).Returns(new byte[] { 0x10, 0x11 }); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act var subProtector = timeLimitedProtector.CreateProtector("new purpose"); var protectedPayload = subProtector.Protect(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }); // Assert Assert.Equal(new byte[] { 0x10, 0x11 }, protectedPayload); }
public void Protect_LifetimeNotSpecified_UsesInfiniteLifetime() { // Arrange // 0x2bca2875f4373fff is the representation of DateTimeOffset.MaxValue. DateTimeOffset expiration = StringToDateTime("2000-01-01 00:00:00Z"); var mockInnerProtector = new Mock <IDataProtector>(); mockInnerProtector.Setup(o => o.CreateProtector("new purpose").CreateProtector(TimeLimitedPurposeString).Protect( new byte[] { 0x2b, 0xca, 0x28, 0x75, 0xf4, 0x37, 0x3f, 0xff, /* header */ 0x01, 0x02, 0x03, 0x04, 0x05 /* payload */ })).Returns(new byte[] { 0x10, 0x11 }); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act var subProtector = timeLimitedProtector.CreateProtector("new purpose"); var protectedPayload = subProtector.Protect(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }); // Assert Assert.Equal(new byte[] { 0x10, 0x11 }, protectedPayload); }
public void Protect_LifetimeSpecified() { // Arrange // 0x08c1220247e44000 is the representation of midnight 2000-01-01 UTC. DateTimeOffset expiration = StringToDateTime("2000-01-01 00:00:00Z"); var mockInnerProtector = new Mock <IDataProtector>(); mockInnerProtector.Setup(o => o.CreateProtector("new purpose").CreateProtector(TimeLimitedPurposeString).Protect( new byte[] { 0x08, 0xc1, 0x22, 0x02, 0x47, 0xe4, 0x40, 0x00, /* header */ 0x01, 0x02, 0x03, 0x04, 0x05 /* payload */ })).Returns(new byte[] { 0x10, 0x11 }); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act var subProtector = timeLimitedProtector.CreateProtector("new purpose"); var protectedPayload = subProtector.Protect(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }, expiration); // Assert Assert.Equal(new byte[] { 0x10, 0x11 }, protectedPayload); }