diff options
author | Robin Jarry <robin@jarry.cc> | 2022-12-06 12:00:14 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-12-06 17:52:43 +0100 |
commit | d25efff65aba373be44d1a514c35472bf52994e5 (patch) | |
tree | 3b1e6ea01cf85a7bdaf5795144d1cbce740b20bc /lib/crypto/pgp | |
parent | c1784b624aea6c93e398a90a4274abe158e72b8a (diff) | |
download | aerc-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/pgp')
-rw-r--r-- | lib/crypto/pgp/pgp.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/crypto/pgp/pgp.go b/lib/crypto/pgp/pgp.go index b2f5fa24..8d7c135a 100644 --- a/lib/crypto/pgp/pgp.go +++ b/lib/crypto/pgp/pgp.go @@ -28,6 +28,17 @@ var ( locked bool ) +func (m *Mail) KeyringExists() bool { + keypath := path.Join(xdg.DataHome(), "aerc", "keyring.asc") + keyfile, err := os.Open(keypath) + if err != nil { + return false + } + defer keyfile.Close() + _, err = openpgp.ReadKeyRing(keyfile) + return err == nil +} + func (m *Mail) Init() error { log.Debugf("Initializing PGP keyring") err := os.MkdirAll(path.Join(xdg.DataHome(), "aerc"), 0o700) @@ -50,13 +61,13 @@ func (m *Mail) Init() error { if os.IsNotExist(err) { return nil } else if err != nil { - panic(err) + return err } defer keyfile.Close() Keyring, err = openpgp.ReadKeyRing(keyfile) if err != nil { - panic(err) + return err } return nil } |