forked from TrueCloudLab/frostfs-api-go
container: implement SignedDataSource on DeleteRequest message
This commit is contained in:
parent
2d53ebf9c4
commit
eedb97d135
4 changed files with 68 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue