Use checksum structure in storagegroup package

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-08-20 11:04:16 +03:00 committed by Stanislav Bogatyrev
parent 6787648027
commit 4405492640
5 changed files with 21 additions and 9 deletions

View file

@ -15,7 +15,9 @@ func StorageGroupToGRPCMessage(s *StorageGroup) *sg.StorageGroup {
m := new(sg.StorageGroup)
m.SetValidationDataSize(s.GetValidationDataSize())
m.SetValidationHash(s.GetValidationHash())
m.SetValidationHash(
refs.ChecksumToGRPCMessage(s.GetValidationHash()),
)
m.SetExpirationEpoch(s.GetExpirationEpoch())
members := s.GetMembers()
@ -39,7 +41,9 @@ func StorageGroupFromGRPCMessage(m *sg.StorageGroup) *StorageGroup {
s := new(StorageGroup)
s.SetValidationDataSize(m.GetValidationDataSize())
s.SetValidationHash(m.GetValidationHash())
s.SetValidationHash(
refs.ChecksumFromGRPCMessage(m.GetValidationHash()),
)
s.SetExpirationEpoch(m.GetExpirationEpoch())
memberMsg := m.GetMembers()

View file

@ -12,7 +12,7 @@ func (m *StorageGroup) SetValidationDataSize(v uint64) {
}
// SetValidationHash sets total homomorphic hash of the storage group payloads.
func (m *StorageGroup) SetValidationHash(v []byte) {
func (m *StorageGroup) SetValidationHash(v *refs.Checksum) {
if m != nil {
m.ValidationHash = v
}

View file

@ -34,7 +34,7 @@ func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
offset += n
n, err = proto.BytesMarshal(hashField, buf[offset:], s.hash)
n, err = proto.NestedStructureMarshal(hashField, buf[offset:], s.hash)
if err != nil {
return nil, err
}
@ -67,7 +67,7 @@ func (s *StorageGroup) StableSize() (size int) {
}
size += proto.UInt64Size(sizeField, s.size)
size += proto.BytesSize(hashField, s.hash)
size += proto.NestedStructureSize(hashField, s.hash)
size += proto.UInt64Size(expirationField, s.exp)
for i := range s.members {

View file

@ -21,7 +21,7 @@ func TestStorageGroup_StableMarshal(t *testing.T) {
t.Run("non empty", func(t *testing.T) {
storageGroupFrom.SetValidationDataSize(300)
storageGroupFrom.SetValidationHash([]byte("Homomorphic hash value"))
storageGroupFrom.SetValidationHash(generateChecksum("Homomorphic hash"))
storageGroupFrom.SetExpirationEpoch(100)
storageGroupFrom.SetMembers([]*refs.ObjectID{ownerID1, ownerID2})
@ -35,3 +35,11 @@ func TestStorageGroup_StableMarshal(t *testing.T) {
require.Equal(t, storageGroupFrom, storageGroupTo)
})
}
func generateChecksum(data string) *refs.Checksum {
checksum := new(refs.Checksum)
checksum.SetType(refs.TillichZemor)
checksum.SetSum([]byte(data))
return checksum
}

View file

@ -9,7 +9,7 @@ import (
type StorageGroup struct {
size uint64
hash []byte
hash *refs.Checksum
exp uint64
@ -33,7 +33,7 @@ func (s *StorageGroup) SetValidationDataSize(v uint64) {
}
// GetValidationHash of unified storage group structure.
func (s *StorageGroup) GetValidationHash() []byte {
func (s *StorageGroup) GetValidationHash() *refs.Checksum {
if s != nil {
return s.hash
}
@ -42,7 +42,7 @@ func (s *StorageGroup) GetValidationHash() []byte {
}
// SetValidationHash into unified storage group structure.
func (s *StorageGroup) SetValidationHash(v []byte) {
func (s *StorageGroup) SetValidationHash(v *refs.Checksum) {
if s != nil {
s.hash = v
}