diff options
author | rsiddharth <s@ricketyspace.net> | 2021-02-11 23:00:49 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2021-02-11 23:00:49 -0500 |
commit | aaabeb704f200023aa544d70eaca9f363e8da975 (patch) | |
tree | 005886d6c8dc5b04160e5eec7fd561ad0d7bdd86 /lib | |
parent | 99a4f2f4e29e7963977ba16bf3aba3463a1c61d1 (diff) |
lib: update Pkcs7PaddingUndo, AESDecryptCBC
Add error as the second return value to Pkcs7PaddingUndo and
AESDecryptCBC.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/aes.go | 8 | ||||
-rw-r--r-- | lib/blocks.go | 6 |
2 files changed, 7 insertions, 7 deletions
@@ -23,7 +23,7 @@ func AESEncryptCBC(plain, key, iv []byte) []byte { return output } -func AESDecryptCBC(cipher, key, iv []byte) []byte { +func AESDecryptCBC(cipher, key, iv []byte) ([]byte, error) { iter := len(cipher) / 16 lc := iv @@ -38,9 +38,9 @@ func AESDecryptCBC(cipher, key, iv []byte) []byte { } // Undo padding - output = Pkcs7PaddingUndo(output) + output, err := Pkcs7PaddingUndo(output) - return output + return output, err } func AESEncryptECB(plain, key []byte) []byte { @@ -72,7 +72,7 @@ func AESDecryptECB(cipher, key []byte) []byte { } // Undo padding - output = Pkcs7PaddingUndo(output) + output, _ = Pkcs7PaddingUndo(output) return output } diff --git a/lib/blocks.go b/lib/blocks.go index 9b184d1..c4d8be1 100644 --- a/lib/blocks.go +++ b/lib/blocks.go @@ -112,15 +112,15 @@ func Pkcs7Padding(in []byte, k int) []byte { } // Removes PKCS#7 Padding from input `in` -func Pkcs7PaddingUndo(in []byte) []byte { +func Pkcs7PaddingUndo(in []byte) ([]byte, error) { pd := in[len(in)-1] // padding character pl := int(pd) // padding length // Validate for i := len(in) - 1; i >= len(in)-pl; i-- { if in[i] != pd { - panic("input is not pkcs#7 padded!") + return []byte{}, CPError{"input is not pkcs#7 padded"} } } - return in[0:(len(in) - pl)] + return in[0:(len(in) - pl)], nil } |