[#257] Upgrade NeoFS API Go module

New version contains fix for `object.GetRangeResponse` message type.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-05-30 22:05:35 +03:00 committed by LeL
parent 3953c2166e
commit 6cb513c976
31 changed files with 46 additions and 139 deletions

View file

@ -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")

View file

@ -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

View file

@ -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)
}

View file

@ -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")

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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")

View file

@ -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.

2
go.mod
View file

@ -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

4
go.sum
View file

@ -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=

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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 {

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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

View file

@ -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.

View file

@ -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.

View file

@ -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.