From 6f6bbf718e4769fb321af88533769b2c1a154b72 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 24 Oct 2017 11:56:37 +0200 Subject: [PATCH] Fix metalinter complaints --- keys/cryptostore/encoder.go | 4 ++-- keys/cryptostore/encoder_test.go | 8 ++++---- keys/cryptostore/holder_test.go | 2 +- nano/keys.go | 6 +++--- nano/sign.go | 20 -------------------- nano/sign_test.go | 20 ++++++++++++++++++++ 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/keys/cryptostore/encoder.go b/keys/cryptostore/encoder.go index 0b957d826..531a534ad 100644 --- a/keys/cryptostore/encoder.go +++ b/keys/cryptostore/encoder.go @@ -39,7 +39,7 @@ func (e secretbox) Encrypt(privKey crypto.PrivKey, passphrase string) (saltBytes 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 // NOTE: Some keys weren't encrypted with a passphrase and hence we have the conditional if passphrase != "" { @@ -53,7 +53,7 @@ func (e secretbox) Decrypt(saltBytes []byte, encBytes []byte, passphrase string) return crypto.PrivKey{}, errors.Wrap(err, "Invalid Passphrase") } } - privKey, err = crypto.PrivKeyFromBytes(privKeyBytes) + privKey, err := crypto.PrivKeyFromBytes(privKeyBytes) if err != nil { return crypto.PrivKey{}, errors.Wrap(err, "Private Key") } diff --git a/keys/cryptostore/encoder_test.go b/keys/cryptostore/encoder_test.go index 9cde95a12..614286a19 100644 --- a/keys/cryptostore/encoder_test.go +++ b/keys/cryptostore/encoder_test.go @@ -68,8 +68,8 @@ func TestSecretBoxNoPass(t *testing.T) { assert, require := assert.New(t), require.New(t) enc := cryptostore.SecretBox - key, err := cryptostore.GenEd25519.Generate(cmn.RandBytes(16)) - require.NoError(err) + key, rerr := cryptostore.GenEd25519.Generate(cmn.RandBytes(16)) + require.NoError(rerr) cases := []struct { encode string @@ -99,7 +99,7 @@ func TestSecretBoxNoPass(t *testing.T) { // now let's make sure raw bytes also work... b := key.Bytes() - pk, err := enc.Decrypt(nil, b, "") - require.Nil(err, "%+v", err) + pk, rerr := enc.Decrypt(nil, b, "") + require.NoError(rerr) assert.Equal(key, pk) } diff --git a/keys/cryptostore/holder_test.go b/keys/cryptostore/holder_test.go index 899f51f02..3709cc55d 100644 --- a/keys/cryptostore/holder_test.go +++ b/keys/cryptostore/holder_test.go @@ -320,7 +320,7 @@ func TestSeedPhrase(t *testing.T) { assert.Equal(info.PubKey, newInfo.PubKey) } -func ExampleStore() { +func ExampleNew() { // Select the encryption and storage for your cryptostore cstore := cryptostore.New( cryptostore.SecretBox, diff --git a/nano/keys.go b/nano/keys.go index eb531ef41..a6d3ea8e4 100644 --- a/nano/keys.go +++ b/nano/keys.go @@ -280,15 +280,15 @@ func init() { // Wrap fulfils interface for PrivKey struct func (pk *PrivKeyLedgerEd25519) Wrap() crypto.PrivKey { - return crypto.PrivKey{pk} + return crypto.PrivKey{PrivKeyInner: pk} } // Wrap fulfils interface for PrivKey struct func (pk MockPrivKeyLedgerEd25519) Wrap() crypto.PrivKey { - return crypto.PrivKey{pk} + return crypto.PrivKey{PrivKeyInner: pk} } // Wrap fulfils interface for PubKey struct func (pk PubKeyLedgerEd25519) Wrap() crypto.PubKey { - return crypto.PubKey{pk} + return crypto.PubKey{PubKeyInner: pk} } diff --git a/nano/sign.go b/nano/sign.go index 874d134e8..c40801583 100644 --- a/nano/sign.go +++ b/nano/sign.go @@ -5,8 +5,6 @@ import ( "crypto/sha512" "github.com/pkg/errors" - - crypto "github.com/tendermint/go-crypto" ) const ( @@ -59,24 +57,6 @@ func parseDigest(resp []byte) (key, sig []byte, err error) { 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 { res := sha512.Sum512(data) return res[:] diff --git a/nano/sign_test.go b/nano/sign_test.go index 89bd7568e..04a6d0be7 100644 --- a/nano/sign_test.go +++ b/nano/sign_test.go @@ -4,10 +4,30 @@ import ( "encoding/hex" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "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) { assert, require := assert.New(t), require.New(t)