From 6df8c84fc26703fea60e4897ef22a11fcd80aebe Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 11 Jan 2021 16:51:29 +0300 Subject: [PATCH] [#290] cmd/cli: Add salt flag to object hash command Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/object.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index bdb9cec9b..60b517993 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -30,6 +30,10 @@ const ( getRangeCmdLongDesc = "Get payload range data of an object" ) +const ( + getRangeHashSaltFlag = "salt" +) + var ( // objectCmd represents the object command objectCmd = &cobra.Command{ @@ -157,6 +161,7 @@ func init() { _ = objectHashCmd.MarkFlagRequired("oid") objectHashCmd.Flags().String("range", "", "Range to take hash from in the form offset1:length1,...") objectHashCmd.Flags().String("type", hashSha256, "Hash type. Either 'sha256' or 'tz'") + objectHashCmd.Flags().String(getRangeHashSaltFlag, "", "Salt in hex format") objectCmd.AddCommand(objectRangeCmd) objectRangeCmd.Flags().String("cid", "", "Container ID") @@ -427,6 +432,11 @@ func getObjectHash(cmd *cobra.Command, _ []string) error { return err } + salt, err := hex.DecodeString(cmd.Flag(getRangeHashSaltFlag).Value.String()) + if err != nil { + return err + } + ctx := context.Background() cli, tok, err := initSession(ctx) if err != nil { @@ -456,7 +466,11 @@ func getObjectHash(cmd *cobra.Command, _ []string) error { return nil } - ps := new(client.RangeChecksumParams).WithAddress(objAddr).WithRangeList(ranges...) + ps := new(client.RangeChecksumParams). + WithAddress(objAddr). + WithRangeList(ranges...). + WithSalt(salt) + switch typ { case hashSha256: res, err := cli.ObjectPayloadRangeSHA256(ctx, ps,