Return an error when data is corrupt
This commit is contained in:
parent
48b644f399
commit
ed6a9555a1
2 changed files with 4 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue