nspcc-dev / neofs-sdk-go

Go implementation of NeoFS SDK
Apache License 2.0
5 stars 14 forks source link

Add SignedData func #513

Closed smallhive closed 1 year ago

smallhive commented 1 year ago

closes #510

Added func to known places with Sign method, plus for some places when I think it would be useful. Of course, in some way it is almost similar to Marshal func, but for consistency called it SignedData.

If I missed any place, just mention it

smallhive commented 1 year ago

what about object.Object?

Nothing, it has a different API for signing with different names. I tend to think we may rewrite it to be compatible with SignedComponent interface. I did these changes in the last commit

type SignedComponent interface { SignedData() []byte Sign(neofscrypto.Signer) error VerifySignature() bool }

I've added the suggested test, but we had some changes in code, according to this

cthulhu-rider commented 1 year ago

SignedData returns data that _would be signed_ breaks me a little. Mabe SignedData returns the data that is signed after a [Token.Sign] call?

// SignedData returns signed data of the T.
//
// See also [T.Sign].

?

smallhive commented 1 year ago

Updated. Make two test interfaces/functions for each user.Signer and neofscrypto.Signer. But Object functions I renamed to be compatible with new test interface and more important with other signable components

smallhive commented 1 year ago

No problem with the signer it is OK. Problem with checking functions

func SignedDataComponent(tb testing.TB, signer neofscrypto.Signer, cmp SignedComponent)

func SignedDataComponentUser(tb testing.TB, signer user.Signer, cmp SignedComponentUserSigner)

They don't want to accept the wrong types for cmp parameter.

Cannot use 'val' (type *session.Container) as the type SignedComponent Type does not implement 'SignedComponent'
need the method: Sign(neofscrypto.Signer) error 
have the method: Sign(signer user.Signer) error
smallhive commented 1 year ago

That is why we have two interfaces and two functions to check them

cthulhu-rider commented 1 year ago
need the method: Sign(neofscrypto.Signer) error 
have the method: Sign(signer user.Signer) error

needed method is more generic and may be implemented in-place