diff --git a/pkg/innerring/processors/container/common.go b/pkg/innerring/processors/container/common.go new file mode 100644 index 0000000000..46c044a976 --- /dev/null +++ b/pkg/innerring/processors/container/common.go @@ -0,0 +1,27 @@ +package container + +import ( + "fmt" + + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neofs-api-go/pkg/owner" +) + +type ownerIDSource interface { + OwnerID() *owner.ID +} + +func (cp *Processor) checkKeyOwnership(ownerIDSrc ownerIDSource, key *keys.PublicKey) error { + ownerKeys, err := cp.idClient.AccountKeys(ownerIDSrc.OwnerID()) + if err != nil { + return fmt.Errorf("could not received owner keys %s: %w", ownerIDSrc.OwnerID(), err) + } + + for _, ownerKey := range ownerKeys { + if ownerKey.Equal(key) { + return nil + } + } + + return fmt.Errorf("key %s is not tied to the owner of the container", key) +} diff --git a/pkg/innerring/processors/container/process_eacl.go b/pkg/innerring/processors/container/process_eacl.go index b5b2e5509b..5b3c797d1b 100644 --- a/pkg/innerring/processors/container/process_eacl.go +++ b/pkg/innerring/processors/container/process_eacl.go @@ -63,21 +63,8 @@ func (cp *Processor) checkEACLOwnership(binTable []byte, key *keys.PublicKey) er return fmt.Errorf("could not receive the container: %w", err) } - ownerID := cnr.OwnerID() - // check key ownership - ownerKeys, err := cp.idClient.AccountKeys(ownerID) - if err != nil { - return fmt.Errorf("could not received owner keys %s: %w", ownerID, err) - } - - for _, ownerKey := range ownerKeys { - if ownerKey.Equal(key) { - return nil - } - } - - return fmt.Errorf("key %s is not tied to the owner of the container", key) + return cp.checkKeyOwnership(cnr, key) } func (cp *Processor) approveSetEACL(e container.SetEACL) {