public void SetFilenameTest() { // Arrange byte[] derivedKey = new byte[16] { 111, 222, 31, 4, 5, 6, 7, 8, 98, 10, 11, 12, 131, 104, 15, 16 }; SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR); string filename = "backup.zip"; byte[] fileContent = Encoding.UTF8.GetBytes("peace, happiness, freedom and something..."); FileEntry fileEntry = new FileEntry(filename, fileContent); FileEntrySecret fes = new FileEntrySecret(fileEntry, "does not matter", ska, derivedKey); string filename1 = "another_backup.zip"; // Act bool shouldBeTrue = fes.SetFilename(filename1, derivedKey); string filename2 = fes.GetFilename(derivedKey); bool shouldBeFalse = fes.SetFilename(filename1, new byte[] { 1, 2, 3 }); // Assert Assert.IsTrue(shouldBeTrue); Assert.IsFalse(shouldBeFalse); Assert.IsFalse(string.IsNullOrEmpty(filename2)); Assert.AreEqual(filename1, filename2); }
public void GetModificationTimeTest() { // Arrange byte[] derivedKey = new byte[16] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255 }; byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter); SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR); string filename = "nice.pdf"; byte[] fileContent = new byte[] { 1, 2, 3, 1, 2, byte.MaxValue, 0, 0, 0, 0, 0, 0 }; FileEntry fe = new FileEntry(filename, fileContent); FileEntrySecret fes = new FileEntrySecret(fe, "does not matter", skaAES_CTR, derivedKey); // Act DateTimeOffset fileEntryModificationTime1 = fes.GetModificationTime(derivedKey); Thread.Sleep(1100); fes.SetFilename("much_nicer.pdf", derivedKey); DateTimeOffset fileEntryModificationTime2 = fes.GetModificationTime(derivedKey); // Assert Assert.Greater(fileEntryModificationTime2, fileEntryModificationTime1); }