From 9efc4ecd70ee2345203827353499a5c0375c493d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 22 Nov 2022 19:22:00 +0300 Subject: [PATCH] [#367] client: Allow to override key in Object.Hash RPC Signed-off-by: Evgenii Stratonikov --- client/object_hash.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/object_hash.go b/client/object_hash.go index 30ea8e3..d0810a7 100644 --- a/client/object_hash.go +++ b/client/object_hash.go @@ -2,6 +2,7 @@ package client import ( "context" + "crypto/ecdsa" "fmt" "github.com/nspcc-dev/neofs-api-go/v2/acl" @@ -27,6 +28,16 @@ type PrmObjectHash struct { csAlgo v2refs.ChecksumType addr v2refs.Address + + keySet bool + key ecdsa.PrivateKey +} + +// UseKey specifies private key to sign the requests. +// If key is not provided, then Client default key is used. +func (x *PrmObjectHash) UseKey(key ecdsa.PrivateKey) { + x.keySet = true + x.key = key } // MarkLocal tells the server to execute the operation locally. @@ -176,7 +187,12 @@ func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectH c.prepareRequest(&req, &prm.meta) req.SetBody(&prm.body) - err := signature.SignServiceMessage(&c.prm.key, &req) + key := c.prm.key + if prm.keySet { + key = prm.key + } + + err := signature.SignServiceMessage(&key, &req) if err != nil { return nil, fmt.Errorf("sign request: %w", err) }