2022-12-13 14:36:35 +00:00
|
|
|
package frostfscrypto_test
|
2022-04-05 11:13:34 +00:00
|
|
|
|
|
|
|
import (
|
2023-09-08 14:15:08 +00:00
|
|
|
"crypto/rand"
|
2022-04-05 11:13:34 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
2023-03-07 11:20:03 +00:00
|
|
|
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
|
|
|
|
frostfsecdsa "git.frostfs.info/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
|
|
|
}
|
|
|
|
}
|