From 1482b0c5d09e782967d50556736f680ae3ba2e89 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 19 Oct 2020 14:51:47 +0300 Subject: [PATCH] [#79] Simplify getCID and getOID functions in CLI Parser from string is available in neofs-api-go. Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/object.go | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index ac402a5797..508a2e7b4b 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "crypto/sha256" "encoding/hex" "encoding/json" "errors" @@ -14,7 +13,6 @@ import ( "strconv" "strings" - "github.com/mr-tron/base58" "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" @@ -453,30 +451,16 @@ func parseObjectAttrs(cmd *cobra.Command) ([]*object.Attribute, error) { func getCID(cmd *cobra.Command) (*container.ID, error) { cid := container.NewID() - var v [32]byte - b, err := base58.Decode(cmd.Flag("cid").Value.String()) - if err != nil { - return nil, err - } else if len(b) != sha256.Size { - return nil, errors.New("invalid length") - } - copy(v[:], b) - cid.SetSHA256(v) - return cid, nil + err := cid.Parse(cmd.Flag("cid").Value.String()) + + return cid, err } func getOID(cmd *cobra.Command) (*object.ID, error) { oid := object.NewID() - var v [32]byte - b, err := base58.Decode(cmd.Flag("oid").Value.String()) - if err != nil { - return nil, err - } else if len(b) != sha256.Size { - return nil, errors.New("invalid length") - } - copy(v[:], b) - oid.SetSHA256(v) - return oid, nil + err := oid.Parse(cmd.Flag("oid").Value.String()) + + return oid, err } func getObjectAddress(cmd *cobra.Command) (*object.Address, error) {