aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/crypto.go
blob: 54a20e688fc7f93ad501f2b9dcb7397a6c8f1e56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package crypto

import (
	"bytes"
	"io"
	"log"

	"git.sr.ht/~rjarry/aerc/lib/crypto/gpg"
	"git.sr.ht/~rjarry/aerc/lib/crypto/pgp"
	"git.sr.ht/~rjarry/aerc/models"
	"github.com/ProtonMail/go-crypto/openpgp"
	"github.com/emersion/go-message/mail"
)

type Provider interface {
	Decrypt(io.Reader, openpgp.PromptFunction) (*models.MessageDetails, error)
	Encrypt(*bytes.Buffer, []string, string, openpgp.PromptFunction, *mail.Header) (io.WriteCloser, error)
	Sign(*bytes.Buffer, string, openpgp.PromptFunction, *mail.Header) (io.WriteCloser, error)
	ImportKeys(io.Reader) error
	Init(*log.Logger) error
	Close()
	GetSignerKeyId(string) (string, error)
	GetKeyId(string) (string, error)
}

func New(s string) Provider {
	switch s {
	case "gpg":
		return &gpg.Mail{}
	default:
		return &pgp.Mail{}
	}
}