2022-12-13 14:36:35 +00:00
|
|
|
package frostfscrypto_test
|
2022-04-05 11:13:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
frostfscrypto "github.com/TrueCloudLab/frostfs-sdk-go/crypto"
|
|
|
|
frostfsecdsa "github.com/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
2022-04-05 11:13:34 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSignature(t *testing.T) {
|
|
|
|
data := make([]byte, 512)
|
|
|
|
rand.Read(data)
|
|
|
|
|
|
|
|
k, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
var s frostfscrypto.Signature
|
2022-04-05 11:13:34 +00:00
|
|
|
var m refs.Signature
|
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
for _, f := range []func() frostfscrypto.Signer{
|
|
|
|
func() frostfscrypto.Signer {
|
|
|
|
return frostfsecdsa.Signer(k.PrivateKey)
|
2022-04-05 11:13:34 +00:00
|
|
|
},
|
2022-12-13 14:36:35 +00:00
|
|
|
func() frostfscrypto.Signer {
|
|
|
|
return frostfsecdsa.SignerRFC6979(k.PrivateKey)
|
2022-04-05 11:13:34 +00:00
|
|
|
},
|
2022-12-13 14:36:35 +00:00
|
|
|
func() frostfscrypto.Signer {
|
|
|
|
return frostfsecdsa.SignerWalletConnect(k.PrivateKey)
|
2022-03-10 12:25:14 +00:00
|
|
|
},
|
2022-04-05 11:13:34 +00:00
|
|
|
} {
|
|
|
|
signer := f()
|
|
|
|
|
|
|
|
err := s.Calculate(signer, data)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
s.WriteToV2(&m)
|
|
|
|
|
2022-07-07 10:51:05 +00:00
|
|
|
require.NoError(t, s.ReadFromV2(m))
|
2022-04-05 11:13:34 +00:00
|
|
|
|
|
|
|
valid := s.Verify(data)
|
2022-03-10 12:25:14 +00:00
|
|
|
require.True(t, valid, "type %T", signer)
|
2022-04-05 11:13:34 +00:00
|
|
|
}
|
|
|
|
}
|