diff --git a/container/sign.go b/container/sign.go index f551989..d9405b8 100644 --- a/container/sign.go +++ b/container/sign.go @@ -64,3 +64,34 @@ func (m PutRequest) ReadSignedData(p []byte) (int, error) { return off, nil } + +// SignedData returns payload bytes of the request. +func (m DeleteRequest) SignedData() ([]byte, error) { + data := make([]byte, m.SignedDataSize()) + + if _, err := m.ReadSignedData(data); err != nil { + return nil, err + } + + return data, nil +} + +// SignedDataSize returns payload size of the request. +func (m DeleteRequest) SignedDataSize() (sz int) { + return m.GetCID().Size() +} + +// ReadSignedData copies payload bytes to passed buffer. +// +// If the Request size is insufficient, io.ErrUnexpectedEOF returns. +func (m DeleteRequest) ReadSignedData(p []byte) (int, error) { + if len(p) < m.SignedDataSize() { + return 0, io.ErrUnexpectedEOF + } + + var off int + + off += copy(p[off:], m.GetCID().Bytes()) + + return off, nil +} diff --git a/container/sign_test.go b/container/sign_test.go index f1476ed..caa3516 100644 --- a/container/sign_test.go +++ b/container/sign_test.go @@ -22,7 +22,7 @@ func TestRequestSign(t *testing.T) { constructor func() sigType payloadCorrupt []func(sigType) }{ - { // Request + { // PutRequest constructor: func() sigType { return new(PutRequest) }, @@ -63,6 +63,21 @@ func TestRequestSign(t *testing.T) { }, }, }, + { // DeleteRequest + constructor: func() sigType { + return new(DeleteRequest) + }, + payloadCorrupt: []func(sigType){ + func(s sigType) { + req := s.(*DeleteRequest) + + cid := req.GetCID() + cid[0]++ + + req.SetCID(cid) + }, + }, + }, } for _, item := range items { diff --git a/container/types.go b/container/types.go index 39cef43..eeabe35 100644 --- a/container/types.go +++ b/container/types.go @@ -128,3 +128,13 @@ func (m *PutRequest) SetRules(rules netmap.PlacementRule) { func (m *PutRequest) SetBasicACL(acl uint32) { m.BasicACL = acl } + +// GetCID is a CID field getter. +func (m DeleteRequest) GetCID() CID { + return m.CID +} + +// SetCID is a CID field setter. +func (m *DeleteRequest) SetCID(cid CID) { + m.CID = cid +} diff --git a/container/types_test.go b/container/types_test.go index 07298bc..c1dafcc 100644 --- a/container/types_test.go +++ b/container/types_test.go @@ -107,3 +107,14 @@ func TestPutRequestGettersSetters(t *testing.T) { require.Equal(t, bACL, m.GetBasicACL()) }) } + +func TestDeleteRequestGettersSetters(t *testing.T) { + t.Run("cid", func(t *testing.T) { + cid := CID{1, 2, 3} + m := new(DeleteRequest) + + m.SetCID(cid) + + require.Equal(t, cid, m.GetCID()) + }) +}