object: implement signing payload methods on GetRangeRequest message

This commit is contained in:
Leonard Lyubich 2020-05-06 14:38:39 +03:00
parent fc0da3c8fc
commit e784206032
2 changed files with 49 additions and 0 deletions

View file

@ -131,6 +131,36 @@ func (m DeleteRequest) SignedDataSize() int {
return m.OwnerID.Size() + addressSize(m.Address) return m.OwnerID.Size() + addressSize(m.Address)
} }
// SignedData returns payload bytes of the request.
func (m GetRangeRequest) SignedData() ([]byte, error) {
data := make([]byte, m.SignedDataSize())
return data, m.ReadSignedData(data)
}
// ReadSignedData copies payload bytes to passed buffer.
//
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
func (m GetRangeRequest) ReadSignedData(p []byte) error {
if len(p) < m.SignedDataSize() {
return io.ErrUnexpectedEOF
}
n, err := (&m.Range).MarshalTo(p)
if err != nil {
return err
}
copy(p[n:], addressBytes(m.GetAddress()))
return nil
}
// SignedDataSize returns payload size of the request.
func (m GetRangeRequest) SignedDataSize() int {
return (&m.Range).Size() + addressSize(m.GetAddress())
}
func addressSize(addr Address) int { func addressSize(addr Address) int {
return addr.CID.Size() + addr.ObjectID.Size() return addr.CID.Size() + addr.ObjectID.Size()
} }

View file

@ -89,6 +89,25 @@ func TestSignVerifyRequests(t *testing.T) {
}, },
}, },
}, },
{ // GetRangeRequest
constructor: func() sigType {
return new(GetRangeRequest)
},
payloadCorrupt: []func(sigType){
func(s sigType) {
s.(*GetRangeRequest).Range.Length++
},
func(s sigType) {
s.(*GetRangeRequest).Range.Offset++
},
func(s sigType) {
s.(*GetRangeRequest).Address.CID[0]++
},
func(s sigType) {
s.(*GetRangeRequest).Address.ObjectID[0]++
},
},
},
} }
for _, item := range items { for _, item := range items {