github.com/ethersphere/bee/v2@v2.2.0/pkg/accesscontrol/mock/grantee.go (about) 1 // Copyright 2024 The Swarm Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package mock 6 7 import ( 8 "crypto/ecdsa" 9 10 "github.com/ethersphere/bee/v2/pkg/swarm" 11 ) 12 13 type GranteeListMock interface { 14 Add(publicKeys []*ecdsa.PublicKey) error 15 Remove(removeList []*ecdsa.PublicKey) error 16 Get() []*ecdsa.PublicKey 17 Save() (swarm.Address, error) 18 } 19 20 type GranteeListStructMock struct { 21 grantees []*ecdsa.PublicKey 22 } 23 24 func (g *GranteeListStructMock) Get() []*ecdsa.PublicKey { 25 grantees := g.grantees 26 keys := make([]*ecdsa.PublicKey, len(grantees)) 27 copy(keys, grantees) 28 return keys 29 } 30 31 func (g *GranteeListStructMock) Add(addList []*ecdsa.PublicKey) error { 32 g.grantees = append(g.grantees, addList...) 33 return nil 34 } 35 36 func (g *GranteeListStructMock) Remove(removeList []*ecdsa.PublicKey) error { 37 for _, remove := range removeList { 38 for i, grantee := range g.grantees { 39 if *grantee == *remove { 40 g.grantees[i] = g.grantees[len(g.grantees)-1] 41 g.grantees = g.grantees[:len(g.grantees)-1] 42 } 43 } 44 } 45 46 return nil 47 } 48 49 func (g *GranteeListStructMock) Save() (swarm.Address, error) { 50 return swarm.EmptyAddress, nil 51 } 52 53 func NewGranteeList() *GranteeListStructMock { 54 return &GranteeListStructMock{grantees: []*ecdsa.PublicKey{}} 55 }