diff --git a/whisper/whisperv5/api.go b/whisper/whisperv5/api.go index a93ac9baf1..e51d2ed1e4 100644 --- a/whisper/whisperv5/api.go +++ b/whisper/whisperv5/api.go @@ -138,18 +138,6 @@ func (api *PublicWhisperAPI) GetPublicKey(id string) (hexutil.Bytes, error) { return crypto.FromECDSAPub(&key.PublicKey), nil } -// todo: delete is tests pass -//func (api *PublicWhisperAPI) GetPublicKey(id string) (string, error) { -// if api.whisper == nil { -// return "", whisperOffLineErr -// } -// key, err := api.whisper.GetPrivateKey(id) -// if err != nil { -// return "", err -// } -// return common.ToHex(crypto.FromECDSAPub(&key.PublicKey)), nil -//} - // GetPrivateKey returns the private key for identity id func (api *PublicWhisperAPI) GetPrivateKey(id string) (string, error) { if api.whisper == nil { @@ -209,20 +197,6 @@ func (api *PublicWhisperAPI) GetSymmetricKey(name string) (hexutil.Bytes, error) return b, nil } -// todo: delete if tests pass -//func (api *PublicWhisperAPI) GetSymmetricKey(name string) (string, error) { -// if api.whisper == nil { -// return "", whisperOffLineErr -// } -// -// b, err := api.whisper.GetSymKey(name) -// if err != nil { -// return "", err -// } -// //return fmt.Sprintf("%x", b), nil // todo: delete if tests pass -// return common.ToHex(b), nil -//} - // DeleteSymmetricKey deletes the key associated with the name string if it exists. func (api *PublicWhisperAPI) DeleteSymmetricKey(name string) (bool, error) { if api.whisper == nil { diff --git a/whisper/whisperv5/envelope.go b/whisper/whisperv5/envelope.go index ef2c54a04d..e61918fcb5 100644 --- a/whisper/whisperv5/envelope.go +++ b/whisper/whisperv5/envelope.go @@ -120,7 +120,7 @@ func (e *Envelope) Seal(options *MessageParams) error { } if target > 0 && bestBit < target { - return fmt.Errorf("Failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime) + return fmt.Errorf("failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime) } return nil diff --git a/whisper/whisperv5/message.go b/whisper/whisperv5/message.go index 7b0a3be714..98443da131 100644 --- a/whisper/whisperv5/message.go +++ b/whisper/whisperv5/message.go @@ -168,7 +168,7 @@ func (msg *SentMessage) sign(key *ecdsa.PrivateKey) error { // encryptAsymmetric encrypts a message with a public key. func (msg *SentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error { if !ValidatePublicKey(key) { - return fmt.Errorf("Invalid public key provided for asymmetric encryption") + return fmt.Errorf("invalid public key provided for asymmetric encryption") } encrypted, err := ecies.Encrypt(crand.Reader, ecies.ImportECDSAPublic(key), msg.Raw, nil, nil) if err == nil { @@ -238,7 +238,7 @@ func (msg *SentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er } else if options.KeySym != nil { salt, nonce, err = msg.encryptSymmetric(options.KeySym) } else { - err = errors.New("Unable to encrypt the message: neither Dst nor Key") + err = errors.New("unable to encrypt the message: neither symmetric nor assymmmetric key provided") } if err != nil { @@ -270,7 +270,7 @@ func (msg *ReceivedMessage) decryptSymmetric(key []byte, salt []byte, nonce []by return err } if len(nonce) != aesgcm.NonceSize() { - info := fmt.Sprintf("Wrong AES nonce size - want: %d, got: %d", len(nonce), aesgcm.NonceSize()) + info := fmt.Sprintf("wrong AES nonce size - want: %d, got: %d", len(nonce), aesgcm.NonceSize()) log.Error(info) return errors.New(info) } @@ -342,7 +342,7 @@ func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey { pub, err := crypto.SigToPub(msg.hash(), msg.Signature) if err != nil { - log.Error(fmt.Sprintf("Could not get public key from signature: %v", err)) + log.Error(fmt.Sprintf("could not get public key from signature: %v", err)) return nil } return pub diff --git a/whisper/whisperv5/peer_test.go b/whisper/whisperv5/peer_test.go index a1a9a1ffa2..cd5153dfd5 100644 --- a/whisper/whisperv5/peer_test.go +++ b/whisper/whisperv5/peer_test.go @@ -120,9 +120,6 @@ func initialize(t *testing.T) { topics = append(topics, sharedTopic) f := Filter{KeySym: sharedKey} f.Topics = [][]byte{topics[0][:]} - // todo: delete if pass - //f.Topics = make([][]byte, 1) - //f.Topics[0] = topics[0][:] node.filerId, err = node.shh.Watch(&f) if err != nil { t.Fatalf("failed to install the filter: %s.", err) diff --git a/whisper/whisperv5/whisper.go b/whisper/whisperv5/whisper.go index a0f8bd97ba..95474550d0 100644 --- a/whisper/whisperv5/whisper.go +++ b/whisper/whisperv5/whisper.go @@ -132,7 +132,7 @@ func (w *Whisper) Version() uint { // SetMaxMessageLength sets the maximal message length allowed by this node func (w *Whisper) SetMaxMessageLength(val int) error { if val <= 0 { - return fmt.Errorf("Invalid message length: %d", val) + return fmt.Errorf("invalid message length: %d", val) } w.maxMsgLength = val return nil @@ -141,7 +141,7 @@ func (w *Whisper) SetMaxMessageLength(val int) error { // SetMinimumPoW sets the minimal PoW required by this node func (w *Whisper) SetMinimumPoW(val float64) error { if val <= 0.0 { - return fmt.Errorf("Invalid PoW: %f", val) + return fmt.Errorf("invalid PoW: %f", val) } w.minPoW = val return nil @@ -190,7 +190,6 @@ func (w *Whisper) SendP2PMessage(peerID []byte, envelope *Envelope) error { if err != nil { return err } - //return p2p.Send(p.ws, p2pCode, envelope) // todo: delete if tests pass return w.SendP2PDirect(p, envelope) } @@ -210,19 +209,19 @@ func (w *Whisper) NewKeyPair() (string, error) { return "", err } if !validatePrivateKey(key) { - return "", fmt.Errorf("Failed to generate valid key") + return "", fmt.Errorf("failed to generate valid key") } id, err := GenerateRandomID() if err != nil { - return "", fmt.Errorf("Failed to generate ID: %s", err) + return "", fmt.Errorf("failed to generate ID: %s", err) } w.keyMu.Lock() defer w.keyMu.Unlock() if w.privateKeys[id] != nil { - return "", fmt.Errorf("Failed to generate unique ID") + return "", fmt.Errorf("failed to generate unique ID") } w.privateKeys[id] = key return id, nil @@ -254,7 +253,7 @@ func (w *Whisper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error) { defer w.keyMu.RUnlock() key := w.privateKeys[id] if key == nil { - return nil, fmt.Errorf("GetPrivateKey: invalid id") + return nil, fmt.Errorf("invalid id") } return key, nil } @@ -282,14 +281,14 @@ func (w *Whisper) GenerateSymKey() (string, error) { id, err := GenerateRandomID() if err != nil { - return "", fmt.Errorf("Failed to generate ID: %s", err) + return "", fmt.Errorf("failed to generate ID: %s", err) } w.keyMu.Lock() defer w.keyMu.Unlock() if w.symKeys[id] != nil { - return "", fmt.Errorf("Failed to generate unique ID") + return "", fmt.Errorf("failed to generate unique ID") } w.symKeys[id] = derived return id, nil @@ -298,19 +297,19 @@ func (w *Whisper) GenerateSymKey() (string, error) { // AddSymKeyDirect stores the key, and returns its id. func (w *Whisper) AddSymKeyDirect(key []byte) (string, error) { if len(key) != aesKeyLength { - return "", fmt.Errorf("Wrong key size: %d", len(key)) + return "", fmt.Errorf("wrong key size: %d", len(key)) } id, err := GenerateRandomID() if err != nil { - return "", fmt.Errorf("Failed to generate ID: %s", err) + return "", fmt.Errorf("failed to generate ID: %s", err) } w.keyMu.Lock() defer w.keyMu.Unlock() if w.symKeys[id] != nil { - return "", fmt.Errorf("Failed to generate unique ID") + return "", fmt.Errorf("failed to generate unique ID") } w.symKeys[id] = key return id, nil @@ -320,10 +319,10 @@ func (w *Whisper) AddSymKeyDirect(key []byte) (string, error) { func (w *Whisper) AddSymKeyFromPassword(password string) (string, error) { id, err := GenerateRandomID() if err != nil { - return "", fmt.Errorf("Failed to generate ID: %s", err) + return "", fmt.Errorf("failed to generate ID: %s", err) } if w.HasSymKey(id) { - return "", fmt.Errorf("Failed to generate unique ID") + return "", fmt.Errorf("failed to generate unique ID") } derived, err := deriveKeyMaterial([]byte(password), EnvelopeVersion) @@ -336,7 +335,7 @@ func (w *Whisper) AddSymKeyFromPassword(password string) (string, error) { // double check is necessary, because deriveKeyMaterial() is very slow if w.symKeys[id] != nil { - return "", fmt.Errorf("Severe error: failed to generate unique ID") + return "", fmt.Errorf("critical error: failed to generate unique ID") } w.symKeys[id] = derived return id, nil @@ -749,7 +748,7 @@ func (s *Statistics) reset() { func ValidateKeyID(id string) error { const target = keyIdSize * 2 if len(id) != target { - return fmt.Errorf("Wrong size of key ID (expected %d bytes, got %d)", target, len(id)) + return fmt.Errorf("wrong size of key ID (expected %d bytes, got %d)", target, len(id)) } return nil }