File: ecb_test.go

package info (click to toggle)
golang-github-dvsekhvalnov-jose2go 1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 440 kB
  • sloc: makefile: 4
file content (38 lines) | stat: -rw-r--r-- 992 bytes parent folder | download | duplicates (3)
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
package aes

import (	
	// "fmt"
	"crypto/aes"
	// "crypto/cipher"
	. "gopkg.in/check.v1"
)

func (s *TestSuite) TestNewECBEncryptor(c *C) {
	//given
	plaintext := []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}
	kek := []byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
	block, _ := aes.NewCipher(kek)
	
	test := make([]byte,len(plaintext))

	//when	
	NewECBEncrypter(block).CryptBlocks(test,plaintext)	
	
	//then
	c.Assert(test, DeepEquals, []byte{105,196,224,216,106,123,4,48,216,205,183,128,112,180,197,90})
}

func (s *TestSuite) TestNewECBDecryptor(c *C) {
	//given
	ciphertext := []byte{105,196,224,216,106,123,4,48,216,205,183,128,112,180,197,90}
	kek := []byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
	block, _ := aes.NewCipher(kek)
	
	test := make([]byte,len(ciphertext))

	//when	
	NewECBDecrypter(block).CryptBlocks(test,ciphertext)	
	
	//then
	c.Assert(test, DeepEquals, []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255})
}