github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/ctx_factory.go (about)

     1  package chat
     2  
     3  import (
     4  	"github.com/keybase/client/go/chat/globals"
     5  	"github.com/keybase/client/go/chat/types"
     6  	"github.com/keybase/client/go/protocol/keybase1"
     7  )
     8  
     9  type CtxFactory struct {
    10  	globals.Contextified
    11  }
    12  
    13  var _ types.ContextFactory = (*CtxFactory)(nil)
    14  
    15  func NewCtxFactory(g *globals.Context) types.ContextFactory {
    16  	return &CtxFactory{
    17  		Contextified: globals.NewContextified(g),
    18  	}
    19  }
    20  
    21  func (c *CtxFactory) NewKeyFinder() types.KeyFinder {
    22  	return NewKeyFinder(c.G())
    23  }
    24  
    25  func (c *CtxFactory) NewUPAKFinder() types.UPAKFinder {
    26  	return NewCachingUPAKFinder(c.G())
    27  }
    28  
    29  // For testing
    30  type mockCtxFactory struct {
    31  	globals.Contextified
    32  	cryptKeys []keybase1.CryptKey
    33  }
    34  
    35  var _ types.ContextFactory = (*mockCtxFactory)(nil)
    36  
    37  func newMockCtxFactory(g *globals.Context, cryptKeys []keybase1.CryptKey) types.ContextFactory {
    38  	return &mockCtxFactory{
    39  		Contextified: globals.NewContextified(g),
    40  		cryptKeys:    cryptKeys,
    41  	}
    42  }
    43  
    44  func (c *mockCtxFactory) NewKeyFinder() types.KeyFinder {
    45  	return NewKeyFinderMock(c.cryptKeys)
    46  }
    47  
    48  func (c *mockCtxFactory) NewUPAKFinder() types.UPAKFinder {
    49  	return NewCachingUPAKFinder(c.G())
    50  }