forked from martinjungblut/go-cryptsetup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplain.go
43 lines (35 loc) · 967 Bytes
/
plain.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
package cryptsetup
// #cgo pkg-config: libcryptsetup
// #include <libcryptsetup.h>
// #include <stdlib.h>
import "C"
import "unsafe"
type Plain struct {
Hash string
Offset uint64
Skip uint64
Size uint64
SectorSize uint32
}
// Name returns the PLAIN device type name as a string.
func (plain Plain) Name() string {
return "PLAIN"
}
func (plain Plain) Unmanaged() (unsafe.Pointer, func()) {
deallocations := make([]func(), 0, 1)
deallocate := func() {
for index := 0; index < len(deallocations); index++ {
deallocations[index]()
}
}
var cParams C.struct_crypt_params_plain
cParams.offset = C.uint64_t(plain.Offset)
cParams.skip = C.uint64_t(plain.Skip)
cParams.size = C.uint64_t(plain.Size)
cParams.sector_size = C.uint32_t(plain.SectorSize)
cParams.hash = C.CString(plain.Hash)
deallocations = append(deallocations, func() {
C.free(unsafe.Pointer(cParams.hash))
})
return unsafe.Pointer(&cParams), deallocate
}