Esempio n. 1
0
        public void RenameFile(UserDataFile file, string name)
        {
            if (name.Contains("/"))
            {
                throw new NotANameException(Strings.Vault_RenameFile_Argument_isn_t_a_name);
            }
            var dir = NDirectory.GetPathParentDir(file.Header.SecuredPlainName.PlainName);

            MoveFile(file, dir + name);
        }
Esempio n. 2
0
        public static async Task <byte[]> ExtractUserDataFile(string sourcePath, string destinationPath, byte[] key,
                                                              byte[] iv)
        {
            NDirectory.CreateMissingDirs(destinationPath);

            await using var src  = new FileStream(sourcePath, FileMode.Open, FileAccess.Read);
            await using var dest = new FileStream(destinationPath, FileMode.Create, FileAccess.Write);

            using var decryptor       = QuickAesTransform.CreateDecryptor(key, iv);
            await using var srcCrypto = new CryptoStream(src, decryptor, CryptoStreamMode.Read);

            var hash = await srcCrypto.CopyToCreateHashAsync(dest);

            return(hash);
        }
Esempio n. 3
0
        public void MoveFile(UserDataFile file, string destination)
        {
            // TODO: check if destination is a path by ending with a /
            var relativePath = NPath.RemoveRelativeParts(destination);
            var prevFileName = file.Header.SecuredPlainName.PlainName;

            if (PlainNameAlreadyExists(relativePath))
            {
                FileAlreadyExists();
            }

            file.Move(relativePath);

            if (file.Header.IsUnlocked)
            {
                var srcPath  = Path.Combine(UnlockedFolderPath, prevFileName);
                var destPath = Path.Combine(UnlockedFolderPath, file.Header.SecuredPlainName.PlainName);
                NDirectory.CreateMissingDirs(destPath);
                File.Move(srcPath, destPath);
            }
        }
Esempio n. 4
0
        public async Task EliminateExtracted(UserDataFile file)
        {
            if (!file.Header.IsUnlocked)
            {
                throw new FileNotUnlockedException();
            }
            var plainTextPath = file.Header.SecuredPlainName.PlainName;

            var path = Path.Combine(UnlockedFolderPath, plainTextPath);

            if (!File.Exists(path))
            {
                file.Header.IsUnlocked = false;
                throw new FileNotFoundException(Strings.Vault_EliminateExtracted_Decrypted_file_was_not_found, plainTextPath);
            }

            await NFile.Purge(path);

            file.Header.IsUnlocked = false;

            var parentDir = Path.Combine(UnlockedFolderPath, NDirectory.GetPathParentDir(plainTextPath));

            NDirectory.DeleteDirIfEmpty(parentDir, UnlockedFolderName);
        }
Esempio n. 5
0
        public static string GetRelativePathToFile(string relativeTo, string path)
        {
            var relativePath = Path.GetRelativePath(relativeTo + "/..", path);

            return(NDirectory.GetPathParentDir(relativePath));
        }