public static void TestWipe() { string testFile = _rootPath.PathCombine("Folder", "file-to-be-wiped.txt"); IRuntimeFileInfo fileInfo = OS.Current.FileInfo(testFile); using (Stream writeStream = fileInfo.OpenWrite()) { } Assert.That(fileInfo.Exists, "Now it should exist."); AxCryptFile.Wipe(fileInfo, new ProgressContext()); Assert.That(!fileInfo.Exists, "And now it should not exist after wiping."); }
public static void TestInvalidArguments() { IRuntimeFileInfo sourceFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo destinationFileInfo = sourceFileInfo.CreateEncryptedName(); AxCryptDocument document = new AxCryptDocument(); IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(Path.Combine(_rootPath, "decrypted test.txt")); AxCryptDocument nullDocument = null; IRuntimeFileInfo nullFileInfo = null; AesKey nullKey = null; ProgressContext nullProgress = null; Passphrase nullPassphrase = null; Stream nullStream = null; string nullString = null; Action <Stream> nullStreamAction = null; Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(nullFileInfo, destinationFileInfo, new Passphrase("axcrypt"), AxCryptOptions.EncryptWithCompression, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(sourceFileInfo, nullFileInfo, new Passphrase("axcrypt"), AxCryptOptions.EncryptWithCompression, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(sourceFileInfo, destinationFileInfo, nullPassphrase, AxCryptOptions.EncryptWithCompression, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(sourceFileInfo, destinationFileInfo, new Passphrase("axcrypt"), AxCryptOptions.EncryptWithCompression, nullProgress); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(nullFileInfo, new MemoryStream(), new AesKey(), AxCryptOptions.None, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(sourceFileInfo, nullStream, new AesKey(), AxCryptOptions.None, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(sourceFileInfo, new MemoryStream(), nullKey, AxCryptOptions.None, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Encrypt(sourceFileInfo, new MemoryStream(), new AesKey(), AxCryptOptions.None, nullProgress); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(nullDocument, decryptedFileInfo, AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(document, nullFileInfo, AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(document, decryptedFileInfo, AxCryptOptions.SetFileTimes, nullProgress); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(nullFileInfo, decryptedFileInfo, new AesKey(), AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(sourceFileInfo, nullFileInfo, new AesKey(), AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(sourceFileInfo, decryptedFileInfo, nullKey, AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(sourceFileInfo, decryptedFileInfo, new AesKey(), AxCryptOptions.SetFileTimes, nullProgress); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(nullFileInfo, Path.Combine(_rootPath, "Directory"), new AesKey(), AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(sourceFileInfo, nullString, new AesKey(), AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(sourceFileInfo, Path.Combine(_rootPath, "Directory"), nullKey, AxCryptOptions.SetFileTimes, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Decrypt(sourceFileInfo, Path.Combine(_rootPath, "Directory"), new AesKey(), AxCryptOptions.SetFileTimes, nullProgress); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Document(nullFileInfo, new AesKey(), new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Document(sourceFileInfo, nullKey, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Document(sourceFileInfo, new AesKey(), nullProgress); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.WriteToFileWithBackup(null, (Stream stream) => { }, new ProgressContext()); }); IRuntimeFileInfo fileInfo = OS.Current.FileInfo(_testTextPath); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.WriteToFileWithBackup(fileInfo, nullStreamAction, new ProgressContext()); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.MakeAxCryptFileName(nullFileInfo); }); Assert.Throws <ArgumentNullException>(() => { AxCryptFile.Wipe(nullFileInfo, new ProgressContext()); }); }
public static void TestWipeWithDelayedUntilDoneCancel() { IRuntimeFileInfo fileInfo = OS.Current.FileInfo(_davidCopperfieldTxtPath); ProgressContext progress = new ProgressContext(TimeSpan.Zero); progress.Progressing += (object sender, ProgressEventArgs e) => { ((ProgressContext)sender).Cancel = true; }; Assert.Throws <OperationCanceledException>(() => { AxCryptFile.Wipe(fileInfo, progress); }); Assert.That(!fileInfo.Exists, "The file should be completely wiped, even if canceled at start."); }
private bool WipeFileOperation() { if (_eventArgs.Skip) { _eventArgs.Status = FileOperationStatus.Success; return(true); } _progress.NotifyLevelStart(); AxCryptFile.Wipe(OS.Current.FileInfo(_eventArgs.SaveFileFullName), _progress); _progress.NotifyLevelFinished(); _eventArgs.Status = FileOperationStatus.Success; return(true); }
public static void TestWipeFileDoesNotExist() { ProgressContext progress = new ProgressContext(TimeSpan.Zero); bool progressed = false; progress.Progressing += (object sender, ProgressEventArgs e) => { progressed = true; }; string filePath = Path.Combine(Path.Combine(_rootPath, "Folder"), "DoesNot.Exist"); IRuntimeFileInfo fileInfo = OS.Current.FileInfo(filePath); Assert.DoesNotThrow(() => { AxCryptFile.Wipe(fileInfo, progress); }); Assert.That(!progressed, "There should be no progress-notification since nothing should happen."); }
private static ActiveFile TryDelete(ActiveFile activeFile, ProgressContext progress) { if (activeFile.Process != null && !activeFile.Process.HasExited) { if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Not deleting '{0}' because it has an active process.".InvariantFormat(activeFile.DecryptedFileInfo.FullName)); } return(activeFile); } if (activeFile.IsModified) { if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Tried delete '{0}' but it is modified.".InvariantFormat(activeFile.DecryptedFileInfo.FullName)); } return(activeFile); } try { if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Deleting '{0}'.".InvariantFormat(activeFile.DecryptedFileInfo.FullName)); } AxCryptFile.Wipe(activeFile.DecryptedFileInfo, progress); } catch (IOException) { if (OS.Log.IsWarningEnabled) { OS.Log.LogWarning("Wiping failed for '{0}'".InvariantFormat(activeFile.DecryptedFileInfo.FullName)); } activeFile = new ActiveFile(activeFile, activeFile.Status | ActiveFileStatus.NotShareable); return(activeFile); } activeFile = new ActiveFile(activeFile, ActiveFileStatus.NotDecrypted, null); if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Deleted '{0}' from '{1}'.".InvariantFormat(activeFile.DecryptedFileInfo.FullName, activeFile.EncryptedFileInfo.FullName)); } return(activeFile); }
private bool DecryptFileOperation() { _progress.NotifyLevelStart(); try { AxCryptFile.Decrypt(_eventArgs.AxCryptDocument, OS.Current.FileInfo(_eventArgs.SaveFileFullName), AxCryptOptions.SetFileTimes, _progress); } finally { _eventArgs.AxCryptDocument.Dispose(); _eventArgs.AxCryptDocument = null; } AxCryptFile.Wipe(OS.Current.FileInfo(_eventArgs.OpenFileFullName), _progress); _progress.NotifyLevelFinished(); _eventArgs.Status = FileOperationStatus.Success; return(true); }