forked from TrueCloudLab/frostfs-api-go
[#133] sdk: Use cid wrapper to sign container delete request
StableMarshalerWrapper is not suitable for container delete request, because it signs marshaled structure of container id. As for delete request, container id itself should be signed. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
acbdbd410e
commit
de505ddee9
1 changed files with 24 additions and 8 deletions
|
@ -13,6 +13,18 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type delContainerSignWrapper struct {
|
||||
body *v2container.DeleteRequestBody
|
||||
}
|
||||
|
||||
func (c delContainerSignWrapper) ReadSignedData(bytes []byte) ([]byte, error) {
|
||||
return c.body.GetContainerID().GetValue(), nil
|
||||
}
|
||||
|
||||
func (c delContainerSignWrapper) SignedDataSize() int {
|
||||
return len(c.body.GetContainerID().GetValue())
|
||||
}
|
||||
|
||||
func (c Client) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*container.ID, error) {
|
||||
switch c.remoteNode.Version.Major {
|
||||
case 2:
|
||||
|
@ -55,7 +67,7 @@ func (c Client) ListSelfContainers(ctx context.Context, opts ...CallOption) ([]*
|
|||
func (c Client) DeleteContainer(ctx context.Context, id *container.ID, opts ...CallOption) error {
|
||||
switch c.remoteNode.Version.Major {
|
||||
case 2:
|
||||
panic("not implemented")
|
||||
return c.delContainerV2(ctx, id, opts...)
|
||||
default:
|
||||
return unsupportedProtocolErr
|
||||
}
|
||||
|
@ -248,13 +260,17 @@ func (c Client) delContainerV2(ctx context.Context, id *container.ID, opts ...Ca
|
|||
reqBody.SetContainerID(id.ToV2())
|
||||
|
||||
// sign container
|
||||
signWrapper := v2signature.StableMarshalerWrapper{SM: reqBody.GetContainerID()}
|
||||
err := signature.SignDataWithHandler(c.key, signWrapper, func(key []byte, sig []byte) {
|
||||
containerSignature := new(refs.Signature)
|
||||
containerSignature.SetKey(key)
|
||||
containerSignature.SetSign(sig)
|
||||
reqBody.SetSignature(containerSignature)
|
||||
}, signature.SignWithRFC6979())
|
||||
err := signature.SignDataWithHandler(c.key,
|
||||
delContainerSignWrapper{
|
||||
body: reqBody,
|
||||
},
|
||||
func(key []byte, sig []byte) {
|
||||
containerSignature := new(refs.Signature)
|
||||
containerSignature.SetKey(key)
|
||||
containerSignature.SetSign(sig)
|
||||
reqBody.SetSignature(containerSignature)
|
||||
},
|
||||
signature.SignWithRFC6979())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue