File: aes_cbc_padder_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.44.133-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 245,296 kB
  • sloc: makefile: 120
file content (41 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package s3crypto

import (
	"bytes"
	"fmt"
	"testing"
)

func TestAESCBCPadding(t *testing.T) {
	for i := 0; i < 16; i++ {
		input := make([]byte, i)
		expected := append(input, bytes.Repeat([]byte{byte(16 - i)}, 16-i)...)
		b, err := AESCBCPadder.Pad(input, len(input))
		if err != nil {
			t.Fatal("Expected error to be nil but received " + err.Error())
		}
		if len(b) != len(expected) {
			t.Fatal(fmt.Sprintf("Case %d: data is not of the same length", i))
		}
		if bytes.Compare(b, expected) != 0 {
			t.Fatal(fmt.Sprintf("Expected %v but got %v", expected, b))
		}
	}
}

func TestAESCBCUnpadding(t *testing.T) {
	for i := 0; i < 16; i++ {
		expected := make([]byte, i)
		input := append(expected, bytes.Repeat([]byte{byte(16 - i)}, 16-i)...)
		b, err := AESCBCPadder.Unpad(input)
		if err != nil {
			t.Fatal("Error received, was expecting nil: " + err.Error())
		}
		if len(b) != len(expected) {
			t.Fatal(fmt.Sprintf("Case %d: data is not of the same length", i))
		}
		if bytes.Compare(b, expected) != 0 {
			t.Fatal(fmt.Sprintf("Expected %v but got %v", expected, b))
		}
	}
}