From d09636ee0b9957ed60fc01224ddfbb03c4f4b7fa Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 25 Apr 2022 08:30:43 -0500 Subject: refactor: refactor pgp implementation This commit refactors the internal PGP implementation to make way for GPG integration. Signed-off-by: Tim Culverhouse Acked-by: Koni Marti Acked-by: Robin Jarry --- widgets/pgpinfo.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'widgets/pgpinfo.go') diff --git a/widgets/pgpinfo.go b/widgets/pgpinfo.go index 6c07ed9..8dc0570 100644 --- a/widgets/pgpinfo.go +++ b/widgets/pgpinfo.go @@ -1,22 +1,18 @@ package widgets import ( - "errors" - "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/ui" - - "github.com/ProtonMail/go-crypto/openpgp" - pgperrors "github.com/ProtonMail/go-crypto/openpgp/errors" + "git.sr.ht/~rjarry/aerc/models" ) type PGPInfo struct { ui.Invalidatable - details *openpgp.MessageDetails + details *models.MessageDetails uiConfig config.UIConfig } -func NewPGPInfo(details *openpgp.MessageDetails, uiConfig config.UIConfig) *PGPInfo { +func NewPGPInfo(details *models.MessageDetails, uiConfig config.UIConfig) *PGPInfo { return &PGPInfo{details: details, uiConfig: uiConfig} } @@ -27,38 +23,33 @@ func (p *PGPInfo) DrawSignature(ctx *ui.Context) { defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT) // TODO: Nicer prompt for TOFU, fetch from keyserver, etc - if errors.Is(p.details.SignatureError, pgperrors.ErrUnknownIssuer) || - p.details.SignedBy == nil { + if p.details.SignatureValidity == models.UnknownEntity || + p.details.SignedBy == "" { x := ctx.Printf(0, 0, warningStyle, "*") x += ctx.Printf(x, 0, defaultStyle, " Signed with unknown key (%8X); authenticity unknown", p.details.SignedByKeyId) - } else if p.details.SignatureError != nil { + } else if p.details.SignatureValidity != models.Valid { x := ctx.Printf(0, 0, errorStyle, "Invalid signature!") x += ctx.Printf(x, 0, errorStyle, " This message may have been tampered with! (%s)", - p.details.SignatureError.Error()) + p.details.SignatureError) } else { - entity := p.details.SignedBy.Entity - ident := entity.PrimaryIdentity() - x := ctx.Printf(0, 0, validStyle, "✓ Authentic ") x += ctx.Printf(x, 0, defaultStyle, "Signature from %s (%8X)", - ident.Name, p.details.SignedByKeyId) + p.details.SignedBy, p.details.SignedByKeyId) } } func (p *PGPInfo) DrawEncryption(ctx *ui.Context, y int) { validStyle := p.uiConfig.GetStyle(config.STYLE_SUCCESS) defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT) - entity := p.details.DecryptedWith.Entity - ident := entity.PrimaryIdentity() x := ctx.Printf(0, y, validStyle, "✓ Encrypted ") x += ctx.Printf(x, y, defaultStyle, - "To %s (%8X) ", ident.Name, p.details.DecryptedWith.PublicKey.KeyId) + "To %s (%8X) ", p.details.DecryptedWith, p.details.DecryptedWithKeyId) } func (p *PGPInfo) Draw(ctx *ui.Context) { -- cgit v1.2.3