identity.go

 1package bootstrap
 2
 3import (
 4	"fmt"
 5
 6	"github.com/ProtonMail/go-crypto/openpgp"
 7	"github.com/ProtonMail/go-crypto/openpgp/packet"
 8
 9	"github.com/MichaelMure/git-bug/repository"
10	"github.com/MichaelMure/git-bug/util/lamport"
11	"github.com/MichaelMure/git-bug/util/timestamp"
12)
13
14var ErrNoPrivateKey = fmt.Errorf("no private key")
15
16type Key interface {
17	Public() *packet.PublicKey
18	Private() *packet.PrivateKey
19	Validate() error
20	Clone() Key
21	PGPEntity() *openpgp.Entity
22
23	// EnsurePrivateKey attempt to load the corresponding private key if it is not loaded already.
24	// If no private key is found, returns ErrNoPrivateKey
25	EnsurePrivateKey(repo repository.RepoKeyring) error
26}
27
28type Identity interface {
29	Entity
30
31	// Name return the last version of the name
32	// Can be empty.
33	Name() string
34
35	// DisplayName return a non-empty string to display, representing the
36	// identity, based on the non-empty values.
37	DisplayName() string
38
39	// Email return the last version of the email
40	// Can be empty.
41	Email() string
42
43	// Login return the last version of the login
44	// Can be empty.
45	// Warning: this login can be defined when importing from a bridge but should *not* be
46	// used to identify an identity as multiple bridge with different login can map to the same
47	// identity. Use the metadata system for that usage instead.
48	Login() string
49
50	// AvatarUrl return the last version of the Avatar URL
51	// Can be empty.
52	AvatarUrl() string
53
54	// Keys return the last version of the valid keys
55	// Can be empty.
56	Keys() []Key
57
58	// SigningKey return the key that should be used to sign new messages. If no key is available, return nil.
59	SigningKey(repo repository.RepoKeyring) (Key, error)
60
61	// ValidKeysAtTime return the set of keys valid at a given lamport time for a given clock of another entity
62	// Can be empty.
63	ValidKeysAtTime(clockName string, time lamport.Time) []Key
64
65	// LastModification return the timestamp at which the last version of the identity became valid.
66	LastModification() timestamp.Timestamp
67
68	// LastModificationLamports return the lamport times at which the last version of the identity became valid.
69	LastModificationLamports() map[string]lamport.Time
70
71	// IsProtected return true if the chain of git commits started to be signed.
72	// If that's the case, only signed commit with a valid key for this identity can be added.
73	IsProtected() bool
74
75	// Validate check if the Identity data is valid
76	Validate() error
77
78	// NeedCommit indicate that the in-memory state changed and need to be committed in the repository
79	NeedCommit() bool
80}