Port to latest libmutton/rcw development versions

This commit is contained in:
2025-05-08 19:44:51 -04:00
parent 752b9d616a
commit 2f34fc2c0c
7 changed files with 38 additions and 57 deletions
+1 -27
View File
@@ -8,35 +8,9 @@ import (
"github.com/rwinkhart/libmutton/core"
"github.com/rwinkhart/libmutton/sync"
"github.com/rwinkhart/rcw/daemon"
"github.com/rwinkhart/rcw/wrappers"
"golang.org/x/term"
)
// GetRCWPassphrase retrieves the RCW passphrase from the most accessible source.
// It first attempts to retrieve from the RCW daemon, then from user input.
// If it does not find an RCW daemon, it launches one to cache the passphrase.
func GetRCWPassphrase() []byte {
// request passphrase from RCW daemon
passphrase := daemon.CallDaemonIfOpen()
// if no passphrase was retrieved, request it from the user
if passphrase == nil {
for {
passphrase = inputHidden("RCW Passphrase:")
err := wrappers.RunSanityCheck(core.ConfigDir+"/sanity.rcw", passphrase)
if err != nil {
fmt.Println(core.AnsiError + "Failed to encrypt - " + err.Error() + core.AnsiReset)
continue
}
break
}
// since no daemon was found earlier, start a new one
core.LaunchRCWDProcess(string(passphrase))
}
return passphrase
}
// input prompts the user for input and returns the input as a string.
func input(prompt string) string {
fmt.Print("\n" + prompt + " ")
@@ -111,7 +85,7 @@ func inputPasswordGen() string {
func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets bool) {
if core.EntryIsNotEmpty(unencryptedEntry) {
// write the entry to the target location
core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n")), GetRCWPassphrase())
core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n")))
// preview the entry
fmt.Println(AnsiBold + "\nEntry Preview:" + core.AnsiReset)
EntryReader(unencryptedEntry, hideSecrets, true)