mirror of https://github.com/status-im/op-geth.git
whisper: renamed errors
This commit is contained in:
parent
b6b0e00198
commit
4a1d516d78
|
@ -18,11 +18,11 @@ package whisperv5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/ecdsa"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"crypto/ecdsa"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
@ -37,12 +37,12 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
SymAsymErr = errors.New("specify either a symetric or a asymmetric key")
|
ErrSymAsym = errors.New("specify either a symetric or a asymmetric key")
|
||||||
InvalidSymmetricKeyErr = errors.New("invalid symmetric key")
|
ErrInvalidSymmetricKey = errors.New("invalid symmetric key")
|
||||||
InvalidPublicKeyErr = errors.New("invalid public key")
|
ErrInvalidPublicKey = errors.New("invalid public key")
|
||||||
InvalidSigningPubKey = errors.New("invalid signing public key")
|
ErrInvalidSigningPubKey = errors.New("invalid signing public key")
|
||||||
TooLowPoWErr = errors.New("message rejected, PoW too low")
|
ErrTooLowPoW = errors.New("message rejected, PoW too low")
|
||||||
NoTopicsErr = errors.New("missing topic(s)")
|
ErrNoTopics = errors.New("missing topic(s)")
|
||||||
)
|
)
|
||||||
|
|
||||||
// PublicWhisperAPI provides the whisper RPC service that can be
|
// PublicWhisperAPI provides the whisper RPC service that can be
|
||||||
|
@ -245,7 +245,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
|
||||||
|
|
||||||
// user must specify either a symmetric or a asymmetric key
|
// user must specify either a symmetric or a asymmetric key
|
||||||
if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) {
|
if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) {
|
||||||
return false, SymAsymErr
|
return false, ErrSymAsym
|
||||||
}
|
}
|
||||||
|
|
||||||
params := &MessageParams{
|
params := &MessageParams{
|
||||||
|
@ -267,13 +267,13 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
|
||||||
// Set symmetric key that is used to encrypt the message
|
// Set symmetric key that is used to encrypt the message
|
||||||
if symKeyGiven {
|
if symKeyGiven {
|
||||||
if params.Topic == (TopicType{}) { // topics are mandatory with symmetric encryption
|
if params.Topic == (TopicType{}) { // topics are mandatory with symmetric encryption
|
||||||
return false, NoTopicsErr
|
return false, ErrNoTopics
|
||||||
}
|
}
|
||||||
if params.KeySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
|
if params.KeySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if !validateSymmetricKey(params.KeySym) {
|
if !validateSymmetricKey(params.KeySym) {
|
||||||
return false, InvalidSymmetricKeyErr
|
return false, ErrInvalidSymmetricKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
|
||||||
if pubKeyGiven {
|
if pubKeyGiven {
|
||||||
params.Dst = crypto.ToECDSAPub(req.PublicKey)
|
params.Dst = crypto.ToECDSAPub(req.PublicKey)
|
||||||
if !ValidatePublicKey(params.Dst) {
|
if !ValidatePublicKey(params.Dst) {
|
||||||
return false, InvalidPublicKeyErr
|
return false, ErrInvalidPublicKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
|
||||||
|
|
||||||
// ensure that the message PoW meets the node's minimum accepted PoW
|
// ensure that the message PoW meets the node's minimum accepted PoW
|
||||||
if req.PowTarget < api.w.MinPow() {
|
if req.PowTarget < api.w.MinPow() {
|
||||||
return false, TooLowPoWErr
|
return false, ErrTooLowPoW
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, api.w.Send(env)
|
return true, api.w.Send(env)
|
||||||
|
@ -346,7 +346,7 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.
|
||||||
|
|
||||||
// user must specify either a symmetric or a asymmetric key
|
// user must specify either a symmetric or a asymmetric key
|
||||||
if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) {
|
if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) {
|
||||||
return nil, SymAsymErr
|
return nil, ErrSymAsym
|
||||||
}
|
}
|
||||||
|
|
||||||
filter := Filter{
|
filter := Filter{
|
||||||
|
@ -358,7 +358,7 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.
|
||||||
if len(crit.Sig) > 0 {
|
if len(crit.Sig) > 0 {
|
||||||
filter.Src = crypto.ToECDSAPub(crit.Sig)
|
filter.Src = crypto.ToECDSAPub(crit.Sig)
|
||||||
if !ValidatePublicKey(filter.Src) {
|
if !ValidatePublicKey(filter.Src) {
|
||||||
return nil, InvalidSigningPubKey
|
return nil, ErrInvalidSigningPubKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,14 +372,14 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.
|
||||||
// listen for message that are encrypted with the given symmetric key
|
// listen for message that are encrypted with the given symmetric key
|
||||||
if symKeyGiven {
|
if symKeyGiven {
|
||||||
if len(filter.Topics) == 0 {
|
if len(filter.Topics) == 0 {
|
||||||
return nil, NoTopicsErr
|
return nil, ErrNoTopics
|
||||||
}
|
}
|
||||||
key, err := api.w.GetSymKey(crit.SymKeyID)
|
key, err := api.w.GetSymKey(crit.SymKeyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !validateSymmetricKey(key) {
|
if !validateSymmetricKey(key) {
|
||||||
return nil, InvalidSymmetricKeyErr
|
return nil, ErrInvalidSymmetricKey
|
||||||
}
|
}
|
||||||
filter.KeySym = key
|
filter.KeySym = key
|
||||||
filter.SymKeyHash = crypto.Keccak256Hash(filter.KeySym)
|
filter.SymKeyHash = crypto.Keccak256Hash(filter.KeySym)
|
||||||
|
@ -389,7 +389,7 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.
|
||||||
if pubKeyGiven {
|
if pubKeyGiven {
|
||||||
filter.KeyAsym, err = api.w.GetPrivateKey(crit.PrivateKeyID)
|
filter.KeyAsym, err = api.w.GetPrivateKey(crit.PrivateKeyID)
|
||||||
if err != nil || filter.KeyAsym == nil {
|
if err != nil || filter.KeyAsym == nil {
|
||||||
return nil, InvalidPublicKeyErr
|
return nil, ErrInvalidPublicKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,13 +536,13 @@ func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) {
|
||||||
|
|
||||||
// user must specify either a symmetric or a asymmetric key
|
// user must specify either a symmetric or a asymmetric key
|
||||||
if (symKeyGiven && asymKeyGiven) || (!symKeyGiven && !asymKeyGiven) {
|
if (symKeyGiven && asymKeyGiven) || (!symKeyGiven && !asymKeyGiven) {
|
||||||
return "", SymAsymErr
|
return "", ErrSymAsym
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.Sig) > 0 {
|
if len(req.Sig) > 0 {
|
||||||
src = crypto.ToECDSAPub(req.Sig)
|
src = crypto.ToECDSAPub(req.Sig)
|
||||||
if !ValidatePublicKey(src) {
|
if !ValidatePublicKey(src) {
|
||||||
return "", InvalidSigningPubKey
|
return "", ErrInvalidSigningPubKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if !validateSymmetricKey(keySym) {
|
if !validateSymmetricKey(keySym) {
|
||||||
return "", InvalidSymmetricKeyErr
|
return "", ErrInvalidSymmetricKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,10 @@ package whisperv5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/ecdsa"
|
||||||
mrand "math/rand"
|
mrand "math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
"crypto/ecdsa"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWhisperBasic(t *testing.T) {
|
func TestWhisperBasic(t *testing.T) {
|
||||||
|
@ -120,11 +120,11 @@ func TestWhisperBasic(t *testing.T) {
|
||||||
|
|
||||||
func TestWhisperAsymmetricKeyImport(t *testing.T) {
|
func TestWhisperAsymmetricKeyImport(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
w = New(&DefaultConfig)
|
w = New(&DefaultConfig)
|
||||||
privateKeys []*ecdsa.PrivateKey
|
privateKeys []*ecdsa.PrivateKey
|
||||||
)
|
)
|
||||||
|
|
||||||
for i:=0; i < 50; i++ {
|
for i := 0; i < 50; i++ {
|
||||||
id, err := w.NewKeyPair()
|
id, err := w.NewKeyPair()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not generate key: %v", err)
|
t.Fatalf("could not generate key: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue