diff --git a/container/sign.go b/container/sign.go index 89c4a4c6..0f5fc939 100644 --- a/container/sign.go +++ b/container/sign.go @@ -77,7 +77,7 @@ func (m DeleteRequest) SignedData() ([]byte, error) { } // SignedDataSize returns payload size of the request. -func (m DeleteRequest) SignedDataSize() (sz int) { +func (m DeleteRequest) SignedDataSize() int { return m.GetCID().Size() } @@ -108,7 +108,7 @@ func (m GetRequest) SignedData() ([]byte, error) { } // SignedDataSize returns payload size of the request. -func (m GetRequest) SignedDataSize() (sz int) { +func (m GetRequest) SignedDataSize() int { return m.GetCID().Size() } @@ -126,3 +126,34 @@ func (m GetRequest) ReadSignedData(p []byte) (int, error) { return off, nil } + +// SignedData returns payload bytes of the request. +func (m ListRequest) 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 ListRequest) SignedDataSize() int { + return m.GetOwnerID().Size() +} + +// ReadSignedData copies payload bytes to passed buffer. +// +// If the Request size is insufficient, io.ErrUnexpectedEOF returns. +func (m ListRequest) ReadSignedData(p []byte) (int, error) { + if len(p) < m.SignedDataSize() { + return 0, io.ErrUnexpectedEOF + } + + var off int + + off += copy(p[off:], m.GetOwnerID().Bytes()) + + return off, nil +} diff --git a/container/sign_test.go b/container/sign_test.go index fb11fab8..e469399c 100644 --- a/container/sign_test.go +++ b/container/sign_test.go @@ -93,6 +93,21 @@ func TestRequestSign(t *testing.T) { }, }, }, + { // ListRequest + constructor: func() sigType { + return new(ListRequest) + }, + payloadCorrupt: []func(sigType){ + func(s sigType) { + req := s.(*ListRequest) + + owner := req.GetOwnerID() + owner[0]++ + + req.SetOwnerID(owner) + }, + }, + }, } for _, item := range items { diff --git a/container/types.go b/container/types.go index b34c51b6..f340aa59 100644 --- a/container/types.go +++ b/container/types.go @@ -148,3 +148,13 @@ func (m GetRequest) GetCID() CID { func (m *GetRequest) SetCID(cid CID) { m.CID = cid } + +// GetOwnerID is an OwnerID field getter. +func (m ListRequest) GetOwnerID() OwnerID { + return m.OwnerID +} + +// SetOwnerID is an OwnerID field setter. +func (m *ListRequest) SetOwnerID(owner OwnerID) { + m.OwnerID = owner +} diff --git a/container/types_test.go b/container/types_test.go index 3c120723..cc171cbe 100644 --- a/container/types_test.go +++ b/container/types_test.go @@ -129,3 +129,14 @@ func TestGetRequestGettersSetters(t *testing.T) { require.Equal(t, cid, m.GetCID()) }) } + +func TestListRequestGettersSetters(t *testing.T) { + t.Run("owner", func(t *testing.T) { + owner := OwnerID{1, 2, 3} + m := new(PutRequest) + + m.SetOwnerID(owner) + + require.Equal(t, owner, m.GetOwnerID()) + }) +}