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 (
|
import (
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"errors"
|
||||||
"github.com/abcum/surreal/util/rand"
|
"github.com/abcum/surreal/util/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ func Decrypt(key []byte, src []byte) (dst []byte, err error) {
|
||||||
|
|
||||||
// Corrupt
|
// Corrupt
|
||||||
if len(src) < 12 {
|
if len(src) < 12 {
|
||||||
return src, nil
|
return src, errors.New("Invalid data")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initiate AES
|
// Initiate AES
|
||||||
|
|
|
@ -62,8 +62,9 @@ func TestCorrupt(t *testing.T) {
|
||||||
enc := []byte("corrupt")
|
enc := []byte("corrupt")
|
||||||
|
|
||||||
Convey("Cryptography should fail", t, func() {
|
Convey("Cryptography should fail", t, func() {
|
||||||
dec, _ := Decrypt(key, enc)
|
dec, err := Decrypt(key, enc)
|
||||||
Convey("Decrypt", func() {
|
Convey("Decrypt", func() {
|
||||||
|
So(err, ShouldNotBeNil)
|
||||||
So(dec, ShouldResemble, enc)
|
So(dec, ShouldResemble, enc)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue