From 6cb513c97688cd218ea75c24eea48eddaca32e5e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 30 May 2022 22:05:35 +0300 Subject: [PATCH] [#257] Upgrade NeoFS API Go module New version contains fix for `object.GetRangeResponse` message type. Signed-off-by: Leonard Lyubich --- audit/result.go | 7 +------ bearer/bearer.go | 23 +++-------------------- client/container.go | 14 ++------------ container/announcement.go | 2 +- container/container.go | 9 ++------- eacl/filter.go | 2 +- eacl/record.go | 2 +- eacl/table.go | 2 +- eacl/target.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- netmap/filter.go | 2 +- netmap/network_info.go | 2 +- netmap/node_info.go | 4 ++-- netmap/policy.go | 2 +- netmap/replica.go | 2 +- netmap/selector.go | 2 +- object/attribute.go | 2 +- object/fmt.go | 14 ++------------ object/id/id.go | 2 +- object/lock.go | 7 +------ object/object.go | 2 +- object/splitinfo.go | 2 +- object/tombstone.go | 2 +- reputation/peer.go | 2 +- reputation/trust.go | 20 +++++--------------- session/container.go | 21 +++------------------ session/object.go | 21 +++------------------ storagegroup/storagegroup.go | 3 +-- subnet/id/id.go | 2 +- subnet/subnet.go | 2 +- 31 files changed, 46 insertions(+), 139 deletions(-) diff --git a/audit/result.go b/audit/result.go index 161c8c7..1ab836b 100644 --- a/audit/result.go +++ b/audit/result.go @@ -38,12 +38,7 @@ func (r *Result) Marshal() []byte { r.versionEncoded = true } - data, err := r.v2.StableMarshal(nil) - if err != nil { - panic(err) - } - - return data + return r.v2.StableMarshal(nil) } var errCIDNotSet = errors.New("container ID is not set") diff --git a/bearer/bearer.go b/bearer/bearer.go index 4d54ea2..f24bb2e 100644 --- a/bearer/bearer.go +++ b/bearer/bearer.go @@ -224,14 +224,9 @@ func (b *Token) Sign(key ecdsa.PrivateKey) error { m := (*acl.BearerToken)(b) - data, err := m.GetBody().StableMarshal(nil) - if err != nil { - return fmt.Errorf("marshal body: %w", err) - } - var sig neofscrypto.Signature - err = sig.Calculate(neofsecdsa.Signer(key), data) + err = sig.Calculate(neofsecdsa.Signer(key), m.GetBody().StableMarshal(nil)) if err != nil { return fmt.Errorf("calculate signature: %w", err) } @@ -257,15 +252,10 @@ func (b Token) VerifySignature() error { return errors.New("missing signature") } - data, err := m.GetBody().StableMarshal(nil) - if err != nil { - return fmt.Errorf("marshal body: %w", err) - } - var sig neofscrypto.Signature sig.ReadFromV2(*sigV2) - if !sig.Verify(data) { + if !sig.Verify(m.GetBody().StableMarshal(nil)) { return errors.New("wrong signature") } @@ -312,14 +302,7 @@ func sanityCheck(b *Token) error { // // See also Unmarshal. func (b Token) Marshal() []byte { - v2 := (acl.BearerToken)(b) - - data, err := v2.StableMarshal(nil) - if err != nil { - panic(err) - } - - return data + return (*acl.BearerToken)(&b).StableMarshal(nil) } // Unmarshal unmarshals Token from canonical NeoFS binary format (proto3 diff --git a/client/container.go b/client/container.go index be67260..9081677 100644 --- a/client/container.go +++ b/client/container.go @@ -84,14 +84,9 @@ func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResCon // sign container cnr := prm.cnr.ToV2() - data, err := cnr.StableMarshal(nil) - if err != nil { - return nil, fmt.Errorf("marshal container: %w", err) - } - var sig neofscrypto.Signature - err = sig.Calculate(neofsecdsa.SignerRFC6979(c.prm.key), data) + err := sig.Calculate(neofsecdsa.SignerRFC6979(c.prm.key), cnr.StableMarshal(nil)) if err != nil { return nil, fmt.Errorf("calculate signature: %w", err) } @@ -675,14 +670,9 @@ func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL) // sign the eACL table eaclV2 := prm.table.ToV2() - data, err := eaclV2.StableMarshal(nil) - if err != nil { - return nil, fmt.Errorf("marshal eACL: %w", err) - } - var sig neofscrypto.Signature - err = sig.Calculate(neofsecdsa.SignerRFC6979(c.prm.key), data) + err := sig.Calculate(neofsecdsa.SignerRFC6979(c.prm.key), eaclV2.StableMarshal(nil)) if err != nil { return nil, fmt.Errorf("calculate signature: %w", err) } diff --git a/container/announcement.go b/container/announcement.go index 0378abc..4b3d626 100644 --- a/container/announcement.go +++ b/container/announcement.go @@ -83,7 +83,7 @@ func (a *UsedSpaceAnnouncement) ToV2() *container.UsedSpaceAnnouncement { // Marshal marshals UsedSpaceAnnouncement into a protobuf binary form. func (a *UsedSpaceAnnouncement) Marshal() ([]byte, error) { - return a.ToV2().StableMarshal(nil) + return a.ToV2().StableMarshal(nil), nil } var errCIDNotSet = errors.New("container ID is not set") diff --git a/container/container.go b/container/container.go index 5c13e1f..dd65c24 100644 --- a/container/container.go +++ b/container/container.go @@ -88,13 +88,8 @@ func NewContainerFromV2(c *container.Container) *Container { // CalculateID calculates container identifier // based on its structure. func CalculateID(c *Container) cid.ID { - data, err := c.ToV2().StableMarshal(nil) - if err != nil { - panic(err) - } - var id cid.ID - id.SetSHA256(sha256.Sum256(data)) + id.SetSHA256(sha256.Sum256(c.ToV2().StableMarshal(nil))) return id } @@ -194,7 +189,7 @@ func (c *Container) SetSignature(sig *neofscrypto.Signature) { // Marshal marshals Container into a protobuf binary form. func (c *Container) Marshal() ([]byte, error) { - return c.v2.StableMarshal(nil) + return c.v2.StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Container. diff --git a/eacl/filter.go b/eacl/filter.go index 07eec68..12fac13 100644 --- a/eacl/filter.go +++ b/eacl/filter.go @@ -143,7 +143,7 @@ func NewFilterFromV2(filter *v2acl.HeaderFilter) *Filter { // Marshal marshals Filter into a protobuf binary form. func (f *Filter) Marshal() ([]byte, error) { - return f.ToV2().StableMarshal(nil) + return f.ToV2().StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Filter. diff --git a/eacl/record.go b/eacl/record.go index 293755f..2d7861f 100644 --- a/eacl/record.go +++ b/eacl/record.go @@ -236,7 +236,7 @@ func NewRecordFromV2(record *v2acl.Record) *Record { // Marshal marshals Record into a protobuf binary form. func (r *Record) Marshal() ([]byte, error) { - return r.ToV2().StableMarshal(nil) + return r.ToV2().StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Record. diff --git a/eacl/table.go b/eacl/table.go index cf3bbe4..962925c 100644 --- a/eacl/table.go +++ b/eacl/table.go @@ -180,7 +180,7 @@ func NewTableFromV2(table *v2acl.Table) *Table { // Marshal marshals Table into a protobuf binary form. func (t *Table) Marshal() ([]byte, error) { - return t.ToV2().StableMarshal(nil) + return t.ToV2().StableMarshal(nil), nil } var errCIDNotSet = errors.New("container ID is not set") diff --git a/eacl/target.go b/eacl/target.go index 84f62c0..768bbdc 100644 --- a/eacl/target.go +++ b/eacl/target.go @@ -125,7 +125,7 @@ func NewTargetFromV2(target *v2acl.Target) *Target { // Marshal marshals Target into a protobuf binary form. func (t *Target) Marshal() ([]byte, error) { - return t.ToV2().StableMarshal(nil) + return t.ToV2().StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Target. diff --git a/go.mod b/go.mod index e8c5e67..92271f7 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/mr-tron/base58 v1.2.0 github.com/nspcc-dev/hrw v1.0.9 github.com/nspcc-dev/neo-go v0.98.2 - github.com/nspcc-dev/neofs-api-go/v2 v2.12.1 + github.com/nspcc-dev/neofs-api-go/v2 v2.12.2-0.20220530190258-c82dcf7e1610 github.com/nspcc-dev/neofs-contract v0.15.1 github.com/nspcc-dev/tzhash v1.5.2 github.com/stretchr/testify v1.7.0 diff --git a/go.sum b/go.sum index 30aad99..b093658 100644 --- a/go.sum +++ b/go.sum @@ -182,8 +182,8 @@ github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321113211-526c423a6152 h1:JK github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321113211-526c423a6152/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y= github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= -github.com/nspcc-dev/neofs-api-go/v2 v2.12.1 h1:PVU2rLlG9S0jDe5eKyaUs4nKo/la+mN5pvz32Gib3qM= -github.com/nspcc-dev/neofs-api-go/v2 v2.12.1/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU= +github.com/nspcc-dev/neofs-api-go/v2 v2.12.2-0.20220530190258-c82dcf7e1610 h1:JwrxHWQJSOxx0LvnEvFj3MpKjWQAPXOq55uuGimghR0= +github.com/nspcc-dev/neofs-api-go/v2 v2.12.2-0.20220530190258-c82dcf7e1610/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU= github.com/nspcc-dev/neofs-contract v0.15.1 h1:1r27t4SGKF7W1PRPOIfircEXHvALThNYNagT+SIabcA= github.com/nspcc-dev/neofs-contract v0.15.1/go.mod h1:kxO5ZTqdzFnRM5RMvM+Fhd+3GGrJo6AmG2ZyA9OCqqQ= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= diff --git a/netmap/filter.go b/netmap/filter.go index 68e6c9e..0f33e2e 100644 --- a/netmap/filter.go +++ b/netmap/filter.go @@ -254,7 +254,7 @@ func (f *Filter) SetInnerFilters(fs ...Filter) { // Marshal marshals Filter into a protobuf binary form. func (f *Filter) Marshal() ([]byte, error) { - return (*netmap.Filter)(f).StableMarshal(nil) + return (*netmap.Filter)(f).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Filter. diff --git a/netmap/network_info.go b/netmap/network_info.go index 6234beb..7af240d 100644 --- a/netmap/network_info.go +++ b/netmap/network_info.go @@ -81,7 +81,7 @@ func (i *NetworkInfo) SetNetworkConfig(v *NetworkConfig) { // Marshal marshals NetworkInfo into a protobuf binary form. func (i *NetworkInfo) Marshal() ([]byte, error) { - return (*netmap.NetworkInfo)(i).StableMarshal(nil) + return (*netmap.NetworkInfo)(i).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of NetworkInfo. diff --git a/netmap/node_info.go b/netmap/node_info.go index 040589f..2e4ba8d 100644 --- a/netmap/node_info.go +++ b/netmap/node_info.go @@ -274,7 +274,7 @@ func (a *NodeAttribute) SetParentKeys(keys ...string) { // Marshal marshals NodeAttribute into a protobuf binary form. func (a *NodeAttribute) Marshal() ([]byte, error) { - return (*netmap.Attribute)(a).StableMarshal(nil) + return (*netmap.Attribute)(a).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of NodeAttribute. @@ -401,7 +401,7 @@ func (i *NodeInfo) SetState(s NodeState) { // Marshal marshals NodeInfo into a protobuf binary form. func (i *NodeInfo) Marshal() ([]byte, error) { - return (*netmap.NodeInfo)(i).StableMarshal(nil) + return (*netmap.NodeInfo)(i).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of NodeInfo. diff --git a/netmap/policy.go b/netmap/policy.go index aa1f336..a5ef032 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -139,7 +139,7 @@ func (p *PlacementPolicy) SetFilters(fs ...Filter) { // Marshal marshals PlacementPolicy into a protobuf binary form. func (p *PlacementPolicy) Marshal() ([]byte, error) { - return (*netmap.PlacementPolicy)(p).StableMarshal(nil) + return (*netmap.PlacementPolicy)(p).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of PlacementPolicy. diff --git a/netmap/replica.go b/netmap/replica.go index 3535cc1..ddc0994 100644 --- a/netmap/replica.go +++ b/netmap/replica.go @@ -52,7 +52,7 @@ func (r *Replica) SetSelector(s string) { // Marshal marshals Replica into a protobuf binary form. func (r *Replica) Marshal() ([]byte, error) { - return (*netmap.Replica)(r).StableMarshal(nil) + return (*netmap.Replica)(r).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Replica. diff --git a/netmap/selector.go b/netmap/selector.go index 1dc6b0d..cec6d33 100644 --- a/netmap/selector.go +++ b/netmap/selector.go @@ -256,7 +256,7 @@ func (s *Selector) SetFilter(f string) { // Marshal marshals Selector into a protobuf binary form. func (s *Selector) Marshal() ([]byte, error) { - return (*netmap.Selector)(s).StableMarshal(nil) + return (*netmap.Selector)(s).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Selector. diff --git a/object/attribute.go b/object/attribute.go index cc1ac42..0e4ac9e 100644 --- a/object/attribute.go +++ b/object/attribute.go @@ -54,7 +54,7 @@ func (a *Attribute) ToV2() *object.Attribute { // Marshal marshals Attribute into a protobuf binary form. func (a *Attribute) Marshal() ([]byte, error) { - return (*object.Attribute)(a).StableMarshal(nil) + return (*object.Attribute)(a).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Attribute. diff --git a/object/fmt.go b/object/fmt.go index b893e8b..4339a04 100644 --- a/object/fmt.go +++ b/object/fmt.go @@ -55,13 +55,8 @@ func VerifyPayloadChecksum(obj *Object) error { // CalculateID calculates identifier for the object. func CalculateID(obj *Object) (oid.ID, error) { - data, err := obj.ToV2().GetHeader().StableMarshal(nil) - if err != nil { - return oid.ID{}, err - } - var id oid.ID - id.SetSHA256(sha256.Sum256(data)) + id.SetSHA256(sha256.Sum256(obj.ToV2().GetHeader().StableMarshal(nil))) return id, nil } @@ -131,15 +126,10 @@ func (o *Object) VerifyIDSignature() bool { return false } - data, err := idV2.StableMarshal(nil) - if err != nil { - return false - } - var sig neofscrypto.Signature sig.ReadFromV2(*sigV2) - return sig.Verify(data) + return sig.Verify(idV2.StableMarshal(nil)) } // SetIDWithSignature sets object identifier and signature. diff --git a/object/id/id.go b/object/id/id.go index f9ccbe9..7df4e4f 100644 --- a/object/id/id.go +++ b/object/id/id.go @@ -132,7 +132,7 @@ func (id ID) Marshal() ([]byte, error) { var v2 refs.ObjectID v2.SetValue(id[:]) - return v2.StableMarshal(nil) + return v2.StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of ID. diff --git a/object/lock.go b/object/lock.go index 4daff7e..ad93fa3 100644 --- a/object/lock.go +++ b/object/lock.go @@ -64,12 +64,7 @@ func (x *Lock) WriteMembers(ids []oid.ID) { // Marshal encodes the Lock into a NeoFS protocol binary format. func (x Lock) Marshal() []byte { - data, err := (*v2object.Lock)(&x).StableMarshal(nil) - if err != nil { - panic(err) - } - - return data + return (*v2object.Lock)(&x).StableMarshal(nil) } // Unmarshal decodes the Lock from its NeoFS protocol binary representation. diff --git a/object/object.go b/object/object.go index 03c0b18..ada5ec7 100644 --- a/object/object.go +++ b/object/object.go @@ -593,7 +593,7 @@ func (o *Object) InitRelations() { // Marshal marshals object into a protobuf binary form. func (o *Object) Marshal() ([]byte, error) { - return (*object.Object)(o).StableMarshal(nil) + return (*object.Object)(o).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of object. diff --git a/object/splitinfo.go b/object/splitinfo.go index 3fa262a..4e9039d 100644 --- a/object/splitinfo.go +++ b/object/splitinfo.go @@ -83,7 +83,7 @@ func (s *SplitInfo) SetLink(v oid.ID) { } func (s *SplitInfo) Marshal() ([]byte, error) { - return (*object.SplitInfo)(s).StableMarshal(nil) + return (*object.SplitInfo)(s).StableMarshal(nil), nil } func (s *SplitInfo) Unmarshal(data []byte) error { diff --git a/object/tombstone.go b/object/tombstone.go index 4f4ffac..f7ff3d5 100644 --- a/object/tombstone.go +++ b/object/tombstone.go @@ -103,7 +103,7 @@ func (t *Tombstone) SetMembers(v []oid.ID) { // Marshal marshals Tombstone into a protobuf binary form. func (t *Tombstone) Marshal() ([]byte, error) { - return (*tombstone.Tombstone)(t).StableMarshal(nil) + return (*tombstone.Tombstone)(t).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Tombstone. diff --git a/reputation/peer.go b/reputation/peer.go index 1edd2a6..d80d23a 100644 --- a/reputation/peer.go +++ b/reputation/peer.go @@ -64,7 +64,7 @@ func (x *PeerID) String() string { // Marshal marshals PeerID into a protobuf binary form. func (x *PeerID) Marshal() ([]byte, error) { - return (*reputation.PeerID)(x).StableMarshal(nil) + return (*reputation.PeerID)(x).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of PeerID. diff --git a/reputation/trust.go b/reputation/trust.go index c0f3d40..4a73f75 100644 --- a/reputation/trust.go +++ b/reputation/trust.go @@ -77,7 +77,7 @@ func (x *Trust) Value() float64 { // Marshal marshals Trust into a protobuf binary form. func (x *Trust) Marshal() ([]byte, error) { - return (*reputation.Trust)(x).StableMarshal(nil) + return (*reputation.Trust)(x).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of Trust. @@ -150,7 +150,7 @@ func (x *PeerToPeerTrust) Trust() *Trust { // Marshal marshals PeerToPeerTrust into a protobuf binary form. func (x *PeerToPeerTrust) Marshal() ([]byte, error) { - return (*reputation.PeerToPeerTrust)(x).StableMarshal(nil) + return (*reputation.PeerToPeerTrust)(x).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of PeerToPeerTrust. @@ -271,14 +271,9 @@ func (x *GlobalTrust) Sign(key *ecdsa.PrivateKey) error { m := (*reputation.GlobalTrust)(x) - data, err := m.GetBody().StableMarshal(nil) - if err != nil { - return fmt.Errorf("marshal body: %w", err) - } - var sig neofscrypto.Signature - err = sig.Calculate(neofsecdsa.Signer(*key), data) + err := sig.Calculate(neofsecdsa.Signer(*key), m.GetBody().StableMarshal(nil)) if err != nil { return fmt.Errorf("calculate signature: %w", err) } @@ -301,15 +296,10 @@ func (x *GlobalTrust) VerifySignature() error { return errors.New("missing signature") } - data, err := m.GetBody().StableMarshal(nil) - if err != nil { - return fmt.Errorf("marshal body: %w", err) - } - var sig neofscrypto.Signature sig.ReadFromV2(*sigV2) - if !sig.Verify(data) { + if !sig.Verify(m.GetBody().StableMarshal(nil)) { return errors.New("wrong signature") } @@ -318,7 +308,7 @@ func (x *GlobalTrust) VerifySignature() error { // Marshal marshals GlobalTrust into a protobuf binary form. func (x *GlobalTrust) Marshal() ([]byte, error) { - return (*reputation.GlobalTrust)(x).StableMarshal(nil) + return (*reputation.GlobalTrust)(x).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of GlobalTrust. diff --git a/session/container.go b/session/container.go index 88f3062..b5722d2 100644 --- a/session/container.go +++ b/session/container.go @@ -109,12 +109,7 @@ func (x Container) Marshal() []byte { var m session.Token x.WriteToV2(&m) - data, err := m.StableMarshal(nil) - if err != nil { - panic(fmt.Sprintf("unexpected error from Token.StableMarshal: %v", err)) - } - - return data + return m.StableMarshal(nil) } // Unmarshal decodes NeoFS API protocol binary format into the Container @@ -181,12 +176,7 @@ func (x *Container) Sign(key ecdsa.PrivateKey) error { x.body.SetLifetime(&x.lt) x.body.SetContext(&x.c) - data, err := x.body.StableMarshal(nil) - if err != nil { - panic(fmt.Sprintf("unexpected error from Token.StableMarshal: %v", err)) - } - - return x.sig.Calculate(neofsecdsa.Signer(key), data) + return x.sig.Calculate(neofsecdsa.Signer(key), x.body.StableMarshal(nil)) } // VerifySignature checks if Container signature is presented and valid. @@ -196,12 +186,7 @@ func (x *Container) Sign(key ecdsa.PrivateKey) error { // See also Sign. func (x Container) VerifySignature() bool { // TODO: (#233) check owner<->key relation - data, err := x.body.StableMarshal(nil) - if err != nil { - panic(fmt.Sprintf("unexpected error from Token.StableMarshal: %v", err)) - } - - return x.sig.Verify(data) + return x.sig.Verify(x.body.StableMarshal(nil)) } // ApplyOnlyTo limits session scope to a given author container. diff --git a/session/object.go b/session/object.go index 5c5a8a6..7b7f6dd 100644 --- a/session/object.go +++ b/session/object.go @@ -112,12 +112,7 @@ func (x Object) Marshal() []byte { var m session.Token x.WriteToV2(&m) - data, err := m.StableMarshal(nil) - if err != nil { - panic(fmt.Sprintf("unexpected error from Token.StableMarshal: %v", err)) - } - - return data + return m.StableMarshal(nil) } // Unmarshal decodes NeoFS API protocol binary format into the Object @@ -184,12 +179,7 @@ func (x *Object) Sign(key ecdsa.PrivateKey) error { x.body.SetLifetime(&x.lt) x.body.SetContext(&x.c) - data, err := x.body.StableMarshal(nil) - if err != nil { - panic(fmt.Sprintf("unexpected error from Token.StableMarshal: %v", err)) - } - - return x.sig.Calculate(neofsecdsa.Signer(key), data) + return x.sig.Calculate(neofsecdsa.Signer(key), x.body.StableMarshal(nil)) } // VerifySignature checks if Object signature is presented and valid. @@ -199,12 +189,7 @@ func (x *Object) Sign(key ecdsa.PrivateKey) error { // See also Sign. func (x Object) VerifySignature() bool { // TODO: (#233) check owner<->key relation - data, err := x.body.StableMarshal(nil) - if err != nil { - panic(fmt.Sprintf("unexpected error from Token.StableMarshal: %v", err)) - } - - return x.sig.Verify(data) + return x.sig.Verify(x.body.StableMarshal(nil)) } // BindContainer binds the Object session to a given container. Each session diff --git a/storagegroup/storagegroup.go b/storagegroup/storagegroup.go index 5d35822..a14bd0a 100644 --- a/storagegroup/storagegroup.go +++ b/storagegroup/storagegroup.go @@ -156,8 +156,7 @@ func (sg *StorageGroup) SetMembers(members []oid.ID) { // // See also Unmarshal. func (sg StorageGroup) Marshal() ([]byte, error) { - v2 := (storagegroup.StorageGroup)(sg) - return v2.StableMarshal(nil) + return (*storagegroup.StorageGroup)(&sg).StableMarshal(nil), nil } // Unmarshal unmarshals protobuf binary representation of StorageGroup. diff --git a/subnet/id/id.go b/subnet/id/id.go index d1f530c..9a198df 100644 --- a/subnet/id/id.go +++ b/subnet/id/id.go @@ -67,7 +67,7 @@ func (x *ID) String() string { // Marshal encodes ID into a binary format of NeoFS API V2 protocol (Protocol Buffers with direct field order). func (x *ID) Marshal() ([]byte, error) { - return (*refs.SubnetID)(x).StableMarshal(nil) + return (*refs.SubnetID)(x).StableMarshal(nil), nil } // Unmarshal decodes ID from NeoFS API V2 binary format (see Marshal). Must not be called on nil. diff --git a/subnet/subnet.go b/subnet/subnet.go index 75c48c9..fd295ab 100644 --- a/subnet/subnet.go +++ b/subnet/subnet.go @@ -26,7 +26,7 @@ func (x Info) WriteToV2(msg *subnet.Info) { // Marshal encodes Info into a binary format of NeoFS API V2 protocol (Protocol Buffers with direct field order). func (x *Info) Marshal() ([]byte, error) { - return (*subnet.Info)(x).StableMarshal(nil) + return (*subnet.Info)(x).StableMarshal(nil), nil } // Unmarshal decodes Info from NeoFS API V2 binary format (see Marshal). Must not be called on nil.