diff --git a/v2/storagegroup/convert.go b/v2/storagegroup/convert.go index df545f92..67126197 100644 --- a/v2/storagegroup/convert.go +++ b/v2/storagegroup/convert.go @@ -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() diff --git a/v2/storagegroup/grpc/types.go b/v2/storagegroup/grpc/types.go index b1159c48..5bba1b15 100644 --- a/v2/storagegroup/grpc/types.go +++ b/v2/storagegroup/grpc/types.go @@ -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 } diff --git a/v2/storagegroup/marshal.go b/v2/storagegroup/marshal.go index cc1160f7..33b0c155 100644 --- a/v2/storagegroup/marshal.go +++ b/v2/storagegroup/marshal.go @@ -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 { diff --git a/v2/storagegroup/marshal_test.go b/v2/storagegroup/marshal_test.go index b79ed80c..0b6a1919 100644 --- a/v2/storagegroup/marshal_test.go +++ b/v2/storagegroup/marshal_test.go @@ -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 +} diff --git a/v2/storagegroup/types.go b/v2/storagegroup/types.go index 720bbe14..6c493ed0 100644 --- a/v2/storagegroup/types.go +++ b/v2/storagegroup/types.go @@ -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 }