2020-10-02 12:23:52 +00:00
|
|
|
package eacl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2021-02-02 15:54:30 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/util/signature"
|
2020-10-02 12:23:52 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2021-02-02 15:54:30 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-10-02 12:23:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type morphStorage struct {
|
|
|
|
w *wrapper.Wrapper
|
|
|
|
}
|
|
|
|
|
2021-02-02 15:54:30 +00:00
|
|
|
type signedEACLTable eacl.Table
|
|
|
|
|
|
|
|
func (s *signedEACLTable) ReadSignedData(buf []byte) ([]byte, error) {
|
|
|
|
return (*eacl.Table)(s).Marshal(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signedEACLTable) SignedDataSize() int {
|
|
|
|
// TODO: add eacl.Table.Size method
|
|
|
|
return (*eacl.Table)(s).ToV2().StableSize()
|
|
|
|
}
|
|
|
|
|
2020-10-02 12:23:52 +00:00
|
|
|
func (s *morphStorage) GetEACL(cid *container.ID) (*eacl.Table, error) {
|
2021-02-02 15:54:30 +00:00
|
|
|
table, sig, err := s.w.GetEACL(cid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signature.VerifyDataWithSource(
|
|
|
|
(*signedEACLTable)(table),
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sig.Key(), sig.Sign()
|
|
|
|
},
|
|
|
|
); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "incorrect signature")
|
|
|
|
}
|
2020-10-02 12:23:52 +00:00
|
|
|
|
2021-02-02 15:54:30 +00:00
|
|
|
return table, nil
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func WithLogger(v *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.logger = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithEACLStorage(v Storage) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.storage = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMorphClient(v *wrapper.Wrapper) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.storage = &morphStorage{
|
|
|
|
w: v,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|