forked from ThalesGroup/gose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_test.go
40 lines (32 loc) · 847 Bytes
/
common_test.go
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
package gose
import (
"github.com/stretchr/testify/mock"
)
const (
ModeEncrypt = iota // blockModeCloser is in encrypt mode
ModeDecrypt // blockModeCloser is in decrypt mode
)
const (
mockExpectedCleartext = "decrypted"
mockExpectedCiphertext = "encrypted"
)
type MockBlockMode struct {
mock.Mock
mode int
}
func (mbm *MockBlockMode) BlockSize() int {
args := mbm.Called()
return args.Get(0).(int)
}
// In order to simulate a behavior tangible for tests, i.e encrypt or decrypt according to the mode, we simply return a
// string that inform us if we properly were in the encrypt or decrypt mode
func (mbm *MockBlockMode) CryptBlocks(dst, src []byte) {
switch mbm.mode {
case ModeDecrypt:
copy(dst, mockExpectedCleartext)
case ModeEncrypt:
copy(dst, mockExpectedCiphertext)
default:
panic("unexpected mode")
}
}