added nil check

This commit is contained in:
obscuren 2015-01-02 13:00:25 +01:00
parent 58a79af01a
commit 6abd465f78
2 changed files with 3 additions and 3 deletions

View File

@ -79,6 +79,7 @@ func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) {
if prv != nil {
message.Payload, err = crypto.Decrypt(prv, payload)
switch err {
case nil: // OK
case ecies.ErrInvalidPublicKey: // Payload isn't encrypted
message.Payload = payload
return &message, err

View File

@ -40,12 +40,11 @@ func TestMessageEncryptDecrypt(t *testing.T) {
msg1, err := envelope.Open(prv2)
if err != nil {
fmt.Println(err)
t.Error(err)
t.FailNow()
}
if !bytes.Equal(msg1.Payload, data) {
fmt.Println("encryption error. data did not match")
t.FailNow()
t.Error("encryption error. data did not match")
}
}