From e784206032922a82fc5180d68d08e69572701406 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 6 May 2020 14:38:39 +0300 Subject: [PATCH] object: implement signing payload methods on GetRangeRequest message --- object/sign.go | 30 ++++++++++++++++++++++++++++++ object/sign_test.go | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/object/sign.go b/object/sign.go index acb9901c..506fc951 100644 --- a/object/sign.go +++ b/object/sign.go @@ -131,6 +131,36 @@ func (m DeleteRequest) SignedDataSize() int { 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 { return addr.CID.Size() + addr.ObjectID.Size() } diff --git a/object/sign_test.go b/object/sign_test.go index d6357b9c..f8450ef9 100644 --- a/object/sign_test.go +++ b/object/sign_test.go @@ -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 {