2020-12-24 09:28:33 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-17 12:56:17 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-12-24 09:28:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewVerifiedFromV2 constructs Container from NeoFS API V2 Container message.
|
|
|
|
// Returns error if message does not meet NeoFS API V2 specification.
|
|
|
|
//
|
|
|
|
// Additionally checks if message carries supported version.
|
|
|
|
func NewVerifiedFromV2(cnrV2 *container.Container) (*Container, error) {
|
|
|
|
cnr := NewContainerFromV2(cnrV2)
|
|
|
|
|
|
|
|
// check version support
|
|
|
|
if err := pkg.IsSupportedVersion(cnr.Version()); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// check nonce format
|
|
|
|
if _, err := cnr.NonceUUID(); err != nil {
|
2021-05-17 12:56:17 +00:00
|
|
|
return nil, fmt.Errorf("invalid nonce: %w", err)
|
2020-12-24 09:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cnr, nil
|
|
|
|
}
|