func (device *Device) ActivateByPassphrase(deviceName string, keyslot int, passphrase string, flags int) error {
	cryptDeviceName := C.CString(deviceName)
	defer C.free(unsafe.Pointer(cryptDeviceName))
	cPassphrase := C.CString(passphrase)
	defer C.free(unsafe.Pointer(cPassphrase))
	err := C.crypt_activate_by_passphrase(device.cryptDevice, cryptDeviceName, C.int(keyslot), cPassphrase, C.size_t(len(passphrase)), C.uint32_t(flags))
	if err < 0 {
		return &Error{functionName: "crypt_activate_by_passphrase", code: int(err)}
	}
	return nil
}
ActivateByPassphrase activates a device by using a passphrase from a specific keyslot.
Returns nil on success, or an error otherwise.
C equivalent: crypt_activate_by_passphrase
package cryptsetup
import "C"
import (
	"unsafe"
)
type Device struct {
	cryptDevice *C.struct_crypt_device
	freed       bool
}
func Init(devicePath string) (*Device, error) {
	cryptDevicePath := C.CString(devicePath)
	defer C.free(unsafe.Pointer(cryptDevicePath))
	var cryptDevice *C.struct_crypt_device
	if err := int(C.crypt_init(&cryptDevice, cryptDevicePath)); err < 0 {
		return nil, &Error{functionName: "crypt_init", code: err}
	}
	return &Device{cryptDevice: cryptDevice}, nil
}
func (device *Device) Free() bool {
	if !device.freed {
		C.crypt_free(device.cryptDevice)
		device.freed = true
		return true
	}
	return false
}
func (device *Device) Dump() int {
	return int(C.crypt_dump(device.cryptDevice))
}
func (device *Device) Type() string {
	return C.GoString(C.crypt_get_type(device.cryptDevice))
}
func (device *Device) Format(deviceType DeviceType, genericParams GenericParams) error {
	cryptDeviceTypeName := C.CString(deviceType.Name())
	defer C.free(unsafe.Pointer(cryptDeviceTypeName))
	cCipher := C.CString(genericParams.Cipher)
	defer C.free(unsafe.Pointer(cCipher))
	cCipherMode := C.CString(genericParams.CipherMode)
	defer C.free(unsafe.Pointer(cCipherMode))
	var cUUID *C.char = nil
	if len(genericParams.UUID) > 0 {
		cUUID = C.CString(genericParams.UUID)
		defer C.free(unsafe.Pointer(cUUID))
	}
	var cVolumeKey *C.char = nil
	if len(genericParams.VolumeKey) > 0 {
		cVolumeKey = C.CString(genericParams.VolumeKey)
		defer C.free(unsafe.Pointer(cVolumeKey))
	}
	cVolumeKeySize := C.size_t(genericParams.VolumeKeySize)
	cTypeParams, freeCTypeParams := deviceType.Unmanaged()
	defer freeCTypeParams()
	err := C.crypt_format(device.cryptDevice, cryptDeviceTypeName, cCipher, cCipherMode, cUUID, cVolumeKey, cVolumeKeySize, cTypeParams)
	if err < 0 {
		return &Error{functionName: "crypt_format", code: int(err)}
	}
	return nil
}
func (device *Device) Load() error {
	err := C.crypt_load(device.cryptDevice, nil, nil)
	if err < 0 {
		return &Error{functionName: "crypt_load", code: int(err)}
	}
	return nil
}
func (device *Device) KeyslotAddByVolumeKey(keyslot int, volumeKey string, passphrase string) error {
	var cVolumeKey *C.char = nil
	if len(volumeKey) > 0 {
		cVolumeKey = C.CString(volumeKey)
		defer C.free(unsafe.Pointer(cVolumeKey))
	}
	cPassphrase := C.CString(passphrase)
	defer C.free(unsafe.Pointer(cPassphrase))
	err := C.crypt_keyslot_add_by_volume_key(device.cryptDevice, C.int(keyslot), cVolumeKey, C.size_t(len(volumeKey)), cPassphrase, C.size_t(len(passphrase)))
	if err < 0 {
		return &Error{functionName: "crypt_keyslot_add_by_volume_key", code: int(err)}
	}
	return nil
}
func (device *Device) KeyslotAddByPassphrase(keyslot int, currentPassphrase string, newPassphrase string) error {
	cCurrentPassphrase := C.CString(currentPassphrase)
	defer C.free(unsafe.Pointer(cCurrentPassphrase))
	cNewPassphrase := C.CString(newPassphrase)
	defer C.free(unsafe.Pointer(cNewPassphrase))
	err := C.crypt_keyslot_add_by_passphrase(
		device.cryptDevice, C.int(keyslot),
		cCurrentPassphrase, C.size_t(len(currentPassphrase)),
		cNewPassphrase, C.size_t(len(newPassphrase)),
	)
	if err < 0 {
		return &Error{functionName: "crypt_keyslot_add_by_passphrase", code: int(err)}
	}
	return nil
}
func (device *Device) KeyslotChangeByPassphrase(currentKeyslot int, newKeyslot int, currentPassphrase string, newPassphrase string) error {
	cCurrentPassphrase := C.CString(currentPassphrase)
	defer C.free(unsafe.Pointer(cCurrentPassphrase))
	cNewPassphrase := C.CString(newPassphrase)
	defer C.free(unsafe.Pointer(cNewPassphrase))
	err := C.crypt_keyslot_change_by_passphrase(
		device.cryptDevice,
		C.int(currentKeyslot),
		C.int(newKeyslot),
		cCurrentPassphrase, C.size_t(len(currentPassphrase)),
		cNewPassphrase, C.size_t(len(newPassphrase)),
	)
	if err < 0 {
		return &Error{functionName: "crypt_keyslot_change_by_passphrase", code: int(err)}
	}
	return nil
}