Implements encryption algorithm change

Implements compression algorithm change
This commit is contained in:
2017-11-02 11:30:03 +01:00
committed by BONNEVILLE Geoffroy
parent 82ef424365
commit 473a3700a7
3 changed files with 56 additions and 11 deletions

View File

@@ -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; }
}
/// <summary>
/// Open a KeePass database
/// </summary>
@@ -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());
}

View File

@@ -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">
<Page.Resources>
<CollectionViewSource x:Name="RecycleBinGroups" Source="{Binding Groups}" />
<CollectionViewSource x:Name="Ciphers" Source="{Binding Ciphers}" />
<CollectionViewSource x:Name="Compressions" Source="{Binding Compressions}" />
</Page.Resources>
<Page.DataContext>
<viewModels:SettingsDatabaseVm />
@@ -17,5 +18,9 @@
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ToggleSwitch Header="Recycle bin" OffContent="Disabled" OnContent="Enabled" IsOn="{Binding HasRecycleBin, Mode=TwoWay}" />
<ComboBox ItemsSource="{Binding Source={StaticResource RecycleBinGroups}}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" IsEnabled="{Binding HasRecycleBin}" />
<TextBlock Text="Encryption Algorithm" FontSize="14" Margin="5,20,0,10" />
<ComboBox ItemsSource="{Binding Source={StaticResource Ciphers}}" SelectedIndex="{Binding CipherIndex, Mode=TwoWay}" />
<TextBlock Text="Compression Algorithm" FontSize="14" Margin="5,20,0,10" />
<ComboBox ItemsSource="{Binding Source={StaticResource Compressions}}" SelectedItem="{Binding CompressionName, Mode=TwoWay}" />
</StackPanel>
</Page>

View File

@@ -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<GroupVm> Groups { get; set; }
public IEnumerable<string> 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<string> 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); }