Browse Source

Fix metalinter complaints

pull/1782/head
Ethan Frey 7 years ago
parent
commit
6f6bbf718e
6 changed files with 30 additions and 30 deletions
  1. +2
    -2
      keys/cryptostore/encoder.go
  2. +4
    -4
      keys/cryptostore/encoder_test.go
  3. +1
    -1
      keys/cryptostore/holder_test.go
  4. +3
    -3
      nano/keys.go
  5. +0
    -20
      nano/sign.go
  6. +20
    -0
      nano/sign_test.go

+ 2
- 2
keys/cryptostore/encoder.go View File

@ -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")
}


+ 4
- 4
keys/cryptostore/encoder_test.go View File

@ -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)
}

+ 1
- 1
keys/cryptostore/holder_test.go View File

@ -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,


+ 3
- 3
nano/keys.go View File

@ -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}
}

+ 0
- 20
nano/sign.go View File

@ -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[:]


+ 20
- 0
nano/sign_test.go View File

@ -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)


Loading…
Cancel
Save