container: implement SignedDataSource on DeleteRequest message

This commit is contained in:
Leonard Lyubich 2020-05-11 15:01:29 +03:00
parent 2d53ebf9c4
commit eedb97d135
4 changed files with 68 additions and 1 deletions

View file

@ -64,3 +64,34 @@ func (m PutRequest) ReadSignedData(p []byte) (int, error) {
return off, nil 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
}

View file

@ -22,7 +22,7 @@ func TestRequestSign(t *testing.T) {
constructor func() sigType constructor func() sigType
payloadCorrupt []func(sigType) payloadCorrupt []func(sigType)
}{ }{
{ // Request { // PutRequest
constructor: func() sigType { constructor: func() sigType {
return new(PutRequest) 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 { for _, item := range items {

View file

@ -128,3 +128,13 @@ func (m *PutRequest) SetRules(rules netmap.PlacementRule) {
func (m *PutRequest) SetBasicACL(acl uint32) { func (m *PutRequest) SetBasicACL(acl uint32) {
m.BasicACL = acl 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
}

View file

@ -107,3 +107,14 @@ func TestPutRequestGettersSetters(t *testing.T) {
require.Equal(t, bACL, m.GetBasicACL()) 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())
})
}