mirror of
https://github.com/status-im/whisper.git
synced 2025-02-08 08:53:36 +00:00
added nil check
This commit is contained in:
parent
58a79af01a
commit
6abd465f78
@ -79,6 +79,7 @@ func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) {
|
|||||||
if prv != nil {
|
if prv != nil {
|
||||||
message.Payload, err = crypto.Decrypt(prv, payload)
|
message.Payload, err = crypto.Decrypt(prv, payload)
|
||||||
switch err {
|
switch err {
|
||||||
|
case nil: // OK
|
||||||
case ecies.ErrInvalidPublicKey: // Payload isn't encrypted
|
case ecies.ErrInvalidPublicKey: // Payload isn't encrypted
|
||||||
message.Payload = payload
|
message.Payload = payload
|
||||||
return &message, err
|
return &message, err
|
||||||
|
@ -40,12 +40,11 @@ func TestMessageEncryptDecrypt(t *testing.T) {
|
|||||||
|
|
||||||
msg1, err := envelope.Open(prv2)
|
msg1, err := envelope.Open(prv2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
t.Error(err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(msg1.Payload, data) {
|
if !bytes.Equal(msg1.Payload, data) {
|
||||||
fmt.Println("encryption error. data did not match")
|
t.Error("encryption error. data did not match")
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user