2020-11-03 09:03:41 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var errNilPolicy = errors.New("placement policy is nil")
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
// CheckFormat conducts an initial check of the v2 container data.
|
2020-11-03 09:03:41 +00:00
|
|
|
//
|
|
|
|
// It is expected that if a container fails this test,
|
|
|
|
// it will not be inner-ring approved.
|
|
|
|
func CheckFormat(c *container.Container) error {
|
2020-11-16 09:43:52 +00:00
|
|
|
if c.PlacementPolicy() == nil {
|
2020-11-03 09:03:41 +00:00
|
|
|
return errNilPolicy
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
if err := pkg.IsSupportedVersion(c.Version()); err != nil {
|
2020-11-03 09:03:41 +00:00
|
|
|
return errors.Wrap(err, "incorrect version")
|
|
|
|
}
|
|
|
|
|
2020-11-17 08:51:49 +00:00
|
|
|
if ln := len(c.OwnerID().ToV2().GetValue()); ln != owner.NEO3WalletSize {
|
|
|
|
return errors.Errorf("incorrect owner identifier: expected length %d != %d", owner.NEO3WalletSize, ln)
|
2020-11-03 09:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
if _, err := uuid.FromBytes(c.Nonce()); err != nil {
|
2020-11-03 09:03:41 +00:00
|
|
|
return errors.Wrap(err, "incorrect nonce")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|