feat(pgp): Add <ESC> to cancel password prompt
Previously there was no way to cancel the password prompt.
This commit is contained in:
parent
58db517c8d
commit
c32ab765a7
2 changed files with 19 additions and 10 deletions
|
@ -537,11 +537,11 @@ func (aerc *Aerc) CloseBackends() error {
|
||||||
return returnErr
|
return returnErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aerc *Aerc) GetPassword(title string, prompt string, cb func(string)) {
|
func (aerc *Aerc) GetPassword(title string, prompt string, cb func(string, error)) {
|
||||||
aerc.getpasswd = NewGetPasswd(title, prompt, func(pw string) {
|
aerc.getpasswd = NewGetPasswd(title, prompt, func(pw string, err error) {
|
||||||
aerc.getpasswd = nil
|
aerc.getpasswd = nil
|
||||||
aerc.Invalidate()
|
aerc.Invalidate()
|
||||||
cb(pw)
|
cb(pw, err)
|
||||||
})
|
})
|
||||||
aerc.getpasswd.OnInvalidate(func(_ ui.Drawable) {
|
aerc.getpasswd.OnInvalidate(func(_ ui.Drawable) {
|
||||||
aerc.Invalidate()
|
aerc.Invalidate()
|
||||||
|
@ -553,7 +553,7 @@ func (aerc *Aerc) Initialize(ui *ui.UI) {
|
||||||
aerc.ui = ui
|
aerc.ui = ui
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) ([]byte, error) {
|
func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, err error) {
|
||||||
// HACK HACK HACK
|
// HACK HACK HACK
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
var ident *openpgp.Identity
|
var ident *openpgp.Identity
|
||||||
|
@ -561,14 +561,18 @@ func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) ([]byte, error
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
aerc.GetPassword("Decrypt PGP private key",
|
aerc.GetPassword("Decrypt PGP private key",
|
||||||
fmt.Sprintf("Enter password for %s (%8X)",
|
fmt.Sprintf("Enter password for %s (%8X)\nPress <ESC> to cancel",
|
||||||
ident.Name, key.PublicKey.KeyId),
|
ident.Name, key.PublicKey.KeyId),
|
||||||
func(pass string) {
|
func(pass string, e error) {
|
||||||
|
if e != nil {
|
||||||
|
err = e
|
||||||
|
return
|
||||||
|
}
|
||||||
key.PrivateKey.Decrypt([]byte(pass))
|
key.PrivateKey.Decrypt([]byte(pass))
|
||||||
})
|
})
|
||||||
for aerc.getpasswd != nil {
|
for aerc.getpasswd != nil {
|
||||||
aerc.ui.Tick()
|
aerc.ui.Tick()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc/lib/ui"
|
"git.sr.ht/~sircmpwn/aerc/lib/ui"
|
||||||
|
@ -8,13 +10,13 @@ import (
|
||||||
|
|
||||||
type GetPasswd struct {
|
type GetPasswd struct {
|
||||||
ui.Invalidatable
|
ui.Invalidatable
|
||||||
callback func(string)
|
callback func(string, error)
|
||||||
title string
|
title string
|
||||||
prompt string
|
prompt string
|
||||||
input *ui.TextInput
|
input *ui.TextInput
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGetPasswd(title string, prompt string, cb func(string)) *GetPasswd {
|
func NewGetPasswd(title string, prompt string, cb func(string, error)) *GetPasswd {
|
||||||
getpasswd := &GetPasswd{
|
getpasswd := &GetPasswd{
|
||||||
callback: cb,
|
callback: cb,
|
||||||
title: title,
|
title: title,
|
||||||
|
@ -46,7 +48,10 @@ func (gp *GetPasswd) Event(event tcell.Event) bool {
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
case tcell.KeyEnter:
|
case tcell.KeyEnter:
|
||||||
gp.input.Focus(false)
|
gp.input.Focus(false)
|
||||||
gp.callback(gp.input.String())
|
gp.callback(gp.input.String(), nil)
|
||||||
|
case tcell.KeyEsc:
|
||||||
|
gp.input.Focus(false)
|
||||||
|
gp.callback("", fmt.Errorf("no password provided"))
|
||||||
default:
|
default:
|
||||||
gp.input.Event(event)
|
gp.input.Event(event)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue