get.porter.sh/porter@v1.3.0/pkg/signing/plugins/mock/mock.go (about) 1 package mock 2 3 import ( 4 "context" 5 b64 "encoding/base64" 6 7 "get.porter.sh/porter/pkg/signing/plugins" 8 "get.porter.sh/porter/pkg/tracing" 9 ) 10 11 var _ plugins.SigningProtocol = &Signer{} 12 13 // Signer implements an in-memory signer for testing. 14 type Signer struct { 15 Signatures map[string]string 16 } 17 18 func NewSigner() *Signer { 19 s := &Signer{ 20 Signatures: make(map[string]string), 21 } 22 23 return s 24 } 25 26 func (s *Signer) Connect(ctx context.Context) error { 27 _, log := tracing.StartSpan(ctx) 28 defer log.EndSpan() 29 return nil 30 } 31 32 func (s *Signer) Sign(ctx context.Context, ref string) error { 33 _, log := tracing.StartSpan(ctx) 34 defer log.EndSpan() 35 36 s.Signatures[ref] = b64.StdEncoding.EncodeToString([]byte(ref)) 37 return nil 38 } 39 40 func (s *Signer) Verify(ctx context.Context, ref string) error { 41 _, log := tracing.StartSpan(ctx) 42 defer log.EndSpan() 43 44 if _, ok := s.Signatures[ref]; !ok { 45 return log.Errorf("%s is not signed", ref) 46 } 47 48 return nil 49 }