Skip to content

Commit

Permalink
op-node: Properly return error on bad hex data (ethereum-optimism#3365)
Browse files Browse the repository at this point in the history
* op-node: Properly return error on bad hex data

* Add forgotten err to Pub2PeerID

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mslipper and mergify[bot] authored Sep 9, 2022
1 parent 21627e4 commit c564e4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions op-node/cmd/p2p/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func Priv2PeerID(r io.Reader) (string, error) {
b, err := readHexData(r)
if err != nil {
return "", nil
return "", err
}

p, err := crypto.UnmarshalSecp256k1PrivateKey(b)
Expand All @@ -34,7 +34,7 @@ func Priv2PeerID(r io.Reader) (string, error) {
func Pub2PeerID(r io.Reader) (string, error) {
b, err := readHexData(r)
if err != nil {
return "", nil
return "", err
}

p, err := crypto.UnmarshalSecp256k1PublicKey(b)
Expand Down
4 changes: 4 additions & 0 deletions op-node/cmd/p2p/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ func TestPrivPub2PeerID(t *testing.T) {
require.NoError(t, err)
require.Equal(t, pubPidLib.String(), pubPidImpl)
})
t.Run("with bad hex", func(t *testing.T) {
_, err := Priv2PeerID(bytes.NewReader([]byte("I am not hex.")))
require.Error(t, err)
})
}

0 comments on commit c564e4e

Please sign in to comment.