frostfs-sdk-go/crypto/crypto_test.go
Pavel Karpy 4c779423f5 Move to frostfs-sdk-go
Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
2022-12-14 09:59:29 +03:00

47 lines
1 KiB
Go

package frostfscrypto_test
import (
"math/rand"
"testing"
"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"
"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)
var s frostfscrypto.Signature
var m refs.Signature
for _, f := range []func() frostfscrypto.Signer{
func() frostfscrypto.Signer {
return frostfsecdsa.Signer(k.PrivateKey)
},
func() frostfscrypto.Signer {
return frostfsecdsa.SignerRFC6979(k.PrivateKey)
},
func() frostfscrypto.Signer {
return frostfsecdsa.SignerWalletConnect(k.PrivateKey)
},
} {
signer := f()
err := s.Calculate(signer, data)
require.NoError(t, err)
s.WriteToV2(&m)
require.NoError(t, s.ReadFromV2(m))
valid := s.Verify(data)
require.True(t, valid, "type %T", signer)
}
}