aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/crypto.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-06 12:00:14 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-06 17:52:43 +0100
commitd25efff65aba373be44d1a514c35472bf52994e5 (patch)
tree3b1e6ea01cf85a7bdaf5795144d1cbce740b20bc /lib/crypto/crypto.go
parentc1784b624aea6c93e398a90a4274abe158e72b8a (diff)
downloadaerc-d25efff65aba373be44d1a514c35472bf52994e5.tar.gz
pgp-provider: set default value to auto
Change the default provider to gpg unless the internal keyring is initialized and contains one key. This should be more user friendly. Link: https://lists.sr.ht/~rjarry/aerc-discuss/%3CCO783CI3IU9F.184DBQTPMIPBS%40paul%3E Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'lib/crypto/crypto.go')
-rw-r--r--lib/crypto/crypto.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/crypto/crypto.go b/lib/crypto/crypto.go
index b7afe638..cb026696 100644
--- a/lib/crypto/crypto.go
+++ b/lib/crypto/crypto.go
@@ -6,6 +6,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/crypto/gpg"
"git.sr.ht/~rjarry/aerc/lib/crypto/pgp"
+ "git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/emersion/go-message/mail"
@@ -25,10 +26,20 @@ type Provider interface {
func New(s string) Provider {
switch s {
+ case "auto":
+ internal := &pgp.Mail{}
+ if internal.KeyringExists() {
+ log.Debugf("internal pgp keyring exists")
+ return internal
+ }
+ log.Debugf("no internal pgp keyring, using system gpg")
+ fallthrough
case "gpg":
return &gpg.Mail{}
- default:
+ case "internal":
return &pgp.Mail{}
+ default:
+ return nil
}
}