mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-15 16:11:21 +00:00
Merge pull request #49 from tendermint/pubKey-invalid-data-returns-empty-pubKey
PubKeyFromBytes: return zero value PubKey on error
This commit is contained in:
commit
b4f04f196c
@ -14,8 +14,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error) {
|
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error) {
|
||||||
err = wire.ReadBinaryBytes(pubKeyBytes, &pubKey)
|
if err := wire.ReadBinaryBytes(pubKeyBytes, &pubKey); err != nil {
|
||||||
return
|
return PubKey{}, err
|
||||||
|
}
|
||||||
|
return pubKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcutil/base58"
|
"github.com/btcsuite/btcutil/base58"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
type keyData struct {
|
type keyData struct {
|
||||||
@ -39,3 +40,9 @@ func TestPubKeySecp256k1Address(t *testing.T) {
|
|||||||
assert.Equal(t, addr, addrB, "Expected addresses to match")
|
assert.Equal(t, addr, addrB, "Expected addresses to match")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPubKeyInvalidDataProperReturnsEmpty(t *testing.T) {
|
||||||
|
pk, err := PubKeyFromBytes([]byte("foo"))
|
||||||
|
require.NotNil(t, err, "expecting a non-nil error")
|
||||||
|
require.True(t, pk.Empty(), "expecting an empty public key on error")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user