From ed6a9555a1a4163841701040a908300ffa4748be Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 14 Sep 2016 17:02:48 +0100 Subject: [PATCH] Return an error when data is corrupt --- util/cryp/cryp.go | 3 ++- util/cryp/cryp_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/util/cryp/cryp.go b/util/cryp/cryp.go index 78501ed6..f920235f 100644 --- a/util/cryp/cryp.go +++ b/util/cryp/cryp.go @@ -17,6 +17,7 @@ package cryp import ( "crypto/aes" "crypto/cipher" + "errors" "github.com/abcum/surreal/util/rand" ) @@ -53,7 +54,7 @@ func Decrypt(key []byte, src []byte) (dst []byte, err error) { // Corrupt if len(src) < 12 { - return src, nil + return src, errors.New("Invalid data") } // Initiate AES diff --git a/util/cryp/cryp_test.go b/util/cryp/cryp_test.go index cb198f0f..2dd89dcf 100644 --- a/util/cryp/cryp_test.go +++ b/util/cryp/cryp_test.go @@ -62,8 +62,9 @@ func TestCorrupt(t *testing.T) { enc := []byte("corrupt") Convey("Cryptography should fail", t, func() { - dec, _ := Decrypt(key, enc) + dec, err := Decrypt(key, enc) Convey("Decrypt", func() { + So(err, ShouldNotBeNil) So(dec, ShouldResemble, enc) }) })