diff --git a/container/sign.go b/container/sign.go index eafd93c3..f538f2d7 100644 --- a/container/sign.go +++ b/container/sign.go @@ -135,3 +135,60 @@ func (m ListRequest) ReadSignedData(p []byte) (int, error) { return off, nil } + +// SignedData returns payload bytes of the request. +func (m GetExtendedACLRequest) SignedData() ([]byte, error) { + return service.SignedDataFromReader(m) +} + +// SignedDataSize returns payload size of the request. +func (m GetExtendedACLRequest) SignedDataSize() int { + return m.GetID().Size() +} + +// ReadSignedData copies payload bytes to passed buffer. +// +// If the Request size is insufficient, io.ErrUnexpectedEOF returns. +func (m GetExtendedACLRequest) ReadSignedData(p []byte) (int, error) { + if len(p) < m.SignedDataSize() { + return 0, io.ErrUnexpectedEOF + } + + var off int + + off += copy(p[off:], m.GetID().Bytes()) + + return off, nil +} + +// SignedData returns payload bytes of the request. +func (m SetExtendedACLRequest) SignedData() ([]byte, error) { + return service.SignedDataFromReader(m) +} + +// SignedDataSize returns payload size of the request. +func (m SetExtendedACLRequest) SignedDataSize() int { + return 0 + + m.GetID().Size() + + len(m.GetEACL()) + + len(m.GetSignature()) +} + +// ReadSignedData copies payload bytes to passed buffer. +// +// If the Request size is insufficient, io.ErrUnexpectedEOF returns. +func (m SetExtendedACLRequest) ReadSignedData(p []byte) (int, error) { + if len(p) < m.SignedDataSize() { + return 0, io.ErrUnexpectedEOF + } + + var off int + + off += copy(p[off:], m.GetID().Bytes()) + + off += copy(p[off:], m.GetEACL()) + + off += copy(p[off:], m.GetSignature()) + + return off, nil +} diff --git a/container/sign_test.go b/container/sign_test.go index d9b7d26e..d04a6989 100644 --- a/container/sign_test.go +++ b/container/sign_test.go @@ -108,6 +108,50 @@ func TestRequestSign(t *testing.T) { }, }, }, + { // GetExtendedACLRequest + constructor: func() sigType { + return new(GetExtendedACLRequest) + }, + payloadCorrupt: []func(sigType){ + func(s sigType) { + req := s.(*GetExtendedACLRequest) + + id := req.GetID() + id[0]++ + + req.SetID(id) + }, + }, + }, + { // SetExtendedACLRequest + constructor: func() sigType { + return new(SetExtendedACLRequest) + }, + payloadCorrupt: []func(sigType){ + func(s sigType) { + req := s.(*SetExtendedACLRequest) + + id := req.GetID() + id[0]++ + + req.SetID(id) + }, + func(s sigType) { + req := s.(*SetExtendedACLRequest) + + req.SetEACL( + append(req.GetEACL(), 1), + ) + }, + func(s sigType) { + req := s.(*SetExtendedACLRequest) + + req.SetSignature( + append(req.GetSignature(), 1), + ) + }, + }, + }, } for _, item := range items {