diff --git a/clip/copyArgument.go b/clip/arguments.go similarity index 71% rename from clip/copyArgument.go rename to clip/arguments.go index b57ca79..d7dd670 100644 --- a/clip/copyArgument.go +++ b/clip/arguments.go @@ -1,3 +1,5 @@ +//go:build (!android && !ios) || termux + package clip import ( @@ -9,37 +11,28 @@ import ( "github.com/rwinkhart/libmutton/crypt" ) -// CopyArgument copies a field from an entry to the clipboard. -// If field is -1, it will one-time copy the TOTP code -// (instead of keeping the clipboard up-to-date). -func CopyArgument(targetLocation string, field int) error { +// CopyShortcut, given a path, decrypts an +// entry and copies a field to the clipboard. +func CopyShortcut(targetLocation string, field int) error { // ensure targetLocation exists and is a file _, err := back.TargetIsFile(targetLocation, true) if err != nil { return err } + // decrypt entry decSlice, err := crypt.DecryptFileToSlice(targetLocation) if err != nil { return errors.New("unable to decrypt entry: " + err.Error()) } - // handle non-persistent TOTP copy - var copySubject string - var realField int - if field == -1 { - realField = 2 - } else { - realField = field - } - // if field exists in entry... - if len(decSlice) > realField { - if decSlice[realField] == "" { + if len(decSlice) > field { + if decSlice[field] == "" { return errors.New("field is empty") } - if realField == 2 { // TOTP mode + if field == 2 { // TOTP mode fmt.Println(back.AnsiWarning + "[Starting]" + back.AnsiReset + " TOTP clipboard refresher") errorChan := make(chan error) go TOTPCopier(decSlice[2], field, errorChan, nil) // "done" is not needed because the process runs until the program is killed @@ -52,19 +45,16 @@ func CopyArgument(targetLocation string, field int) error { } select {} // block indefinitely } else { // other - copySubject = decSlice[realField] + // copy field to clipboard; launch clipboard clearing process + err = CopyString(true, decSlice[field]) + if err != nil { + return err + } + return nil } } else { return errors.New("field does not exist in entry") } - - // copy field to clipboard; launch clipboard clearing process - err = CopyString(false, copySubject) - if err != nil { - return err - } - - return nil } // ClipClearArgument reads the assigned clipboard contents from stdin and passes them to clipClearProcess. diff --git a/clip/clipClearProcess_GENERIC.go b/clip/clipClearProcess.go similarity index 100% rename from clip/clipClearProcess_GENERIC.go rename to clip/clipClearProcess.go diff --git a/clip/totp.go b/clip/totp.go index 9f9ec84..2105a4d 100644 --- a/clip/totp.go +++ b/clip/totp.go @@ -1,3 +1,5 @@ +//go:build (!android && !ios) || termux + package clip import ( @@ -29,16 +31,7 @@ func GenTOTP(secret string, time time.Time, forSteam bool) (string, error) { // TOTPCopier is meant to be run as a goroutine to keep // the clipboard up-to-date with the latest TOTP token. -// Set oneTime to -1 for a one-time (non-continuous) TOTP copy. -// For oneTime mode, this function can be used normally (not as a goroutine). func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan bool) error { - var writeErrorChan func(err error) - if errorChan != nil { - writeErrorChan = func(err error) { errorChan <- err } - } else { - writeErrorChan = func(err error) {} - } - var forSteam bool if strings.HasPrefix(secret, "steam@") { secret = secret[6:] @@ -49,16 +42,16 @@ func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan currentTime := time.Now() token, err := GenTOTP(secret, currentTime, forSteam) if err != nil { - writeErrorChan(err) + errorChan <- err return err // return for when not used as goroutine; should exit on error regardless } - err = CopyString(true, token) + err = CopyString(false, token) if err != nil { - writeErrorChan(err) + errorChan <- err return err // return for when not used as goroutine; should exit on error regardless } if oneTime != -1 { - writeErrorChan(err) + errorChan <- err time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second) } else { return nil @@ -67,7 +60,7 @@ func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan // exit after sleep if indicated (will not update clipboard again) select { case <-done: - writeErrorChan(nil) + errorChan <- err return nil default: } diff --git a/wiki/developers.md b/wiki/developers.md index 177fac5..448e0e5 100644 --- a/wiki/developers.md +++ b/wiki/developers.md @@ -21,7 +21,7 @@ These are as follows: - `startrcwd`: Should be accepted by all libmutton implementations making use of the RCW daemon to cache passwords. Please accept a `startrcwd` argument that calls `crypt.RCWDArgument()`. ## Mobile Clipboard Management -In an effort to reduce dependencies not needed in most environments, libmutton no longer provides clipboard management for mobile platforms. This should be handled by your GUI toolkit/framework. +In an effort to reduce dependencies not needed in most environments, libmutton no longer provides clipboard management for mobile platforms (except for Termux). This should be handled by your GUI toolkit/framework. ## Configuration libmutton-based password manager clients should all share the same INI configuration file.