forked from TrueCloudLab/frostfs-sdk-go
[#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 <a.arifullin@yadro.com>
This commit is contained in:
parent
425d48f68b
commit
ec0cb2169f
2 changed files with 11 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue