github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/util/signature/sign_test.go (about) 1 package signature 2 3 import ( 4 "crypto/ecdsa" 5 "crypto/elliptic" 6 "crypto/rand" 7 "testing" 8 9 "github.com/TrueCloudLab/frostfs-api-go/v2/refs" 10 "github.com/stretchr/testify/require" 11 ) 12 13 type testData struct { 14 data []byte 15 sig *refs.Signature 16 } 17 18 func (t testData) SignedDataSize() int { return len(t.data) } 19 func (t testData) ReadSignedData(data []byte) ([]byte, error) { 20 n := copy(data, t.data) 21 return data[:n], nil 22 } 23 func (t testData) GetSignature() *refs.Signature { return t.sig } 24 func (t *testData) SetSignature(s *refs.Signature) { t.sig = s } 25 26 func TestWalletConnect(t *testing.T) { 27 testCases := [...][]byte{ 28 {}, 29 {0}, 30 {1, 2}, 31 {3, 4, 5}, 32 {6, 7, 8, 9, 10, 11, 12}, 33 } 34 35 pk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) 36 require.NoError(t, err) 37 38 for _, tc := range testCases { 39 td := &testData{data: tc} 40 require.NoError(t, SignData(pk, td, SignWithWalletConnect())) 41 require.Equal(t, refs.ECDSA_RFC6979_SHA256_WALLET_CONNECT, td.sig.GetScheme()) 42 require.NoError(t, VerifyData(td)) 43 } 44 }