Simplify PGP messaging
This commit is contained in:
parent
403b6af379
commit
f79813ada3
|
@ -19,29 +19,22 @@ func NewPGPInfo(details *openpgp.MessageDetails) *PGPInfo {
|
||||||
return &PGPInfo{details: details}
|
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).
|
errorStyle := tcell.StyleDefault.Background(tcell.ColorRed).
|
||||||
Foreground(tcell.ColorWhite).Bold(true)
|
Foreground(tcell.ColorWhite).Bold(true)
|
||||||
softErrorStyle := tcell.StyleDefault.Foreground(tcell.ColorYellow).
|
softErrorStyle := tcell.StyleDefault.Foreground(tcell.ColorYellow).Bold(true)
|
||||||
Reverse(true).Bold(true)
|
|
||||||
validStyle := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)
|
validStyle := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)
|
||||||
header := "Signature "
|
|
||||||
if offs {
|
|
||||||
header += " "
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Nicer prompt for TOFU, fetch from keyserver, etc
|
// TODO: Nicer prompt for TOFU, fetch from keyserver, etc
|
||||||
if errors.Is(p.details.SignatureError, pgperrors.ErrUnknownIssuer) ||
|
if errors.Is(p.details.SignatureError, pgperrors.ErrUnknownIssuer) ||
|
||||||
p.details.SignedBy == nil {
|
p.details.SignedBy == nil {
|
||||||
|
|
||||||
x := ctx.Printf(0, 0, tcell.StyleDefault.Bold(true), "%s", header)
|
x := ctx.Printf(0, 0, softErrorStyle, "*")
|
||||||
x += ctx.Printf(x, 0, softErrorStyle, " Unknown ")
|
|
||||||
x += ctx.Printf(x, 0, tcell.StyleDefault,
|
x += ctx.Printf(x, 0, tcell.StyleDefault,
|
||||||
" Signed with unknown key (%8X); authenticity unknown",
|
" Signed with unknown key (%8X); authenticity unknown",
|
||||||
p.details.SignedByKeyId)
|
p.details.SignedByKeyId)
|
||||||
} else if p.details.SignatureError != nil {
|
} else if p.details.SignatureError != nil {
|
||||||
x := ctx.Printf(0, 0, tcell.StyleDefault.Bold(true), "%s", header)
|
x := ctx.Printf(0, 0, errorStyle, "Invalid signature!")
|
||||||
x += ctx.Printf(x, 0, errorStyle, " ✗ Invalid! ")
|
|
||||||
x += ctx.Printf(x, 0, tcell.StyleDefault.
|
x += ctx.Printf(x, 0, tcell.StyleDefault.
|
||||||
Foreground(tcell.ColorRed).Bold(true),
|
Foreground(tcell.ColorRed).Bold(true),
|
||||||
" This message may have been tampered with! (%s)",
|
" 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 {
|
for _, ident = range entity.Identities {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', validStyle)
|
x := ctx.Printf(0, 0, validStyle, "✓ ")
|
||||||
x := ctx.Printf(0, 0, tcell.StyleDefault.Bold(true), "%s", header)
|
|
||||||
x += ctx.Printf(x, 0, validStyle, "✓ Signed ")
|
|
||||||
x += ctx.Printf(x, 0, tcell.StyleDefault,
|
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
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
x := ctx.Printf(0, y, tcell.StyleDefault.Bold(true), "Encryption ")
|
x := ctx.Printf(0, y, validStyle, "✓ ")
|
||||||
x += ctx.Printf(x, y, validStyle, "✓ Encrypted ")
|
|
||||||
x += ctx.Printf(x, y, tcell.StyleDefault,
|
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) {
|
func (p *PGPInfo) Draw(ctx *ui.Context) {
|
||||||
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
|
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
|
||||||
if p.details.IsSigned && p.details.IsEncrypted {
|
if p.details.IsSigned && p.details.IsEncrypted {
|
||||||
p.DrawSignature(ctx, true)
|
p.DrawSignature(ctx)
|
||||||
p.DrawEncryption(ctx, 1)
|
p.DrawEncryption(ctx, 1)
|
||||||
} else if p.details.IsSigned {
|
} else if p.details.IsSigned {
|
||||||
p.DrawSignature(ctx, false)
|
p.DrawSignature(ctx)
|
||||||
} else if p.details.IsEncrypted {
|
} else if p.details.IsEncrypted {
|
||||||
p.DrawEncryption(ctx, 0)
|
p.DrawEncryption(ctx, 0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue