2022-04-25 13:30:43 +00:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
|
2022-04-25 13:30:44 +00:00
|
|
|
"git.sr.ht/~rjarry/aerc/lib/crypto/gpg"
|
2022-04-25 13:30:43 +00:00
|
|
|
"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()
|
2022-04-29 16:19:52 +00:00
|
|
|
GetSignerKeyId(string) (string, error)
|
2022-04-25 13:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(s string) Provider {
|
|
|
|
switch s {
|
2022-04-25 13:30:44 +00:00
|
|
|
case "gpg":
|
|
|
|
return &gpg.Mail{}
|
2022-04-25 13:30:43 +00:00
|
|
|
default:
|
|
|
|
return &pgp.Mail{}
|
|
|
|
}
|
|
|
|
}
|