diff --git a/util/cryp/cryp.go b/util/cryp/cryp.go index 979713b8..0c39c083 100644 --- a/util/cryp/cryp.go +++ b/util/cryp/cryp.go @@ -22,7 +22,7 @@ import ( func Encrypt(key []byte, src []byte) (dst []byte, err error) { - if len(key) == 0 { + if len(key) == 0 || len(src) == 0 { return src, nil } @@ -50,7 +50,7 @@ func Encrypt(key []byte, src []byte) (dst []byte, err error) { func Decrypt(key []byte, src []byte) (dst []byte, err error) { - if len(key) == 0 { + if len(key) == 0 || len(src) == 0 { return src, nil } diff --git a/util/cryp/cryp_test.go b/util/cryp/cryp_test.go index 862b2f3f..f9c13c2f 100644 --- a/util/cryp/cryp_test.go +++ b/util/cryp/cryp_test.go @@ -38,6 +38,24 @@ func TestEmpty(t *testing.T) { } +func TestBlank(t *testing.T) { + + key := []byte("1hg7dbrma8ghe547") + str := []byte("") + + Convey("Cryptography should fail", t, func() { + enc, _ := Encrypt(key, str) + dec, _ := Decrypt(key, enc) + Convey("Encrypt", func() { + So(enc, ShouldResemble, str) + }) + Convey("Decrypt", func() { + So(dec, ShouldResemble, str) + }) + }) + +} + func TestInvalid(t *testing.T) { key := []byte("invalidkey")