forked from xtaci/safebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadkey.go
77 lines (64 loc) · 1.74 KB
/
loadkey.go
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
package main
import (
"fmt"
"os"
"github.com/rivo/tview"
)
var loadKeyWindowTitle = "-=- LOAD MASTER KEY -=-"
var loadKeyPasswordTitle = "-=- PASSWORD TO DECRYPT MASTER KEY -=-"
func showLoadPassword(parent string, path string) {
windowName := "showLoadPassword"
form := tview.NewForm()
form.SetBorder(true)
form.SetTitle(loadKeyPasswordTitle)
passwordField := tview.NewInputField().SetLabel("Password").
SetFieldWidth(64).
SetMaskCharacter('*')
form.AddButton("OK", func() {
// create a master key
masterKeyToLoad := newMasterKey()
err := masterKeyToLoad.load([]byte(passwordField.GetText()), path)
if err != nil {
showFailWindow("FAILURE", err.Error())
root.RemovePage(windowName)
} else {
showSuccessWindow("SUCCESS", fmt.Sprintf("Successfully Loaded Master Key!!!\n%v", path), func() {
masterKey = masterKeyToLoad
masterKey.path = path
info = infoWindow()
mainFrame = mainFrameWindow()
refreshBody()
root.RemovePage(windowName)
root.RemovePage(parent)
})
}
})
form.AddFormItem(passwordField)
form.SetFocus(0)
root.AddPage(windowName, popup(40, 7, form), true, true)
}
func showLoadKeyWindow() {
windowName := "showLoadKeyWindow"
// path input field
path, err := os.Getwd()
if err != nil {
panic(err)
}
form := tview.NewForm()
// input field setting
inputField := tview.NewInputField().
SetLabel("Path: ").
SetText(path + "/.safebox.key").
SetFieldWidth(64)
form.AddFormItem(inputField)
form.AddButton("Load", func() {
showLoadPassword(windowName, inputField.GetText())
})
form.AddButton("...", func() {
showDirWindow(inputField)
})
form.SetBorder(true)
form.SetTitle(loadKeyWindowTitle)
form.SetFocus(0)
root.AddPage(windowName, popup(80, 7, form), true, true)
}