From ec0cb2169f92fd57f2585980d1f1e08ac18d9fda Mon Sep 17 00:00:00 2001 From: aarifullin Date: Thu, 28 Mar 2024 18:53:34 +0300 Subject: [PATCH] [#211] object: Fix setIDWithSignature * Calculate and set checksum before ID is calculated. * Add header verification for parts in unit-test. Signed-off-by: Airat Arifullin --- object/erasurecode/split.go | 4 ++-- object/erasurecode/split_test.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/object/erasurecode/split.go b/object/erasurecode/split.go index b449b27..196de4a 100644 --- a/object/erasurecode/split.go +++ b/object/erasurecode/split.go @@ -44,12 +44,12 @@ func (c *Constructor) Split(obj *objectSDK.Object, key *ecdsa.PrivateKey) ([]*ob } func setIDWithSignature(obj *objectSDK.Object, key *ecdsa.PrivateKey) error { + objectSDK.CalculateAndSetPayloadChecksum(obj) + if err := objectSDK.CalculateAndSetID(obj); err != nil { return err } - objectSDK.CalculateAndSetPayloadChecksum(obj) - if key == nil { return nil } diff --git a/object/erasurecode/split_test.go b/object/erasurecode/split_test.go index 9fcba76..e82bd51 100644 --- a/object/erasurecode/split_test.go +++ b/object/erasurecode/split_test.go @@ -3,6 +3,7 @@ package erasurecode_test import ( "testing" + objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/erasurecode" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/stretchr/testify/require" @@ -23,6 +24,10 @@ func TestSplitMaxShardCount(t *testing.T) { parts, err := c.Split(original, &pk.PrivateKey) require.NoError(t, err) require.Len(t, parts, erasurecode.MaxShardCount) + + for _, part := range parts { + require.NoError(t, objectSDK.CheckHeaderVerificationFields(part)) + } }) t.Run("data + parity", func(t *testing.T) { c, err := erasurecode.NewConstructor(1, erasurecode.MaxShardCount-1) @@ -31,6 +36,10 @@ func TestSplitMaxShardCount(t *testing.T) { parts, err := c.Split(original, &pk.PrivateKey) require.NoError(t, err) require.Len(t, parts, erasurecode.MaxShardCount) + + for _, part := range parts { + require.NoError(t, objectSDK.CheckHeaderVerificationFields(part)) + } }) }