frostfs-sdk-go/crypto/crypto_test.go
Pavel Pogodaev 7d6ce3928b
All checks were successful
DCO / DCO (pull_request) Successful in 57s
Tests and linters / Tests (pull_request) Successful in 1m14s
Tests and linters / Lint (pull_request) Successful in 1m36s
[#276] Merge repo with frostfs-api-go
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
2024-10-12 12:48:38 +03:00

47 lines
1 KiB
Go

package frostfscrypto_test
import (
"crypto/rand"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
frostfsecdsa "git.frostfs.info/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)
}
}