Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Add test for zero-length padding
Browse files Browse the repository at this point in the history
  • Loading branch information
csstaub committed Aug 18, 2015
1 parent 0edc31a commit 070d78c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cipher/cbc_hmac.go
Expand Up @@ -183,7 +183,7 @@ func unpadBuffer(buffer []byte, blockSize int) ([]byte, error) {
last := buffer[len(buffer)-1]
count := int(last)

if count > blockSize || count > len(buffer) {
if count == 0 || count > blockSize || count > len(buffer) {
return nil, errors.New("square/go-jose: invalid padding")
}

Expand Down
8 changes: 8 additions & 0 deletions cipher/cbc_hmac_test.go
Expand Up @@ -357,6 +357,14 @@ func TestInvalidPadding(t *testing.T) {
}
}

func TestZeroLengthPadding(t *testing.T) {
data := make([]byte, 16)
data, err := unpadBuffer(data, 16)
if err == nil {
t.Error("padding with 0x00 should never be valid")
}
}

func benchEncryptCBCHMAC(b *testing.B, keySize, chunkSize int) {
key := make([]byte, keySize*2)
nonce := make([]byte, 16)
Expand Down

0 comments on commit 070d78c

Please sign in to comment.