Simplify PGP messaging

This commit is contained in:
Drew DeVault 2020-03-03 19:02:27 -05:00
parent 403b6af379
commit f79813ada3

View file

@ -19,29 +19,22 @@ func NewPGPInfo(details *openpgp.MessageDetails) *PGPInfo {
return &PGPInfo{details: details}
}
func (p *PGPInfo) DrawSignature(ctx *ui.Context, offs bool) {
func (p *PGPInfo) DrawSignature(ctx *ui.Context) {
errorStyle := tcell.StyleDefault.Background(tcell.ColorRed).
Foreground(tcell.ColorWhite).Bold(true)
softErrorStyle := tcell.StyleDefault.Foreground(tcell.ColorYellow).
Reverse(true).Bold(true)
softErrorStyle := tcell.StyleDefault.Foreground(tcell.ColorYellow).Bold(true)
validStyle := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)
header := "Signature "
if offs {
header += " "
}
// TODO: Nicer prompt for TOFU, fetch from keyserver, etc
if errors.Is(p.details.SignatureError, pgperrors.ErrUnknownIssuer) ||
p.details.SignedBy == nil {
x := ctx.Printf(0, 0, tcell.StyleDefault.Bold(true), "%s", header)
x += ctx.Printf(x, 0, softErrorStyle, " Unknown ")
x := ctx.Printf(0, 0, softErrorStyle, "*")
x += ctx.Printf(x, 0, tcell.StyleDefault,
" Signed with unknown key (%8X); authenticity unknown",
p.details.SignedByKeyId)
} else if p.details.SignatureError != nil {
x := ctx.Printf(0, 0, tcell.StyleDefault.Bold(true), "%s", header)
x += ctx.Printf(x, 0, errorStyle, " ✗ Invalid! ")
x := ctx.Printf(0, 0, errorStyle, "Invalid signature!")
x += ctx.Printf(x, 0, tcell.StyleDefault.
Foreground(tcell.ColorRed).Bold(true),
" This message may have been tampered with! (%s)",
@ -53,11 +46,10 @@ func (p *PGPInfo) DrawSignature(ctx *ui.Context, offs bool) {
for _, ident = range entity.Identities {
break
}
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', validStyle)
x := ctx.Printf(0, 0, tcell.StyleDefault.Bold(true), "%s", header)
x += ctx.Printf(x, 0, validStyle, "✓ Signed ")
x := ctx.Printf(0, 0, validStyle, "✓ ")
x += ctx.Printf(x, 0, tcell.StyleDefault,
"by %s (%8X)", ident.Name, p.details.SignedByKeyId)
"Authentic signature from %s (%8X)",
ident.Name, p.details.SignedByKeyId)
}
}
@ -70,19 +62,18 @@ func (p *PGPInfo) DrawEncryption(ctx *ui.Context, y int) {
break
}
x := ctx.Printf(0, y, tcell.StyleDefault.Bold(true), "Encryption ")
x += ctx.Printf(x, y, validStyle, "✓ Encrypted ")
x := ctx.Printf(0, y, validStyle, "✓ ")
x += ctx.Printf(x, y, tcell.StyleDefault,
"for %s (%8X) ", ident.Name, p.details.DecryptedWith.PublicKey.KeyId)
"Encrypted for %s (%8X) ", ident.Name, p.details.DecryptedWith.PublicKey.KeyId)
}
func (p *PGPInfo) Draw(ctx *ui.Context) {
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
if p.details.IsSigned && p.details.IsEncrypted {
p.DrawSignature(ctx, true)
p.DrawSignature(ctx)
p.DrawEncryption(ctx, 1)
} else if p.details.IsSigned {
p.DrawSignature(ctx, false)
p.DrawSignature(ctx)
} else if p.details.IsEncrypted {
p.DrawEncryption(ctx, 0)
}