aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/pgp/pgp.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto/pgp/pgp.go')
-rw-r--r--lib/crypto/pgp/pgp.go15
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
}