about summary refs log tree commit diff stats
path: root/widgets/aerc.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-03-03 16:20:07 -0500
committerDrew DeVault <sir@cmpwn.com>2020-03-03 16:49:52 -0500
commitf3158b36f1f210ff54febbe82b571c1379b30c98 (patch)
tree10cde839c9517609f55b8f1057b1cf84ac592632 /widgets/aerc.go
parent89f1684ea4b5e680db7ff06a54b2d4e78212cd12 (diff)
downloadaerc-f3158b36f1f210ff54febbe82b571c1379b30c98.tar.gz
Initial support for PGP decryption & signatures
Diffstat (limited to 'widgets/aerc.go')
-rw-r--r--widgets/aerc.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index a9be47e..e6d2525 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -2,6 +2,7 @@ package widgets
 
 import (
 	"errors"
+	"fmt"
 	"io"
 	"log"
 	"net/url"
@@ -10,6 +11,7 @@ import (
 
 	"github.com/gdamore/tcell"
 	"github.com/google/shlex"
+	"golang.org/x/crypto/openpgp"
 
 	"git.sr.ht/~sircmpwn/aerc/config"
 	"git.sr.ht/~sircmpwn/aerc/lib"
@@ -32,7 +34,9 @@ type Aerc struct {
 	pendingKeys []config.KeyStroke
 	prompts     *ui.Stack
 	tabs        *ui.Tabs
+	ui          *ui.UI
 	beep        func() error
+	getpasswd   *GetPasswd
 }
 
 func NewAerc(conf *config.AercConfig, logger *log.Logger,
@@ -160,6 +164,10 @@ func (aerc *Aerc) Focus(focus bool) {
 
 func (aerc *Aerc) Draw(ctx *ui.Context) {
 	aerc.grid.Draw(ctx)
+	if aerc.getpasswd != nil {
+		aerc.getpasswd.Draw(ctx.Subcontext(4, 4,
+			ctx.Width()-8, ctx.Height()-8))
+	}
 }
 
 func (aerc *Aerc) getBindings() *config.KeyBindings {
@@ -198,6 +206,10 @@ func (aerc *Aerc) simulate(strokes []config.KeyStroke) {
 }
 
 func (aerc *Aerc) Event(event tcell.Event) bool {
+	if aerc.getpasswd != nil {
+		return aerc.getpasswd.Event(event)
+	}
+
 	if aerc.focused != nil {
 		return aerc.focused.Event(event)
 	}
@@ -484,3 +496,39 @@ func (aerc *Aerc) CloseBackends() error {
 	}
 	return returnErr
 }
+
+func (aerc *Aerc) GetPassword(title string, prompt string, cb func(string)) {
+	aerc.getpasswd = NewGetPasswd(title, prompt, func(pw string) {
+		aerc.getpasswd = nil
+		aerc.Invalidate()
+		cb(pw)
+	})
+	aerc.getpasswd.OnInvalidate(func(_ ui.Drawable) {
+		aerc.Invalidate()
+	})
+	aerc.Invalidate()
+}
+
+func (aerc *Aerc) Initialize(ui *ui.UI) {
+	aerc.ui = ui
+}
+
+func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) ([]byte, error) {
+	// HACK HACK HACK
+	for _, key := range keys {
+		var ident *openpgp.Identity
+		for _, ident = range key.Entity.Identities {
+			break
+		}
+		aerc.GetPassword("Decrypt PGP private key",
+			fmt.Sprintf("Enter password for %s (%8X)",
+				ident.Name, key.PublicKey.KeyId),
+			func(pass string) {
+				key.PrivateKey.Decrypt([]byte(pass))
+			})
+		for aerc.getpasswd != nil {
+			aerc.ui.Tick()
+		}
+	}
+	return nil, nil
+}