コード例 #1
0
        public void TestMicrosoftAesStrategyFactory()
        {
            var options = new FileSystemOptions("", StreamEncryptionType.MicrosoftAes, StreamCompressionType.None);
            var encryptionOptions = GetEncryptionOptions();
            options.EncryptionKey = encryptionOptions.Key;
            options.EncryptionInitializationVector = encryptionOptions.InitializationVector;
            var res = new StramStrategyResolver(options);
            var s = res.ResolveStrategy();

            using (var ms = new MemoryStream())
            {
                var a = s.DecorateToVFS(ms);
                var b = s.DecorateToHost(ms);
                Assert.AreNotSame(ms, a);
                Assert.AreNotSame(ms, b);
                Assert.IsTrue(a is CryptoStream);
                Assert.IsTrue(b is CryptoStream);
                var c = a as CryptoStream;
                var d = b as CryptoStream;
                Assert.AreEqual(false, c.CanRead);
                Assert.AreEqual(true, c.CanWrite);
                Assert.AreEqual(true, d.CanRead);
                Assert.AreEqual(false, d.CanWrite);
            }
        }
コード例 #2
0
ファイル: BlockList.cs プロジェクト: RainsSoft/VFSPrototype
 // NOTE: long parameter smell. Are they all needed? If yes: refactoring "introduce parameter object".
 public BlockList(IIndexNode node, BlockAllocation blockAllocation, FileSystemOptions options, BlockParser blockParser,
                  BlockManipulator blockManipulator, Persistence persistence)
 {
     _node = node;
     _blockAllocation = blockAllocation;
     _options = options;
     _blockParser = blockParser;
     _blockManipulator = blockManipulator;
     _persistence = persistence;
 }
コード例 #3
0
        public VFSFileStream(VFSFile file, BlockParser blockParser, FileSystemOptions options, BlockAllocation blockAllocation, BlockManipulator blockManipulator, Persistence.Persistence persistence)
        {
            _file = file;
            _blockParser = blockParser;
            _options = options;
            _blockAllocation = blockAllocation;
            _blockManipulator = blockManipulator;
            _persistence = persistence;

            _writeBuffer = new byte[_options.BlockSize];
        }
コード例 #4
0
ファイル: FileSystem.cs プロジェクト: RainsSoft/VFSPrototype
        internal FileSystem(FileSystemOptions options)
        {
            _options = options;

            _blockManipulator = new BlockManipulator(_options.Location, _options.BlockSize, _options.MasterBlockSize);
            _blockParser = new BlockParser(_options);
            _persistence = new Persistence.Persistence(_blockParser, _blockManipulator);
            _blockAllocation = _options.BlockAllocation;

            InitializeFileSystem();
        }
コード例 #5
0
 public void TestApplyEncryptionSettings()
 {
     var o = TestHelper.CreateFileSystemOptions("");
     var o2 = new FileSystemOptions(o.Location, StreamEncryptionType.None, StreamCompressionType.None);
     o.EncryptionKey = new byte[] { 1, 2, 3 };
     Assert.IsNotNull(o.EncryptionKey);
     Assert.IsNull(o2.EncryptionKey);
     o2.ApplyEncryptionSettings(o);
     Assert.AreEqual(o.EncryptionKey, o2.EncryptionKey);
     Assert.AreEqual(1, o2.EncryptionKey[0]);
     Assert.AreEqual(2, o2.EncryptionKey[1]);
     Assert.AreEqual(3, o2.EncryptionKey[2]);
 }
コード例 #6
0
        internal static IFileSystem Create(FileSystemOptions options, string password)
        {
            if (File.Exists(options.Location)) throw new VFSException("File already exists");

            using (var file = File.Open(options.Location, FileMode.CreateNew, FileAccess.Write))
            {
                options.InitializePassword(password);

                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(file, options);
            }

            return new ThreadSafeFileSystem(options);
        }
コード例 #7
0
ファイル: BlockParser.cs プロジェクト: RainsSoft/VFSPrototype
 public BlockParser(FileSystemOptions options)
 {
     _options = options;
 }
コード例 #8
0
        public void ApplyEncryptionSettings(FileSystemOptions oldOptions)
        {
            if (oldOptions == null) throw new ArgumentNullException("oldOptions");

            _encryptedEncryptionKey = oldOptions._encryptedEncryptionKey;
            EncryptionKey = oldOptions.EncryptionKey;
            _streamCodingStrategy = oldOptions._streamCodingStrategy;
        }
コード例 #9
0
 public void Reload(FileSystemOptions newOptions)
 {
     _lock.EnterWriteLock();
     try
     {
         _fileSystem.Reload(newOptions);
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
コード例 #10
0
 internal ThreadSafeFileSystem(FileSystemOptions options)
 {
     _fileSystem = new FileSystem(options);
     _lock = _fileSystem.GetReadWriteLock();
 }
コード例 #11
0
 public void TestApplyEncryptionSettingFail()
 {
     var o2 = new FileSystemOptions("", StreamEncryptionType.None, StreamCompressionType.None);
     o2.ApplyEncryptionSettings(null);
 }
コード例 #12
0
 public ConsoleApplication(IConsoleApplicationSettings consoleApplicationSettings, FileSystemOptions options, IFileSystemTextManipulatorFactory factory)
     : this(consoleApplicationSettings, File.Exists(options.Location) ? factory.Open(options.Location, "console") : factory.Create(options, "console"))
 {
 }
コード例 #13
0
 public StramStrategyResolver(FileSystemOptions options)
 {
     _options = options;
 }
コード例 #14
0
        private void NewVfs(object parameter)
        {
            var pathToVFS = ViewModelHelper.ChoosePlaceForNewVFSFile();
            if (pathToVFS == null) return;

            // Close last vfs
            DisposeManipulator();

            var vm = new NewVFSViewModel();
            if (vm.ShowDialog() != true) return;

            try
            {
                var fileSystemData = new FileSystemOptions(pathToVFS, vm.EncryptionType, vm.CompressionType);
                _manipulator = _container.Resolve<IFileSystemTextManipulatorFactory>().Create(fileSystemData, vm.Password);
                _manipulator.FileSystemChanged += FileSystemChanged;
                CurrentPath = new DirectoryPath();
                OnPropertyChanged("FileSystemName");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            UpdateVersion();
        }
コード例 #15
0
 public IFileSystemTextManipulator Create(FileSystemOptions options, string password)
 {
     var fileSystem = FileSystemFactory.Create(options, password);
     fileSystem.TestEncryptionKey();
     return new ThreadSafeFileSystemTextManipulator(fileSystem);
 }
コード例 #16
0
ファイル: FileSystem.cs プロジェクト: RainsSoft/VFSPrototype
        public void Reload(FileSystemOptions newOptions)
        {
            newOptions.ApplyEncryptionSettings(_options);
            _options = newOptions;

            _blockAllocation = _options.BlockAllocation;
            // TODO: reload indexing service
            // SearchService.StartIndexing(_searchService, this);

            Root = LatestRoot = ImportRootFolder();
        }