From 473a3700a72396247b4858ac5d0e84ad66bdb885 Mon Sep 17 00:00:00 2001 From: Geoffroy Bonneville Date: Thu, 2 Nov 2017 11:30:03 +0100 Subject: [PATCH] Implements encryption algorithm change Implements compression algorithm change --- ModernKeePass/Common/DatabaseHelper.cs | 25 +++++++------ .../SettingsDatabasePage.xaml | 7 +++- .../ViewModels/SettingsDatabaseVm.cs | 35 +++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/ModernKeePass/Common/DatabaseHelper.cs b/ModernKeePass/Common/DatabaseHelper.cs index 4388974..fe6a42d 100644 --- a/ModernKeePass/Common/DatabaseHelper.cs +++ b/ModernKeePass/Common/DatabaseHelper.cs @@ -1,9 +1,9 @@ using System; using Windows.Storage; -using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using ModernKeePass.ViewModels; using ModernKeePassLib; +using ModernKeePassLib.Cryptography.Cipher; using ModernKeePassLib.Interfaces; using ModernKeePassLib.Keys; using ModernKeePassLib.Serialization; @@ -33,7 +33,7 @@ namespace ModernKeePass.Common _pwDatabase.RecycleBinUuid = _recycleBin.IdUuid; } } - + public DatabaseStatus Status { get; private set; } = DatabaseStatus.Closed; public string Name => DatabaseFile?.Name; @@ -52,7 +52,19 @@ namespace ModernKeePass.Common Status = DatabaseStatus.Opening; } } - + + public PwUuid DataCipher + { + get { return _pwDatabase.DataCipherUuid; } + internal set { _pwDatabase.DataCipherUuid = value; } + } + + public PwCompressionAlgorithm CompressionAlgorithm + { + get { return _pwDatabase.Compression; } + set { _pwDatabase.Compression = value; } + } + /// /// Open a KeePass database /// @@ -107,13 +119,6 @@ namespace ModernKeePass.Common public void Save() { if (_pwDatabase == null || !_pwDatabase.IsOpen) return; - // Commit real changes to DB - /*var app = (App) Application.Current; - foreach (var entity in app.PendingDeleteEntities) - { - entity.Value.CommitDelete(); - } - app.PendingDeleteEntities.Clear();*/ _pwDatabase.Save(new NullStatusLogger()); } diff --git a/ModernKeePass/Pages/SettingsPageFrames/SettingsDatabasePage.xaml b/ModernKeePass/Pages/SettingsPageFrames/SettingsDatabasePage.xaml index 8357e3e..7087abc 100644 --- a/ModernKeePass/Pages/SettingsPageFrames/SettingsDatabasePage.xaml +++ b/ModernKeePass/Pages/SettingsPageFrames/SettingsDatabasePage.xaml @@ -2,13 +2,14 @@ x:Class="ModernKeePass.Pages.SettingsDatabasePage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:ModernKeePass.Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="using:ModernKeePass.ViewModels" mc:Ignorable="d"> + + @@ -17,5 +18,9 @@ + + + + diff --git a/ModernKeePass/ViewModels/SettingsDatabaseVm.cs b/ModernKeePass/ViewModels/SettingsDatabaseVm.cs index 9069fb4..ff67b3b 100644 --- a/ModernKeePass/ViewModels/SettingsDatabaseVm.cs +++ b/ModernKeePass/ViewModels/SettingsDatabaseVm.cs @@ -1,10 +1,13 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Windows.Storage; using Windows.UI.Xaml; using ModernKeePass.Common; using ModernKeePass.Interfaces; +using ModernKeePassLib; +using ModernKeePassLib.Cryptography.Cipher; namespace ModernKeePass.ViewModels { @@ -26,6 +29,38 @@ namespace ModernKeePass.ViewModels public ObservableCollection Groups { get; set; } + public IEnumerable Ciphers + { + get + { + for (var inx = 0; inx < CipherPool.GlobalPool.EngineCount; inx++) + { + yield return CipherPool.GlobalPool[inx].DisplayName; + } + } + } + + public int CipherIndex + { + get + { + for (var inx = 0; inx < CipherPool.GlobalPool.EngineCount; ++inx) + { + if (CipherPool.GlobalPool[inx].CipherUuid.Equals(_app.Database.DataCipher)) return inx; + } + return -1; + } + set { _app.Database.DataCipher = CipherPool.GlobalPool[value].CipherUuid; } + } + + public IEnumerable Compressions => Enum.GetNames(typeof(PwCompressionAlgorithm)).Take((int)PwCompressionAlgorithm.Count); + + public string CompressionName + { + get { return Enum.GetName(typeof(PwCompressionAlgorithm), _app.Database.CompressionAlgorithm); } + set { _app.Database.CompressionAlgorithm = (PwCompressionAlgorithm)Enum.Parse(typeof(PwCompressionAlgorithm), value); } + } + public ISelectableModel SelectedItem { get { return Groups.FirstOrDefault(g => g.IsSelected); }