mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-29 20:51:45 +00:00
Fix metalinter complaints
This commit is contained in:
@ -39,7 +39,7 @@ func (e secretbox) Encrypt(privKey crypto.PrivKey, passphrase string) (saltBytes
|
|||||||
return saltBytes, crypto.EncryptSymmetric(privKeyBytes, key), nil
|
return saltBytes, crypto.EncryptSymmetric(privKeyBytes, key), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e secretbox) Decrypt(saltBytes []byte, encBytes []byte, passphrase string) (privKey crypto.PrivKey, err error) {
|
func (e secretbox) Decrypt(saltBytes []byte, encBytes []byte, passphrase string) (crypto.PrivKey, error) {
|
||||||
privKeyBytes := encBytes
|
privKeyBytes := encBytes
|
||||||
// NOTE: Some keys weren't encrypted with a passphrase and hence we have the conditional
|
// NOTE: Some keys weren't encrypted with a passphrase and hence we have the conditional
|
||||||
if passphrase != "" {
|
if passphrase != "" {
|
||||||
@ -53,7 +53,7 @@ func (e secretbox) Decrypt(saltBytes []byte, encBytes []byte, passphrase string)
|
|||||||
return crypto.PrivKey{}, errors.Wrap(err, "Invalid Passphrase")
|
return crypto.PrivKey{}, errors.Wrap(err, "Invalid Passphrase")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
privKey, err = crypto.PrivKeyFromBytes(privKeyBytes)
|
privKey, err := crypto.PrivKeyFromBytes(privKeyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return crypto.PrivKey{}, errors.Wrap(err, "Private Key")
|
return crypto.PrivKey{}, errors.Wrap(err, "Private Key")
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ func TestSecretBoxNoPass(t *testing.T) {
|
|||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
enc := cryptostore.SecretBox
|
enc := cryptostore.SecretBox
|
||||||
|
|
||||||
key, err := cryptostore.GenEd25519.Generate(cmn.RandBytes(16))
|
key, rerr := cryptostore.GenEd25519.Generate(cmn.RandBytes(16))
|
||||||
require.NoError(err)
|
require.NoError(rerr)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
encode string
|
encode string
|
||||||
@ -99,7 +99,7 @@ func TestSecretBoxNoPass(t *testing.T) {
|
|||||||
|
|
||||||
// now let's make sure raw bytes also work...
|
// now let's make sure raw bytes also work...
|
||||||
b := key.Bytes()
|
b := key.Bytes()
|
||||||
pk, err := enc.Decrypt(nil, b, "")
|
pk, rerr := enc.Decrypt(nil, b, "")
|
||||||
require.Nil(err, "%+v", err)
|
require.NoError(rerr)
|
||||||
assert.Equal(key, pk)
|
assert.Equal(key, pk)
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ func TestSeedPhrase(t *testing.T) {
|
|||||||
assert.Equal(info.PubKey, newInfo.PubKey)
|
assert.Equal(info.PubKey, newInfo.PubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleStore() {
|
func ExampleNew() {
|
||||||
// Select the encryption and storage for your cryptostore
|
// Select the encryption and storage for your cryptostore
|
||||||
cstore := cryptostore.New(
|
cstore := cryptostore.New(
|
||||||
cryptostore.SecretBox,
|
cryptostore.SecretBox,
|
||||||
|
@ -280,15 +280,15 @@ func init() {
|
|||||||
|
|
||||||
// Wrap fulfils interface for PrivKey struct
|
// Wrap fulfils interface for PrivKey struct
|
||||||
func (pk *PrivKeyLedgerEd25519) Wrap() crypto.PrivKey {
|
func (pk *PrivKeyLedgerEd25519) Wrap() crypto.PrivKey {
|
||||||
return crypto.PrivKey{pk}
|
return crypto.PrivKey{PrivKeyInner: pk}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap fulfils interface for PrivKey struct
|
// Wrap fulfils interface for PrivKey struct
|
||||||
func (pk MockPrivKeyLedgerEd25519) Wrap() crypto.PrivKey {
|
func (pk MockPrivKeyLedgerEd25519) Wrap() crypto.PrivKey {
|
||||||
return crypto.PrivKey{pk}
|
return crypto.PrivKey{PrivKeyInner: pk}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap fulfils interface for PubKey struct
|
// Wrap fulfils interface for PubKey struct
|
||||||
func (pk PubKeyLedgerEd25519) Wrap() crypto.PubKey {
|
func (pk PubKeyLedgerEd25519) Wrap() crypto.PubKey {
|
||||||
return crypto.PubKey{pk}
|
return crypto.PubKey{PubKeyInner: pk}
|
||||||
}
|
}
|
||||||
|
20
nano/sign.go
20
nano/sign.go
@ -5,8 +5,6 @@ import (
|
|||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -59,24 +57,6 @@ func parseDigest(resp []byte) (key, sig []byte, err error) {
|
|||||||
return key, sig, nil
|
return key, sig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEdKey(data []byte) (key crypto.PubKey, err error) {
|
|
||||||
ed := crypto.PubKeyEd25519{}
|
|
||||||
if len(data) < len(ed) {
|
|
||||||
return key, errors.Errorf("Key length too short: %d", len(data))
|
|
||||||
}
|
|
||||||
copy(ed[:], data)
|
|
||||||
return ed.Wrap(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseSig(data []byte) (key crypto.Signature, err error) {
|
|
||||||
ed := crypto.SignatureEd25519{}
|
|
||||||
if len(data) < len(ed) {
|
|
||||||
return key, errors.Errorf("Sig length too short: %d", len(data))
|
|
||||||
}
|
|
||||||
copy(ed[:], data)
|
|
||||||
return ed.Wrap(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func hashMsg(data []byte) []byte {
|
func hashMsg(data []byte) []byte {
|
||||||
res := sha512.Sum512(data)
|
res := sha512.Sum512(data)
|
||||||
return res[:]
|
return res[:]
|
||||||
|
@ -4,10 +4,30 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
crypto "github.com/tendermint/go-crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func parseEdKey(data []byte) (key crypto.PubKey, err error) {
|
||||||
|
ed := crypto.PubKeyEd25519{}
|
||||||
|
if len(data) < len(ed) {
|
||||||
|
return key, errors.Errorf("Key length too short: %d", len(data))
|
||||||
|
}
|
||||||
|
copy(ed[:], data)
|
||||||
|
return ed.Wrap(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseSig(data []byte) (key crypto.Signature, err error) {
|
||||||
|
ed := crypto.SignatureEd25519{}
|
||||||
|
if len(data) < len(ed) {
|
||||||
|
return key, errors.Errorf("Sig length too short: %d", len(data))
|
||||||
|
}
|
||||||
|
copy(ed[:], data)
|
||||||
|
return ed.Wrap(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseDigest(t *testing.T) {
|
func TestParseDigest(t *testing.T) {
|
||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user