From 70a7354e9ddc5344a58b42deffe21cc7768cb325 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 31 May 2021 13:30:59 +0300 Subject: [PATCH] [#570] *: Use new Equal method of owner.ID type Signed-off-by: Leonard Lyubich --- pkg/core/object/fmt.go | 5 ++--- pkg/innerring/processors/settlement/common/util.go | 5 +++-- pkg/services/object/acl/acl.go | 7 +------ pkg/services/object/acl/classifier.go | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index 29ef45b27..81a9e2650 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -115,9 +115,8 @@ func (v *FormatValidator) checkOwnerKey(id *owner.ID, key []byte) error { id2 := owner.NewID() id2.SetNeo3Wallet(wallet) - // FIXME: implement Equal method - if s1, s2 := id.String(), id2.String(); s1 != s2 { - return fmt.Errorf("(%T) different owner identifiers %s/%s", v, s1, s2) + if !id.Equal(id2) { + return fmt.Errorf("(%T) different owner identifiers %s/%s", v, id, id2) } return nil diff --git a/pkg/innerring/processors/settlement/common/util.go b/pkg/innerring/processors/settlement/common/util.go index a642b42a7..2c6efa696 100644 --- a/pkg/innerring/processors/settlement/common/util.go +++ b/pkg/innerring/processors/settlement/common/util.go @@ -23,11 +23,12 @@ func NewTransferTable() *TransferTable { } func (t *TransferTable) Transfer(tx *TransferTx) { - from, to := tx.From.String(), tx.To.String() - if from == to { + if tx.From.Equal(tx.To) { return } + from, to := tx.From.String(), tx.To.String() + m, ok := t.txs[from] if !ok { if m, ok = t.txs[to]; ok { diff --git a/pkg/services/object/acl/acl.go b/pkg/services/object/acl/acl.go index f1a0e888e..de2f847f1 100644 --- a/pkg/services/object/acl/acl.go +++ b/pkg/services/object/acl/acl.go @@ -1,7 +1,6 @@ package acl import ( - "bytes" "context" "crypto/ecdsa" "errors" @@ -765,11 +764,7 @@ func isOwnerFromKey(id *owner.ID, key *ecdsa.PublicKey) bool { return false } - // here we compare `owner.ID -> wallet` with `wallet <- publicKey` - // consider making equal method on owner.ID structure - // we can compare .String() version of owners but don't think it is good idea - // binary comparison is better but MarshalBinary is more expensive - return bytes.Equal(id.ToV2().GetValue(), wallet.Bytes()) + return id.Equal(owner.NewIDFromNeo3Wallet(wallet)) } // originalBearerToken goes down to original request meta header and fetches diff --git a/pkg/services/object/acl/classifier.go b/pkg/services/object/acl/classifier.go index 31d226673..f365127a6 100644 --- a/pkg/services/object/acl/classifier.go +++ b/pkg/services/object/acl/classifier.go @@ -65,7 +65,7 @@ func (c SenderClassifier) Classify( // todo: get owner from neofs.id if present // if request owner is the same as container owner, return RoleUser - if bytes.Equal(cnr.OwnerID().ToV2().GetValue(), ownerID.ToV2().GetValue()) { + if ownerID.Equal(cnr.OwnerID()) { return acl.RoleUser, false, ownerKeyInBytes, nil }