-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMultiCipherExt.cs
111 lines (78 loc) · 3.28 KB
/
MultiCipherExt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
MultiCipher Plugin for Keepass Password Safe
Copyright (C) 2019 Titas Raha <support@titasraha.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Diagnostics;
using System.Windows.Forms;
using KeePass.Plugins;
using KeePass.UI;
using KeePassLib;
using KeePassLib.Utility;
namespace MultiCipher
{
public sealed class MultiCipherExt:Plugin
{
private Configuration m_Config;
private ToolStripMenuItem m_MultiCipherMenuItem;
private static MultiCipherEngine m_Level2CipherEngine = new MultiCipherEngine();
public override bool Initialize(IPluginHost host)
{
if (host == null) return false;
Debug.Assert(m_Level2CipherEngine != null);
if (m_Level2CipherEngine == null) return false;
m_Config = new Configuration(host);
m_Level2CipherEngine.SetConfig(m_Config);
host.CipherPool.AddCipher(m_Level2CipherEngine);
host.MainWindow.ToolsMenu.DropDownOpening += OnToolsMenu;
return true;
}
public override void Terminate()
{
Debug.Assert(m_Config != null);
m_Config.Host.MainWindow.ToolsMenu.DropDownOpening -= OnToolsMenu;
}
private bool IsValidMultiCipherDatabase()
{
Debug.Assert(m_Level2CipherEngine != null && m_Config != null && m_Config.Host != null);
PwDatabase pd = m_Config.Host.Database;
return ((pd != null) && pd.IsOpen && m_Level2CipherEngine.CipherUuid.Equals(pd.DataCipherUuid));
}
private void OnToolsMenu(object sender, EventArgs e)
{
bool bOpen = IsValidMultiCipherDatabase();
if (m_MultiCipherMenuItem != null)
m_MultiCipherMenuItem.Enabled = bOpen;
}
public override ToolStripMenuItem GetMenuItem(PluginMenuType t)
{
if (t != PluginMenuType.Main) return null;
ToolStripMenuItem tsmi = new ToolStripMenuItem("MultiCipher Encryption Settings...");
tsmi.Click += OnShowSetting;
m_MultiCipherMenuItem = tsmi;
return tsmi;
}
private void OnShowSetting(object sender, EventArgs e)
{
bool IsValid = IsValidMultiCipherDatabase();
Debug.Assert(IsValid);
if (IsValid)
{
var form = new Settings(m_Config);
UIUtil.ShowDialogAndDestroy(form);
}
else
MessageService.ShowWarning("MultiCipher Plugin:", "Not a valid MultiCipher Database");
}
}
}