summaryrefslogtreecommitdiffstats
path: root/lib/blocks.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2021-01-26 21:24:18 -0500
committerrsiddharth <s@ricketyspace.net>2021-01-26 21:24:39 -0500
commit34637327ef1eef55c35286223d2669637c9da25e (patch)
tree72409c88502b9951fc92f714430bbe54f7d86ccf /lib/blocks.go
parent9ea6c0786aa71ca368b32a6c38284378b99613f6 (diff)
lib: update Pkcs7PaddingUndo
Add validation.
Diffstat (limited to 'lib/blocks.go')
-rw-r--r--lib/blocks.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/blocks.go b/lib/blocks.go
index 76f39d6..9b184d1 100644
--- a/lib/blocks.go
+++ b/lib/blocks.go
@@ -113,5 +113,14 @@ func Pkcs7Padding(in []byte, k int) []byte {
// Removes PKCS#7 Padding from input `in`
func Pkcs7PaddingUndo(in []byte) []byte {
- return in[0:(len(in) - int(in[len(in)-1]))]
+ 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 in[0:(len(in) - pl)]
}