Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using file BackendType and FixedStringPrompt creates file, but does not prompt for password #124

Open
jsoneaday opened this issue Feb 26, 2023 · 0 comments

Comments

@jsoneaday
Copy link

I would like to prompt the user for a password during encrypted file creation, but using FixedStringPrompt does not do so. Using TerminalPrompt does not work as it causes an error "multiple-value keyring.TerminalPrompt("Please select a password") (value of type (string, error)) in single-value context"

func SetFileStore(fileSaveDir *C.char, fileName *C.char, data *C.char) *C.char {
	saveDir := C.GoString(fileSaveDir)
	// saveDir, _ := os.Getwd()

	ring, openErr := keyring.Open(keyring.Config{
		AllowedBackends:  []keyring.BackendType{"file"},
		FilePasswordFunc: keyring.FixedStringPrompt("Please select a password"),
		FileDir:          saveDir,
	})
	if openErr != nil {
		openErrStr := string(openErr.Error())
		returnErrStr := (*C.char)(C.CString(openErrStr))
		defer C.free(unsafe.Pointer(returnErrStr))
		return returnErrStr
	}

	dataStr := C.GoString(data)
	fileNameStr := C.GoString(fileName)
	setErr := ring.Set(keyring.Item{
		Key:  fileNameStr,
		Data: []byte(dataStr),
	})
	if setErr != nil {
		errStr := string(setErr.Error())
		returnErrStr := (*C.char)(C.CString(errStr))
		defer C.free(unsafe.Pointer(returnErrStr))
		return returnErrStr
	}

	fileItem, getErr := ring.Get(fileNameStr)
	if getErr != nil {
		errStr := string(getErr.Error())
		returnErrStr := (*C.char)(C.CString(errStr))
		defer C.free(unsafe.Pointer(returnErrStr))
		return returnErrStr
	}
	if string(fileItem.Data) != dataStr {
		returnErrStr := (*C.char)(C.CString("File was not found"))
		defer C.free(unsafe.Pointer(returnErrStr))
		return returnErrStr
	}

	result := (*C.char)(C.CString(""))
	defer C.free(unsafe.Pointer(result))
	return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant