forked from martinjungblut/go-cryptsetup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
luks1.go
48 lines (39 loc) · 1.11 KB
/
luks1.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
package cryptsetup
// #cgo pkg-config: libcryptsetup
// #include <libcryptsetup.h>
// #include <stdlib.h>
import "C"
import "unsafe"
// LUKS1 is the struct used to manipulate LUKS1 devices.
type LUKS1 struct {
Hash string
DataAlignment int
DataDevice string
}
// Name returns the LUKS1 device type name as a string.
func (luks1 LUKS1) Name() string {
return C.CRYPT_LUKS1
}
// Unmanaged is used to specialize LUKS1.
func (luks1 LUKS1) Unmanaged() (unsafe.Pointer, func()) {
deallocations := make([]func(), 0, 2)
deallocate := func() {
for index := 0; index < len(deallocations); index++ {
deallocations[index]()
}
}
var cParams C.struct_crypt_params_luks1
cParams.data_alignment = C.size_t(luks1.DataAlignment)
cParams.hash = C.CString(luks1.Hash)
deallocations = append(deallocations, func() {
C.free(unsafe.Pointer(cParams.hash))
})
cParams.data_device = nil
if luks1.DataDevice != "" {
cParams.data_device = C.CString(luks1.DataDevice)
deallocations = append(deallocations, func() {
C.free(unsafe.Pointer(cParams.data_device))
})
}
return unsafe.Pointer(&cParams), deallocate
}