forked from keybase/client
/
pgp_ui.go
68 lines (57 loc) · 1.95 KB
/
pgp_ui.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"fmt"
"io"
humanize "github.com/dustin/go-humanize"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
"golang.org/x/net/context"
)
type PgpUI struct {
w io.Writer
}
func NewPgpUIProtocol(g *libkb.GlobalContext) rpc.Protocol {
return keybase1.PGPUiProtocol(g.UI.GetPgpUI())
}
func (p PgpUI) OutputSignatureSuccess(_ context.Context, arg keybase1.OutputSignatureSuccessArg) error {
signedAt := keybase1.FromTime(arg.SignedAt)
un := ColorString("bold", arg.Username)
output := func(fmtString string, args ...interface{}) {
s := fmt.Sprintf(fmtString, args...)
s = ColorString("green", s)
p.w.Write([]byte(s))
}
if signedAt.IsZero() {
output("Signature verified. Signed by %s.\n", un)
} else {
output("Signature verified. Signed by %s %s (%s).\n", un, humanize.Time(signedAt), signedAt)
}
output("PGP Fingerprint: %s.\n", arg.Fingerprint)
return nil
}
func (p PgpUI) OutputSignatureSuccessNonKeybase(ctx context.Context, arg keybase1.OutputSignatureSuccessNonKeybaseArg) error {
signedAt := keybase1.FromTime(arg.SignedAt)
output := func(fmtString string, args ...interface{}) {
s := fmt.Sprintf(fmtString, args...)
s = ColorString("green", s)
p.w.Write([]byte(s))
}
if signedAt.IsZero() {
output("Signature verified. Signed by key %s (unknown to keybase).\n", arg.KeyID)
} else {
output("Signature verified. Signed by key %s (unknown to keybase) %s (%s).\n", arg.KeyID, humanize.Time(signedAt), signedAt)
}
return nil
}
func (p PgpUI) KeyGenerated(ctx context.Context, arg keybase1.KeyGeneratedArg) error {
return nil
}
func (p PgpUI) ShouldPushPrivate(ctx context.Context, sessionID int) (bool, error) {
return false, nil
}
func (p PgpUI) Finished(ctx context.Context, sessionID int) error {
return nil
}