-
Notifications
You must be signed in to change notification settings - Fork 14
/
plain_test.go
163 lines (112 loc) · 4.46 KB
/
plain_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package cryptsetup
import (
"testing"
)
func Test_Plain_ActivateByPassphrase_Deactivate(test *testing.T) {
testWrapper := TestWrapper{test}
device, err := Init(DevicePath)
testWrapper.AssertNoError(err)
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertNoError(err)
err = device.ActivateByPassphrase(DevicePath, 0, PassKey, CRYPT_ACTIVATE_READONLY)
testWrapper.AssertNoError(err)
err = device.Deactivate(DevicePath)
testWrapper.AssertNoError(err)
device.Free()
}
func Test_Plain_ActivateByPassphrase_Free_InitByName_Deactivate(test *testing.T) {
testWrapper := TestWrapper{test}
device, err := Init(DevicePath)
testWrapper.AssertNoError(err)
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertNoError(err)
err = device.ActivateByPassphrase(DevicePath, 0, PassKey, CRYPT_ACTIVATE_READONLY)
testWrapper.AssertNoError(err)
device.Free()
device, err = InitByName(DevicePath)
testWrapper.AssertNoError(err)
err = device.Deactivate(DevicePath)
testWrapper.AssertNoError(err)
device.Free()
}
func Test_Plain_ActivateByVolumeKey_Deactivate(test *testing.T) {
testWrapper := TestWrapper{test}
genericParams := GenericParams{
Cipher: "aes",
CipherMode: "xts-plain64",
VolumeKey: generateKey(512/8, test),
VolumeKeySize: 512 / 8,
}
device, err := Init(DevicePath)
testWrapper.AssertNoError(err)
err = device.Format(Plain{Hash: "sha256"}, genericParams)
testWrapper.AssertNoError(err)
err = device.ActivateByVolumeKey(DeviceName, genericParams.VolumeKey, genericParams.VolumeKeySize, CRYPT_ACTIVATE_READONLY)
testWrapper.AssertNoError(err)
err = device.Deactivate(DeviceName)
testWrapper.AssertNoError(err)
if device.Type() != "PLAIN" {
test.Error("Expected type: PLAIN.")
}
device.Free()
}
func Test_Plain_Format_Should_Not_Be_Supported(test *testing.T) {
testWrapper := TestWrapper{test}
device, err := Init(DevicePath)
testWrapper.AssertNoError(err)
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertNoError(err)
if device.Type() != "PLAIN" {
test.Error("Expected type: PLAIN.")
}
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertErrorCodeEquals(err, -22)
device.Free()
}
func Test_Plain_KeyslotAddByVolumeKey_Should_Not_Be_Supported(test *testing.T) {
testWrapper := TestWrapper{test}
device, err := Init(DevicePath)
testWrapper.AssertNoError(err)
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertNoError(err)
err = device.KeyslotAddByVolumeKey(0, "", "")
testWrapper.AssertErrorCodeEquals(err, -22)
device.Free()
}
func Test_Plain_KeyslotAddByPassphrase_Should_Not_Be_Supported(test *testing.T) {
testWrapper := TestWrapper{test}
device, err := Init(DevicePath)
testWrapper.AssertNoError(err)
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertNoError(err)
err = device.KeyslotAddByPassphrase(0, "", "")
testWrapper.AssertErrorCodeEquals(err, -22)
device.Free()
}
func Test_Plain_KeyslotChangeByPassphrase_Should_Not_Be_Supported(test *testing.T) {
testWrapper := TestWrapper{test}
device, err := Init(DevicePath)
testWrapper.AssertNoError(err)
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertNoError(err)
err = device.KeyslotChangeByPassphrase(0, 0, "", "")
testWrapper.AssertErrorCodeEquals(err, -22)
device.Free()
}
func Test_Plain_Resize(test *testing.T) {
resizeDiskPath := "testResizeDevice"
setup(resizeDiskPath)
defer teardown(resizeDiskPath)
testWrapper := TestWrapper{test}
device, err := Init(resizeDiskPath)
testWrapper.AssertNoError(err)
defer device.Free()
err = device.Format(Plain{Hash: "sha256"}, GenericParams{Cipher: "aes", CipherMode: "xts-plain64", VolumeKeySize: 512 / 8})
testWrapper.AssertNoError(err)
err = device.ActivateByPassphrase(DeviceName, 0, PassKey, CRYPT_ACTIVATE_READONLY)
testWrapper.AssertNoError(err)
defer device.Deactivate(DeviceName)
resize(resizeDiskPath)
err = device.Resize(DeviceName, 0)
testWrapper.AssertNoError(err)
}