/
ctx_factory.go
50 lines (39 loc) · 1.1 KB
/
ctx_factory.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
package chat
import (
"github.com/keybase/client/go/chat/globals"
"github.com/keybase/client/go/chat/types"
"github.com/keybase/client/go/protocol/keybase1"
)
type CtxFactory struct {
globals.Contextified
}
var _ types.ContextFactory = (*CtxFactory)(nil)
func NewCtxFactory(g *globals.Context) types.ContextFactory {
return &CtxFactory{
Contextified: globals.NewContextified(g),
}
}
func (c *CtxFactory) NewKeyFinder() types.KeyFinder {
return NewKeyFinder(c.G())
}
func (c *CtxFactory) NewUPAKFinder() types.UPAKFinder {
return NewCachingUPAKFinder(c.G())
}
// For testing
type mockCtxFactory struct {
globals.Contextified
cryptKeys []keybase1.CryptKey
}
var _ types.ContextFactory = (*mockCtxFactory)(nil)
func newMockCtxFactory(g *globals.Context, cryptKeys []keybase1.CryptKey) types.ContextFactory {
return &mockCtxFactory{
Contextified: globals.NewContextified(g),
cryptKeys: cryptKeys,
}
}
func (c *mockCtxFactory) NewKeyFinder() types.KeyFinder {
return NewKeyFinderMock(c.cryptKeys)
}
func (c *mockCtxFactory) NewUPAKFinder() types.UPAKFinder {
return NewCachingUPAKFinder(c.G())
}